fixes NPE if parameters are null and removed toString calls in logging statements

Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
Kai Kreuzer 2016-02-22 19:32:51 +01:00
parent 615e822480
commit 1b9af5d70e

View File

@ -9,7 +9,6 @@
package org.openhab.core.events; package org.openhab.core.events;
import org.eclipse.smarthome.core.events.EventPublisher; import org.eclipse.smarthome.core.events.EventPublisher;
import org.eclipse.smarthome.core.items.ItemRegistry;
import org.eclipse.smarthome.core.items.events.ItemCommandEvent; import org.eclipse.smarthome.core.items.events.ItemCommandEvent;
import org.eclipse.smarthome.core.items.events.ItemEventFactory; import org.eclipse.smarthome.core.items.events.ItemEventFactory;
import org.eclipse.smarthome.core.items.events.ItemStateEvent; import org.eclipse.smarthome.core.items.events.ItemStateEvent;
@ -41,23 +40,31 @@ public class EventPublisherDelegate implements org.openhab.core.events.EventPubl
@Override @Override
public void postCommand(String itemName, Command command) { public void postCommand(String itemName, Command command) {
org.eclipse.smarthome.core.types.Command eshCommand = (org.eclipse.smarthome.core.types.Command) TypeMapper.mapToESHType(command); org.eclipse.smarthome.core.types.Command eshCommand = (org.eclipse.smarthome.core.types.Command) TypeMapper
.mapToESHType(command);
if (eshCommand != null) { if (eshCommand != null) {
ItemCommandEvent event = ItemEventFactory.createCommandEvent(itemName, eshCommand); ItemCommandEvent event = ItemEventFactory.createCommandEvent(itemName, eshCommand);
eventPublisher.post(event); eventPublisher.post(event);
} else if (command != null) {
logger.warn("Compatibility layer could not convert {} of type {}.", command,
command.getClass().getSimpleName());
} else { } else {
logger.warn("Compatibility layer could not convert {} of type {}.", command.toString(), command.getClass().getSimpleName() ); logger.warn("given command is NULL, couldn't post command for '{}'", itemName);
} }
} }
@Override @Override
public void postUpdate(String itemName, State newState) { public void postUpdate(String itemName, State newState) {
org.eclipse.smarthome.core.types.State eshState = (org.eclipse.smarthome.core.types.State) TypeMapper.mapToESHType(newState); org.eclipse.smarthome.core.types.State eshState = (org.eclipse.smarthome.core.types.State) TypeMapper
.mapToESHType(newState);
if (eshState != null) { if (eshState != null) {
ItemStateEvent event = ItemEventFactory.createStateEvent(itemName, eshState); ItemStateEvent event = ItemEventFactory.createStateEvent(itemName, eshState);
eventPublisher.post(event); eventPublisher.post(event);
} else if (newState != null) {
logger.warn("Compatibility layer could not convert {} of type {}.", newState,
newState.getClass().getSimpleName());
} else { } else {
logger.warn("Compatibility layer could not convert {} of type {}.", newState.toString(), newState.getClass().getSimpleName() ); logger.warn("given new state is NULL, couldn't post update for '{}'", itemName);
} }
} }
} }