Snmp.send() returns null?


I’m seeing rare instances in timeouts in which the Snmp.send() method returns null.
Looking at the code, I suspect it is because of the following block:

        ResponseEvent<A> responseEvent = syncResponse.getResponse();
        if (syncResponse.getResponse() == null) {
            responseEvent =
                    new ResponseEvent<A>(Snmp.this, null, pdu, null, null);
        return responseEvent;

Should the null check be performed on responseEvent instead of syncResponse.getResponse(), because the first call to syncResponse.getResponse() could return null, but the second followup call in the null check may not be null, and thus responseEvent is never assigned a non-null value before it returns?


Sure, the following code is better:

        return Objects.requireNonNullElse(syncResponse.getResponse(),
                new ResponseEvent<A>(this, null, pdu, null, null));

This code will be part of the next 2.8 and 3.6 updates.