web3j
web3j copied to clipboard
GetBlocks cause NullPointerException
GetBlocks cause NullPointerException
Web3j web3j =
Web3j.build(
new HttpService(web3jUri));
Iterable<EthBlock> eths = web3j.replayPastBlocksFlowable(
new DefaultBlockParameterNumber(startBlock),
new DefaultBlockParameterNumber(endBlock), true)
.blockingIterable();
eths.forEach(eth -> {
String printStr = eth.getBlock().toString();
System.out.println(printStr);
});
it will cause
org.web3j.protocol.core.methods.response.EthBlock$Block@9a316cc5
org.web3j.protocol.core.methods.response.EthBlock$Block@c14e6975
org.web3j.protocol.core.methods.response.EthBlock$Block@c20ce720
org.web3j.protocol.core.methods.response.EthBlock$Block@4cee7328
org.web3j.protocol.core.methods.response.EthBlock$Block@1ae94be0
Exception in thread "main" java.lang.NullPointerException
at Web3jMain.lambda$main$0(Web3jMain.java:65)
at java.lang.Iterable.forEach(Iterable.java:75)
at Web3jMain.main(Web3jMain.java:64)
Steps To Reproduce
- Set up a local eth node by this
- start miner
Expected behavior
No errors throw
Actual behavior
Throw nullPointerException
Environment
Web3j version: 5.0.0
Additional context
null
org.web3j.protocol.Service #send
the size of result buffer is zero

you iterate EthBlock from startBlock -> endBlock , but actually there is not enough block in your local Ethereum.
So, eths.forEach will get null at runtime.
