Bug fix for array isempty checks
This commit is contained in:
parent
19a12dee44
commit
09cce76707
3 changed files with 13 additions and 3 deletions
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
package zutil;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -59,7 +60,7 @@ public class ObjectUtil {
|
|||
else if (obj instanceof List)
|
||||
return ((List) obj).isEmpty();
|
||||
else if (obj.getClass().isArray())
|
||||
return ((Object[]) obj).length == 0;
|
||||
return (Array.getLength(obj) == 0);
|
||||
else if (obj instanceof CharSequence)
|
||||
return ((CharSequence) obj).length() == 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
package zutil.net.mqtt;
|
||||
|
||||
import zutil.ObjectUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.mqtt.packet.*;
|
||||
import zutil.net.mqtt.packet.MqttPacketSubscribe.MqttSubscribePayload;
|
||||
|
|
@ -187,7 +188,7 @@ public class MqttBroker extends ThreadedTCPNetworkServer {
|
|||
* @param data the data that should be published.
|
||||
*/
|
||||
public void publish(String topicName, byte[] data) {
|
||||
logger.finer("Data has been published to topic: " + topicName);
|
||||
logger.finest("Data has been published to topic: " + topicName);
|
||||
|
||||
if (globalListeners != null)
|
||||
globalListeners.forEach(listener -> listener.dataPublished(topicName, data));
|
||||
|
|
@ -209,7 +210,13 @@ public class MqttBroker extends ThreadedTCPNetworkServer {
|
|||
MqttTopic topicData = createTopic(topicName);
|
||||
|
||||
if (topicData != null) {
|
||||
topicData.retainedPayload = data;
|
||||
if (ObjectUtil.isEmpty(data)) {
|
||||
logger.finer("Retained message removed for topic: " + topicName);
|
||||
topicData.retainedPayload = null;
|
||||
} else {
|
||||
logger.finer("New message retained for topic: " + topicName);
|
||||
topicData.retainedPayload = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue