diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/TbLwM2mRedisSecurityStore.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/TbLwM2mRedisSecurityStore.java index b108286afd..54200be434 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/TbLwM2mRedisSecurityStore.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/TbLwM2mRedisSecurityStore.java @@ -46,7 +46,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore { lock = redisLock.obtain(toLockKey(endpoint)); lock.lock(); byte[] data = connection.get((SEC_EP + endpoint).getBytes()); - if (data == null) { + if (data == null || data.length == 0) { return null; } else { return ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo(); @@ -69,7 +69,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore { return null; } else { byte[] data = connection.get((SEC_EP + new String(ep)).getBytes()); - if (data == null) { + if (data == null || data.length == 0) { return null; } else { return ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo(); @@ -122,7 +122,11 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore { lock = redisLock.obtain(endpoint); lock.lock(); byte[] data = connection.get((SEC_EP + endpoint).getBytes()); - return (TbLwM2MSecurityInfo) serializer.asObject(data); + if (data != null && data.length > 0) { + return (TbLwM2MSecurityInfo) serializer.asObject(data); + } else { + return null; + } } finally { if (lock != null) { lock.unlock(); @@ -137,7 +141,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore { lock = redisLock.obtain(endpoint); lock.lock(); byte[] data = connection.get((SEC_EP + endpoint).getBytes()); - if (data != null) { + if (data != null && data.length > 0) { SecurityInfo info = ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo(); if (info != null && info.getIdentity() != null) { connection.hDel(PSKID_SEC.getBytes(), info.getIdentity().getBytes());