Fixed - RedissonSession.getAttribute throws NPE #1859

pull/1871/head
Nikita Koksharov 6 years ago
parent d1618f4b69
commit 4fbaa1bfeb

@ -51,7 +51,7 @@ public class RedissonSession extends StandardSession {
private final RedissonSessionManager redissonManager;
private final Map<String, Object> attrs;
private RMap<String, Object> map;
private RTopic topic;
private final RTopic topic;
private final RedissonSessionManager.ReadMode readMode;
private final UpdateMode updateMode;
@ -60,6 +60,7 @@ public class RedissonSession extends StandardSession {
this.redissonManager = manager;
this.readMode = readMode;
this.updateMode = updateMode;
this.topic = redissonManager.getTopic();
try {
Field attr = StandardSession.class.getDeclaredField("attributes");
@ -80,13 +81,6 @@ public class RedissonSession extends StandardSession {
return super.getAttribute(name);
}
@Override
public void setId(String id, boolean notify) {
super.setId(id, notify);
map = redissonManager.getMap(id);
topic = redissonManager.getTopic();
}
public void delete() {
map.delete();
if (readMode == ReadMode.MEMORY) {
@ -183,7 +177,7 @@ public class RedissonSession extends StandardSession {
boolean oldValue = isNew;
super.endAccess();
if (isNew != oldValue) {
if (isNew != oldValue && map != null) {
fastPut(IS_NEW_ATTR, isNew);
}
}
@ -218,6 +212,10 @@ public class RedissonSession extends StandardSession {
}
public void save() {
if (map == null) {
map = redissonManager.getMap(id);
}
Map<String, Object> newMap = new HashMap<String, Object>();
newMap.put(CREATION_TIME_ATTR, creationTime);
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);

@ -147,7 +147,6 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
session.setManager(this);
session.setId(sessionId);
session.save();
return session;
}
@ -206,6 +205,12 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
return new RedissonSession(this, readMode, updateMode);
}
@Override
public void add(Session session) {
super.add(session);
((RedissonSession)session).save();
}
@Override
public void remove(Session session) {
super.remove(session);

@ -51,7 +51,7 @@ public class RedissonSession extends StandardSession {
private final RedissonSessionManager redissonManager;
private final Map<String, Object> attrs;
private RMap<String, Object> map;
private RTopic topic;
private final RTopic topic;
private final RedissonSessionManager.ReadMode readMode;
private final UpdateMode updateMode;
@ -60,6 +60,7 @@ public class RedissonSession extends StandardSession {
this.redissonManager = manager;
this.readMode = readMode;
this.updateMode = updateMode;
this.topic = redissonManager.getTopic();
try {
Field attr = StandardSession.class.getDeclaredField("attributes");
@ -80,13 +81,6 @@ public class RedissonSession extends StandardSession {
return super.getAttribute(name);
}
@Override
public void setId(String id, boolean notify) {
super.setId(id, notify);
map = redissonManager.getMap(id);
topic = redissonManager.getTopic();
}
public void delete() {
map.delete();
if (readMode == ReadMode.MEMORY) {
@ -183,7 +177,7 @@ public class RedissonSession extends StandardSession {
boolean oldValue = isNew;
super.endAccess();
if (isNew != oldValue) {
if (isNew != oldValue && map != null) {
fastPut(IS_NEW_ATTR, isNew);
}
}
@ -218,6 +212,10 @@ public class RedissonSession extends StandardSession {
}
public void save() {
if (map == null) {
map = redissonManager.getMap(id);
}
Map<String, Object> newMap = new HashMap<String, Object>();
newMap.put(CREATION_TIME_ATTR, creationTime);
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);

@ -126,7 +126,6 @@ public class RedissonSessionManager extends ManagerBase {
session.setManager(this);
session.setId(sessionId);
session.save();
return session;
}
@ -185,6 +184,12 @@ public class RedissonSessionManager extends ManagerBase {
return new RedissonSession(this, readMode, updateMode);
}
@Override
public void add(Session session) {
super.add(session);
((RedissonSession)session).save();
}
@Override
public void remove(Session session, boolean update) {
super.remove(session, update);

@ -51,7 +51,7 @@ public class RedissonSession extends StandardSession {
private final RedissonSessionManager redissonManager;
private final Map<String, Object> attrs;
private RMap<String, Object> map;
private RTopic topic;
private final RTopic topic;
private final RedissonSessionManager.ReadMode readMode;
private final UpdateMode updateMode;
@ -60,6 +60,7 @@ public class RedissonSession extends StandardSession {
this.redissonManager = manager;
this.readMode = readMode;
this.updateMode = updateMode;
this.topic = redissonManager.getTopic();
try {
Field attr = StandardSession.class.getDeclaredField("attributes");
@ -80,13 +81,6 @@ public class RedissonSession extends StandardSession {
return super.getAttribute(name);
}
@Override
public void setId(String id, boolean notify) {
super.setId(id, notify);
map = redissonManager.getMap(id);
topic = redissonManager.getTopic();
}
public void delete() {
map.delete();
if (readMode == ReadMode.MEMORY) {
@ -183,7 +177,7 @@ public class RedissonSession extends StandardSession {
boolean oldValue = isNew;
super.endAccess();
if (isNew != oldValue) {
if (isNew != oldValue && map != null) {
fastPut(IS_NEW_ATTR, isNew);
}
}
@ -218,6 +212,10 @@ public class RedissonSession extends StandardSession {
}
public void save() {
if (map == null) {
map = redissonManager.getMap(id);
}
Map<String, Object> newMap = new HashMap<String, Object>();
newMap.put(CREATION_TIME_ATTR, creationTime);
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);

@ -125,7 +125,6 @@ public class RedissonSessionManager extends ManagerBase {
session.setManager(this);
session.setId(sessionId);
session.save();
return session;
}
@ -195,6 +194,12 @@ public class RedissonSessionManager extends ManagerBase {
}
}
@Override
public void add(Session session) {
super.add(session);
((RedissonSession)session).save();
}
public RedissonClient getRedisson() {
return redisson;
}

@ -51,7 +51,7 @@ public class RedissonSession extends StandardSession {
private final RedissonSessionManager redissonManager;
private final Map<String, Object> attrs;
private RMap<String, Object> map;
private RTopic topic;
private final RTopic topic;
private final RedissonSessionManager.ReadMode readMode;
private final UpdateMode updateMode;
@ -60,6 +60,7 @@ public class RedissonSession extends StandardSession {
this.redissonManager = manager;
this.readMode = readMode;
this.updateMode = updateMode;
this.topic = redissonManager.getTopic();
try {
Field attr = StandardSession.class.getDeclaredField("attributes");
@ -80,13 +81,6 @@ public class RedissonSession extends StandardSession {
return super.getAttribute(name);
}
@Override
public void setId(String id, boolean notify) {
super.setId(id, notify);
map = redissonManager.getMap(id);
topic = redissonManager.getTopic();
}
public void delete() {
map.delete();
if (readMode == ReadMode.MEMORY) {
@ -183,7 +177,7 @@ public class RedissonSession extends StandardSession {
boolean oldValue = isNew;
super.endAccess();
if (isNew != oldValue) {
if (isNew != oldValue && map != null) {
fastPut(IS_NEW_ATTR, isNew);
}
}
@ -218,6 +212,10 @@ public class RedissonSession extends StandardSession {
}
public void save() {
if (map == null) {
map = redissonManager.getMap(id);
}
Map<String, Object> newMap = new HashMap<String, Object>();
newMap.put(CREATION_TIME_ATTR, creationTime);
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);

@ -125,7 +125,6 @@ public class RedissonSessionManager extends ManagerBase {
session.setManager(this);
session.setId(sessionId);
session.save();
return session;
}
@ -193,6 +192,12 @@ public class RedissonSessionManager extends ManagerBase {
}
}
@Override
public void add(Session session) {
super.add(session);
((RedissonSession)session).save();
}
public RedissonClient getRedisson() {
return redisson;
}

Loading…
Cancel
Save