java.lang.NullPointerException every few seconds

Hello my log is full (every few seconds) of the following error.
I can not find a hint that tells me it is something i did, like a rule for example.
Running the latest snapshot.

What can i do?

2017-05-25 07:02:58.307 [ERROR] [] - Dispatching/filtering event for subscriber '' failed: java.lang.NullPointerException
java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.util.concurrent.FutureTask.get([:1.8.0_131]
	at org.eclipse.smarthome.core.common.SafeMethodCaller.callAsynchronous([100:org.eclipse.smarthome.core:]
	at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent([]
	at java.util.concurrent.Executors$[:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor.runWorker([:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor$[:1.8.0_131]
Caused by: java.lang.NullPointerException
	at org.eclipse.smarthome.core.items.GenericItem.applyState([100:org.eclipse.smarthome.core:]
	at org.eclipse.smarthome.core.library.items.DimmerItem.setState([100:org.eclipse.smarthome.core:]
	at org.eclipse.smarthome.core.internal.items.ItemUpdater.receiveUpdate([100:org.eclipse.smarthome.core:]
	at org.eclipse.smarthome.core.common.SafeMethodCaller$[100:org.eclipse.smarthome.core:]
	... 4 more

That is an interesting one can you put the log in between back ticks.

Can you enable debug logging, or maybe also append the event.log

I suspect some binding is publishing a null state for the dimmer, whether this is expected to fall apart is another thing to find out.

Yes, a bit more logging might be helpful - especially the event in event.log that causes that.

In any case, there should not be an NPE, so please additionally also file a bug at Thanks!

@Kai I almost fixed it, but I’m in doubt what the correct behaviour should it or should it not publish a StateChangedEvent the oldState is null in this case. So it feels like a change to me?

Existing code fragment:

        this.state = state;
        notifyListeners(oldState, state);
        if (!oldState.equals(state)) {
            sendStateChangedEvent(state, oldState);

So either this one:

if (oldState == null || !oldState.equals(newState)) {
   sendStateChangedEvent(newState, oldState);

Or this one:

if (oldState != null && !oldState.equals(newState)) {
   sendStateChangedEvent(newState, oldState);

Or should I forward a state = null as UnDefType.NULL

Would have to look into the code how it used to be in the past - this issue is a regression, so we should make it work in the way it used to. I entered for tracking.

Opened a PR :slight_smile:

1 Like

I had this error and the reason was a @Autowired class in the thread class -> give the instance of the class as parameter to the constructor.