java.lang.NullPointerException in at org.web3j.protocol.core.filters.LogFilter.process(LogFilter.java:46) over {"code":-32000,"message":"exceed maximum block range: 5000"}}
java.lang.NullPointerException: null
at org.web3j.protocol.core.filters.LogFilter.process(LogFilter.java:46)
at org.web3j.protocol.core.filters.Filter.getInitialFilterLogs(Filter.java:119)
at org.web3j.protocol.core.filters.Filter.run(Filter.java:69)
at org.web3j.protocol.rx.JsonRpc2_0Rx.run(JsonRpc2_0Rx.java:89)
at org.web3j.protocol.rx.JsonRpc2_0Rx.lambda$ethLogFlowable$2(JsonRpc2_0Rx.java:79)
at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java:71)
at io.reactivex.Flowable.subscribe(Flowable.java:14935)
at io.reactivex.Flowable.subscribe(Flowable.java:14872)
at io.reactivex.Flowable.subscribe(Flowable.java:14791)
Code in question
for (EthLog.LogResult logResult : logResults) { https://github.com/web3j/web3j/blob/master/core/src/main/java/org/web3j/protocol/core/filters/LogFilter.java#L46
@Override
protected void process(List<EthLog.LogResult> logResults) {
for (EthLog.LogResult logResult : logResults) {
if (logResult instanceof EthLog.LogObject) {
Log log = ((EthLog.LogObject) logResult).get();
callback.onEvent(log);
} else {
throw new FilterException(
"Unexpected result type: " + logResult.get() + " required LogObject");
}
}
}
Bug_title
java.lang.NullPointerException in at org.web3j.protocol.core.filters.LogFilter.process(LogFilter.java:46)
The should be check if result is null instead of Exception
Steps To Reproduce
Describe the exact steps or scenario to reproduce the issue.
Expected behavior
No exception
Actual behavior
A description of the actual behavior occurring.
Environment
Describe the environment in which the issue occurs
- Web3j version: 4.8.4 and 4.8.7 give the same error
- Java or Android version: Java 8
- Operating System: macOS
Additional context
Add any other context about the problem here.
- Logs
- Sample code and/or code snippets
private void createEventMonitor() {
log.info("createEventMonitor() begin...");
// contract from block
EthFilter filter = new EthFilter(DefaultBlockParameter.valueOf(new BigInteger("7605105")),
DefaultBlockParameterName.LATEST, hedgingStrategy.getController());
//Disposable subscription
subscription = web3j
.ethLogFlowable(filter)
.subscribe(
event -> {
log.info("Withdraw event received:");
log.info(" event data >>> {}", event.getData());
log.info(" event topic >>> {}", event.getTopics().stream().collect(Collectors.joining()));
log.info(" event address >>> {}", event.getAddress());
log.info(" event txHash >>> {}", event.getTransactionHash());
}, error -> {
log.error("Event error: {}", error, error); //!
});
log.info("createEventMonitor() end.");
}
- Unit/integration tests to highlight the issue
- etherscan references
Asked on https://stackoverflow.com/questions/68919728/java-lang-nullpointerexception-at-org-web3j-protocol-core-filters-logfilter-proc
Are you sure you are not using an RPC endpoint with a pool of servers that don't synchronize the filterIds ?
I've experienced the same issue, and the root cause was that the eth_newFilter call reached a server, while the next eth_getFilterLogs didn't recognize the just created filterId.
Thanks for sharing. Well, this is still TEST environment, and there maybe different instances running,
but for sure they are not connected between each other to synchronize the filterIds.
By the way, how to get this filterId ? I have not seen any API for that.
~~I wonder, can it be geth node bug, when geth node giving the same ids?~~
P.S. I recalled, that I had issue, where Filter id got visible.
But it was when connecting to geth node (server) was in fact failing.
It was raised on SO https://stackoverflow.com/questions/68933870/warn-org-web3j-protocol-core-filters-filter-reinstallfilter153-the-filter-has
2021-08-26 14:40:25,134 [pool-2-thread-1] WARN org.web3j.protocol.core.filters.Filter.reinstallFilter(153) -The filter has not been found. Filter id: 330683721788227458774458119455366581270
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
2021-08-26 14:40:25,420 [pool-2-thread-1] ERROR org.web3j.protocol.core.filters.Filter.lambda$run$0(97) -Error sending request
org.web3j.protocol.core.filters.FilterException: Error sending request
at org.web3j.protocol.core.filters.Filter.throwException(Filter.java:194)
at org.web3j.protocol.core.filters.Filter.run(Filter.java:104)
at org.web3j.protocol.core.filters.Filter.reinstallFilter(Filter.java:155)
at org.web3j.protocol.core.filters.Filter.pollFilter(Filter.java:137)
at org.web3j.protocol.core.filters.Filter.lambda$run$0(Filter.java:92)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.InterruptedIOException: interrupted
at okio.Timeout.throwIfReached(Timeout.kt:98)
at okio.OutputStreamSink.write(Okio.kt:53)
at okio.AsyncTimeout$sink$1.write(AsyncTimeout.kt:103)
at okio.RealBufferedSink.flush(RealBufferedSink.kt:247)
at okhttp3.internal.http1.Http1ExchangeCodec.finishRequest(Http1ExchangeCodec.kt:158)
at okhttp3.internal.connection.Exchange.finishRequest(Exchange.kt:90)
Alex, that was great lead,
P.P.S.
My bad, at some point I disabled most of debug logging, and when I turned in on, I saw exact JSON RPC error
{"code":-32000,"message":"exceed maximum block range: 5000"}}
So this issue should actually be about catching low level error and giving exact JSON RPC error message in higher Web3j API
2021-08-30 15:37:37 DEBUG o.w.p.websocket.WebSocketService - Sending request: {"jsonrpc":"2.0","method":"eth_newFilter","params":[{"topics":[],"fromBlock":"earliest","toBlock":"latest","address":["0xF46a8985347f072eB7A743a8506F3cDF791560a5"]}],"id":1}
2021-08-30 15:37:37 DEBUG o.w.p.websocket.WebSocketClient - Received message {"jsonrpc":"2.0","id":1,"result":"0x62f7226ff50e7c8bfcafa5e4df32a668"}
from server wss://ws-testnet.hecochain.com
2021-08-30 15:37:37 DEBUG o.w.p.websocket.WebSocketService - Sending request: {"jsonrpc":"2.0","method":"eth_getFilterLogs","params":["0x62f7226ff50e7c8bfcafa5e4df32a668"],"id":2}
2021-08-30 15:37:37 DEBUG o.w.p.websocket.WebSocketClient - Received message {"jsonrpc":"2.0","id":2,"error":{"code":-32000,"message":"exceed maximum block range: 5000"}}
from server wss://ws-testnet.hecochain.com
2021-08-30 15:37:37 ERROR c.h.p.h.s.w.c.r.ContractEventSubscriber - Event error 1: {}
java.lang.NullPointerException: null
at org.web3j.protocol.core.filters.LogFilter.process(LogFilter.java:46)
at org.web3j.protocol.core.filters.Filter.getInitialFilterLogs(Filter.java:119)
at org.web3j.protocol.core.filters.Filter.run(Filter.java:69)
I'll push a PR soon that will show the error instead of hiding it with a NPE, since there may be multiple causes for the getInitialFilterLogs failure.
https://github.com/web3j/web3j/pull/1495
#1495 merged, is this issue good to close? @paulvi
well, I believe this issue should be closed after next version release.
This is not a bug in web3j, but a limitation of BSC. My practice is to check whether it exceeds 5000 before starting. If it exceeds 5000, use web3j first Ethgetlogs pull logs of previous periods
Hi @paulvi, is this issue good to close?
https://github.com/web3j/web3j/pull/1495