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] [ore.internal.events.OSGiEventManager] - Dispatching/filtering event for subscriber 'org.eclipse.smarthome.core.events.EventSubscriber' failed: java.lang.NullPointerException
java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)[:1.8.0_131]
	at java.util.concurrent.FutureTask.get(FutureTask.java:206)[:1.8.0_131]
	at org.eclipse.smarthome.core.common.SafeMethodCaller.callAsynchronous(SafeMethodCaller.java:194)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	at org.eclipse.smarthome.core.common.SafeMethodCaller.call(SafeMethodCaller.java:83)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	at org.eclipse.smarthome.core.common.SafeMethodCaller.call(SafeMethodCaller.java:67)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	at org.eclipse.smarthome.core.internal.events.OSGiEventManager.dispatchESHEvent(OSGiEventManager.java:188)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	at org.eclipse.smarthome.core.internal.events.OSGiEventManager.handleEvent(OSGiEventManager.java:163)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	at org.eclipse.smarthome.core.internal.events.OSGiEventManager.handleEvent(OSGiEventManager.java:146)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415)[6:org.apache.karaf.services.eventadmin:4.0.8]
	at org.apache.felix.eventadmin.impl.tasks.HandlerTask.run(HandlerTask.java:90)[6:org.apache.karaf.services.eventadmin:4.0.8]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_131]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_131]
	at java.lang.Thread.run(Thread.java:748)[:1.8.0_131]
Caused by: java.lang.NullPointerException
	at org.eclipse.smarthome.core.items.GenericItem.applyState(GenericItem.java:208)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	at org.eclipse.smarthome.core.library.items.DimmerItem.setState(DimmerItem.java:74)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	at org.eclipse.smarthome.core.internal.items.ItemUpdater.receiveUpdate(ItemUpdater.java:70)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	at org.eclipse.smarthome.core.items.events.AbstractItemEventSubscriber.receive(AbstractItemEventSubscriber.java:44)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	at org.eclipse.smarthome.core.internal.events.OSGiEventManager$1.call(OSGiEventManager.java:192)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	at org.eclipse.smarthome.core.internal.events.OSGiEventManager$1.call(OSGiEventManager.java:1)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	at org.eclipse.smarthome.core.common.SafeMethodCaller$CallableWrapper.call(SafeMethodCaller.java:181)[100:org.eclipse.smarthome.core:0.9.0.201705231820]
	... 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 https://github.com/eclipse/smarthome/issues. 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 https://github.com/eclipse/smarthome/issues/3520 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.