Fixed - ConcurrentModificationException thrown on RedissonSession save method if readMode = MEMORY and updateMode = AFTER_REQUEST #5677

pull/5711/head
Nikita Koksharov 10 months ago
parent 4036874862
commit 64d1ab55d4

@ -37,26 +37,30 @@ public class AttributesPutAllMessage extends AttributeMessage {
public AttributesPutAllMessage() {
}
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs, Encoder encoder) throws Exception {
super(nodeId, sessionId);
public AttributesPutAllMessage(RedissonSessionManager redissonSessionManager, String sessionId, Map<String, Object> attrs, Encoder encoder) throws Exception {
super(redissonSessionManager.getNodeId(), sessionId);
if (attrs != null) {
this.attrs = new HashMap<>();
for (Entry<String, Object> entry: attrs.entrySet()) {
Object value = entry.getValue();
try {
if (value instanceof Collection) {
Collection newInstance = (Collection) value.getClass().getDeclaredConstructor().newInstance();
newInstance.addAll((Collection) value);
value = newInstance;
if (redissonSessionManager.getReadMode()
.equals(RedissonSessionManager.ReadMode.MEMORY.toString())) {
try {
if (value instanceof Collection) {
Collection newInstance = (Collection) value.getClass().getDeclaredConstructor().newInstance();
newInstance.addAll((Collection) value);
value = newInstance;
}
if (value instanceof Map) {
Map newInstance = (Map) value.getClass().getDeclaredConstructor().newInstance();
newInstance.putAll((Map) value);
value = newInstance;
}
} catch (Exception e) {
// can't be copied
}
if (value instanceof Map) {
Map newInstance = (Map) value.getClass().getDeclaredConstructor().newInstance();
newInstance.putAll((Map) value);
value = newInstance;
}
} catch (Exception e) {
// can't be copied
}
this.attrs.put(entry.getKey(), toByteArray(encoder, value));
}
} else {

@ -236,7 +236,7 @@ public class RedissonSession extends StandardSession {
protected AttributesPutAllMessage createPutAllMessage(Map<String, Object> newMap) {
try {
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), newMap, this.map.getCodec().getMapValueEncoder());
return new AttributesPutAllMessage(redissonManager, getId(), newMap, this.map.getCodec().getMapValueEncoder());
} catch (Exception e) {
throw new IllegalStateException(e);
}

@ -36,26 +36,30 @@ public class AttributesPutAllMessage extends AttributeMessage {
public AttributesPutAllMessage() {
}
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs, Encoder encoder) throws Exception {
super(nodeId, sessionId);
public AttributesPutAllMessage(RedissonSessionManager redissonSessionManager, String sessionId, Map<String, Object> attrs, Encoder encoder) throws Exception {
super(redissonSessionManager.getNodeId(), sessionId);
if (attrs != null) {
this.attrs = new HashMap<>();
for (Entry<String, Object> entry: attrs.entrySet()) {
Object value = entry.getValue();
try {
if (value instanceof Collection) {
Collection newInstance = (Collection) value.getClass().getDeclaredConstructor().newInstance();
newInstance.addAll((Collection) value);
value = newInstance;
if (redissonSessionManager.getReadMode()
.equals(RedissonSessionManager.ReadMode.MEMORY.toString())) {
try {
if (value instanceof Collection) {
Collection newInstance = (Collection) value.getClass().getDeclaredConstructor().newInstance();
newInstance.addAll((Collection) value);
value = newInstance;
}
if (value instanceof Map) {
Map newInstance = (Map) value.getClass().getDeclaredConstructor().newInstance();
newInstance.putAll((Map) value);
value = newInstance;
}
} catch (Exception e) {
// can't be copied
}
if (value instanceof Map) {
Map newInstance = (Map) value.getClass().getDeclaredConstructor().newInstance();
newInstance.putAll((Map) value);
value = newInstance;
}
} catch (Exception e) {
// can't be copied
}
this.attrs.put(entry.getKey(), toByteArray(encoder, value));
}
} else {

@ -230,7 +230,7 @@ public class RedissonSession extends StandardSession {
protected AttributesPutAllMessage createPutAllMessage(Map<String, Object> newMap) {
try {
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), newMap, this.map.getCodec().getMapValueEncoder());
return new AttributesPutAllMessage(redissonManager, getId(), newMap, this.map.getCodec().getMapValueEncoder());
} catch (Exception e) {
throw new IllegalStateException(e);
}

@ -36,26 +36,30 @@ public class AttributesPutAllMessage extends AttributeMessage {
public AttributesPutAllMessage() {
}
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs, Encoder encoder) throws Exception {
super(nodeId, sessionId);
public AttributesPutAllMessage(RedissonSessionManager redissonSessionManager, String sessionId, Map<String, Object> attrs, Encoder encoder) throws Exception {
super(redissonSessionManager.getNodeId(), sessionId);
if (attrs != null) {
this.attrs = new HashMap<>();
for (Entry<String, Object> entry: attrs.entrySet()) {
Object value = entry.getValue();
try {
if (value instanceof Collection) {
Collection newInstance = (Collection) value.getClass().getDeclaredConstructor().newInstance();
newInstance.addAll((Collection) value);
value = newInstance;
if (redissonSessionManager.getReadMode()
.equals(RedissonSessionManager.ReadMode.MEMORY.toString())) {
try {
if (value instanceof Collection) {
Collection newInstance = (Collection) value.getClass().getDeclaredConstructor().newInstance();
newInstance.addAll((Collection) value);
value = newInstance;
}
if (value instanceof Map) {
Map newInstance = (Map) value.getClass().getDeclaredConstructor().newInstance();
newInstance.putAll((Map) value);
value = newInstance;
}
} catch (Exception e) {
// can't be copied
}
if (value instanceof Map) {
Map newInstance = (Map) value.getClass().getDeclaredConstructor().newInstance();
newInstance.putAll((Map) value);
value = newInstance;
}
} catch (Exception e) {
// can't be copied
}
this.attrs.put(entry.getKey(), toByteArray(encoder, value));
}
} else {

@ -231,7 +231,7 @@ public class RedissonSession extends StandardSession {
protected AttributesPutAllMessage createPutAllMessage(Map<String, Object> newMap) {
try {
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), newMap, this.map.getCodec().getMapValueEncoder());
return new AttributesPutAllMessage(redissonManager, getId(), newMap, this.map.getCodec().getMapValueEncoder());
} catch (Exception e) {
throw new IllegalStateException(e);
}

@ -36,26 +36,30 @@ public class AttributesPutAllMessage extends AttributeMessage {
public AttributesPutAllMessage() {
}
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs, Encoder encoder) throws Exception {
super(nodeId, sessionId);
public AttributesPutAllMessage(RedissonSessionManager redissonSessionManager, String sessionId, Map<String, Object> attrs, Encoder encoder) throws Exception {
super(redissonSessionManager.getNodeId(), sessionId);
if (attrs != null) {
this.attrs = new HashMap<>();
for (Entry<String, Object> entry: attrs.entrySet()) {
Object value = entry.getValue();
try {
if (value instanceof Collection) {
Collection newInstance = (Collection) value.getClass().getDeclaredConstructor().newInstance();
newInstance.addAll((Collection) value);
value = newInstance;
if (redissonSessionManager.getReadMode()
.equals(RedissonSessionManager.ReadMode.MEMORY.toString())) {
try {
if (value instanceof Collection) {
Collection newInstance = (Collection) value.getClass().getDeclaredConstructor().newInstance();
newInstance.addAll((Collection) value);
value = newInstance;
}
if (value instanceof Map) {
Map newInstance = (Map) value.getClass().getDeclaredConstructor().newInstance();
newInstance.putAll((Map) value);
value = newInstance;
}
} catch (Exception e) {
// can't be copied
}
if (value instanceof Map) {
Map newInstance = (Map) value.getClass().getDeclaredConstructor().newInstance();
newInstance.putAll((Map) value);
value = newInstance;
}
} catch (Exception e) {
// can't be copied
}
this.attrs.put(entry.getKey(), toByteArray(encoder, value));
}
} else {

@ -231,7 +231,7 @@ public class RedissonSession extends StandardSession {
protected AttributesPutAllMessage createPutAllMessage(Map<String, Object> newMap) {
try {
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), newMap, this.map.getCodec().getMapValueEncoder());
return new AttributesPutAllMessage(redissonManager, getId(), newMap, this.map.getCodec().getMapValueEncoder());
} catch (Exception e) {
throw new IllegalStateException(e);
}

Loading…
Cancel
Save