Fix potential NPE in ProfileCallbackImpl (#1627)

Also annotates ItemChannelLink.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2020-09-07 15:13:06 +02:00 committed by GitHub
parent 02404b2fa7
commit 2273f8976f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -137,6 +137,12 @@ public class ProfileCallbackImpl implements ProfileCallback {
@Override
public void sendUpdate(State state) {
Item item = itemProvider.apply(link.getItemName());
if (item == null) {
logger.warn("Cannot post update event '{}' for item '{}', because no item could be found.", state,
link.getItemName());
return;
}
State acceptedState;
if (state instanceof StringType && !(item instanceof StringItem)) {
acceptedState = TypeParser.parseState(item.getAcceptedDataTypes(), state.toString());
@ -146,6 +152,7 @@ public class ProfileCallbackImpl implements ProfileCallback {
} else {
acceptedState = itemStateConverter.convertToAcceptedState(state, item);
}
eventPublisher.post(
ItemEventFactory.createStateEvent(link.getItemName(), acceptedState, link.getLinkedUID().toString()));
}

View File

@ -12,6 +12,7 @@
*/
package org.openhab.core.thing.link;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.items.Item;
import org.openhab.core.thing.ChannelUID;
@ -23,9 +24,10 @@ import org.openhab.core.thing.ChannelUID;
* @author Jochen Hiller - Bugfix 455434: added default constructor, object is now mutable
* @author Simon Kaufmann - added configuration
*/
@NonNullByDefault
public class ItemChannelLink extends AbstractLink {
private final ChannelUID channelUID;
private final @NonNullByDefault({}) ChannelUID channelUID;
private final Configuration configuration;
/**