Commit 5bff4d1a6baed5725e72ceff0ebd790d472a7c99

Authored by Andrii Shvaika
1 parent d190cba2

Fix NPE in Redis Security Store

... ... @@ -46,7 +46,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore {
46 46 lock = redisLock.obtain(toLockKey(endpoint));
47 47 lock.lock();
48 48 byte[] data = connection.get((SEC_EP + endpoint).getBytes());
49   - if (data == null) {
  49 + if (data == null || data.length == 0) {
50 50 return null;
51 51 } else {
52 52 return ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo();
... ... @@ -69,7 +69,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore {
69 69 return null;
70 70 } else {
71 71 byte[] data = connection.get((SEC_EP + new String(ep)).getBytes());
72   - if (data == null) {
  72 + if (data == null || data.length == 0) {
73 73 return null;
74 74 } else {
75 75 return ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo();
... ... @@ -122,7 +122,11 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore {
122 122 lock = redisLock.obtain(endpoint);
123 123 lock.lock();
124 124 byte[] data = connection.get((SEC_EP + endpoint).getBytes());
125   - return (TbLwM2MSecurityInfo) serializer.asObject(data);
  125 + if (data != null && data.length > 0) {
  126 + return (TbLwM2MSecurityInfo) serializer.asObject(data);
  127 + } else {
  128 + return null;
  129 + }
126 130 } finally {
127 131 if (lock != null) {
128 132 lock.unlock();
... ... @@ -137,7 +141,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore {
137 141 lock = redisLock.obtain(endpoint);
138 142 lock.lock();
139 143 byte[] data = connection.get((SEC_EP + endpoint).getBytes());
140   - if (data != null) {
  144 + if (data != null && data.length > 0) {
141 145 SecurityInfo info = ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo();
142 146 if (info != null && info.getIdentity() != null) {
143 147 connection.hDel(PSKID_SEC.getBytes(), info.getIdentity().getBytes());
... ...