Closed amitjoy closed 4 months ago
I can only assume that protocolHandler
is null at this point which should not normally be the case. Please can you provide a debug log that provides some context of what is going on.
@cdjackson Thanks a lot for your quick reply. Unfortunately, I don't have any logs at all since it has been reported to our sentry endpoint as soon as it happened. But, we have never noticed any critical scenario earlier resulting from this though. Can we still do something for this?
@cdjackson I think it would make sense to introduce NPE invariants (preconditions) to denote the expectation. wdyt?
An NPE at his point shouldn't be possible which is why I wanted to know the context. I'm assuming that this is during initialisation, and if we look at the code we see the following -:
In initialiseEzspProtocol
-:
frameHandler.connect();
EmberNcp ncp = getEmberNcp();
// We MUST send the version command first.
// Any failure to respond here indicates a failure of the ASH or EZSP layers to initialise
ezspVersion = ncp.getVersion();
if (ezspVersion == null) {
logger.debug("EZSP Dongle: Version returned null. ASH/EZSP not initialised.");
return false;
}
public EmberNcp getEmberNcp() {
return new EmberNcp(frameHandler);
}
Then in ncp.getVersion()
-:
I've pasted this as an image so we can see the line numbers. The line where the exception occurred is line 216...
So, we can see above that frameHandler.connect();
is called just before getEmberNcp
. getEmberNcp
uses frameHandler
to pass to the ncp
, and this is locally called protocolHandler
. So, for protocolHandler
to be null, frameHandler
would also be null, but it can't be null since it was used 2 lines before calling getVersion
.
Maybe this isn't where your exception occurred? Without the log it's hard to know what is happening.
Maybe in the EmberNcp
constructor we should check that protocolHandler
is not null and throw an invalid argument exception there?
E.g. -:
public EmberNcp(EzspProtocolHandler protocolHandler) {
if (protocolHandler == null) {
throw new InvallidArgumentException(....);
}
this.protocolHandler = protocolHandler;
}
What do you think?
@cdjackson I was also thinking along the line. It would be better to introduce the invariant for our expectation of it to be not null. I will open the MR shortly then.
Thanks for the PR @amitjoy
The following NPE has been noticed in the runtime which indicates that ZB transport layer hasn't been initialized properly.
@cdjackson Would you please provide clarification as to the underlying reasons for this occurrence?