Possible null pointer dereference in ReceivingService
DaveJarvis opened this issue · 0 comments
DaveJarvis commented
The following code has a null
guard for the _rsCfg
argument, but the argument is used in both guarded and unguarded contexts:
ReceivingService(ReceivingServiceConfig _rsCfg) {
ReceivingServiceConfig rsCfg = Optional.ofNullable(_rsCfg).orElse(ReceivingServiceConfigBuilder.getDefaultConfig());
executors.put(ExecutorNames.SIGNAL, Executors.newFixedThreadPool(rsCfg.getSignalThreadPoolSize(), new NameableThreadFactory("DBus-Signal-Receiver-", true)));
executors.put(ExecutorNames.ERROR, Executors.newFixedThreadPool(rsCfg.getErrorThreadPoolSize(), new NameableThreadFactory("DBus-Error-Receiver-", true)));
// we need multiple threads here so recursive method calls are possible
executors.put(ExecutorNames.METHODCALL, Executors.newFixedThreadPool(rsCfg.getMethodCallThreadPoolSize(), new NameableThreadFactory("DBus-MethodCall-Receiver-", true)));
executors.put(ExecutorNames.METHODRETURN, Executors.newFixedThreadPool(rsCfg.getMethodReturnThreadPoolSize(), new NameableThreadFactory("DBus-MethodReturn-Receiver-", true)));
retryHandler = _rsCfg.getRetryHandler();
}
The deprecated DirectConnection
constructor passes in a null
configuration, as per:
public DirectConnection(String _address, int _timeout) throws DBusException {
this(createTransportConfig(_address, _timeout), null);
}
That null
configuration is then passed along to:
protected AbstractConnection(TransportConfig _transportConfig, ReceivingServiceConfig _rsCfg) throws DBusException {
Then passed to ReceivingService
via its constructor:
receivingService = new ReceivingService(_rsCfg);
This means that the following line can throw a NullPointerException
:
retryHandler = _rsCfg.getRetryHandler();
Is this supposed to be called without the _
to use the null
-safe variable? Such as:
retryHandler = rsCfg.getRetryHandler();