Fixed - NPE arise during Tomcat Session getAttribute/delete methods invocation.

getAttributeNames and getValueNames methods implementation. #1874
2.x.x
Nikita Koksharov 6 years ago
parent 2b4529c736
commit 31dfbdbcf2

@ -18,6 +18,8 @@ package org.redisson.tomcat;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -76,13 +78,52 @@ public class RedissonSession extends StandardSession {
@Override
public Object getAttribute(String name) {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException(sm.getString("standardSession.getAttribute.ise"));
}
if (name == null) {
return null;
}
return map.get(name);
}
return super.getAttribute(name);
}
@Override
public Enumeration<String> getAttributeNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
return Collections.enumeration(map.readAllKeySet());
}
return super.getAttributeNames();
}
@Override
public String[] getValueNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
Set<String> keys = map.readAllKeySet();
return keys.toArray(new String[keys.size()]);
}
return super.getValueNames();
}
public void delete() {
if (map == null) {
map = redissonManager.getMap(id);
}
map.delete();
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));

@ -18,6 +18,8 @@ package org.redisson.tomcat;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -76,13 +78,52 @@ public class RedissonSession extends StandardSession {
@Override
public Object getAttribute(String name) {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException(sm.getString("standardSession.getAttribute.ise"));
}
if (name == null) {
return null;
}
return map.get(name);
}
return super.getAttribute(name);
}
@Override
public Enumeration<String> getAttributeNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
return Collections.enumeration(map.readAllKeySet());
}
return super.getAttributeNames();
}
@Override
public String[] getValueNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
Set<String> keys = map.readAllKeySet();
return keys.toArray(new String[keys.size()]);
}
return super.getValueNames();
}
public void delete() {
if (map == null) {
map = redissonManager.getMap(id);
}
map.delete();
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));

@ -18,6 +18,8 @@ package org.redisson.tomcat;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -76,13 +78,52 @@ public class RedissonSession extends StandardSession {
@Override
public Object getAttribute(String name) {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException(sm.getString("standardSession.getAttribute.ise"));
}
if (name == null) {
return null;
}
return map.get(name);
}
return super.getAttribute(name);
}
@Override
public Enumeration<String> getAttributeNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
return Collections.enumeration(map.readAllKeySet());
}
return super.getAttributeNames();
}
@Override
public String[] getValueNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
Set<String> keys = map.readAllKeySet();
return keys.toArray(new String[keys.size()]);
}
return super.getValueNames();
}
public void delete() {
if (map == null) {
map = redissonManager.getMap(id);
}
map.delete();
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));

@ -18,6 +18,8 @@ package org.redisson.tomcat;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -76,13 +78,52 @@ public class RedissonSession extends StandardSession {
@Override
public Object getAttribute(String name) {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException(sm.getString("standardSession.getAttribute.ise"));
}
if (name == null) {
return null;
}
return map.get(name);
}
return super.getAttribute(name);
}
@Override
public Enumeration<String> getAttributeNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
return Collections.enumeration(map.readAllKeySet());
}
return super.getAttributeNames();
}
@Override
public String[] getValueNames() {
if (readMode == ReadMode.REDIS) {
if (!isValidInternal()) {
throw new IllegalStateException
(sm.getString("standardSession.getAttributeNames.ise"));
}
Set<String> keys = map.readAllKeySet();
return keys.toArray(new String[keys.size()]);
}
return super.getValueNames();
}
public void delete() {
if (map == null) {
map = redissonManager.getMap(id);
}
map.delete();
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));

Loading…
Cancel
Save