Browse files

VYSPER-335: check for NPEs in DefaultResourceRegistry

git-svn-id: https://svn.apache.org/repos/asf/mina/vysper/trunk@1412056 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent cc62884 commit cfbfad6cf13b1b922a1ef7b9598b90451be68188 Bernd Fondermann committed Nov 21, 2012
View
15 ...e/src/main/java/org/apache/vysper/xmpp/state/resourcebinding/DefaultResourceRegistry.java
@@ -136,17 +136,20 @@ public String bindSession(SessionContext sessionContext) {
* @param resourceId
*/
public boolean unbindResource(String resourceId) {
- boolean noResourceRemainsForSession = false;
+ boolean noResourceRemainsForSession;
synchronized (boundResources) {
synchronized (entityResources) {
synchronized (sessionResources) {
SessionContext sessionContext = getSessionContext(resourceId);
// remove from entity's list of resources
List<String> resourceListForEntity = getResourceList(sessionContext.getInitiatingEntity());
- resourceListForEntity.remove(resourceId);
- if (resourceListForEntity.isEmpty())
- entityResources.remove(sessionContext.getInitiatingEntity());
+ if (resourceListForEntity != null) {
+ resourceListForEntity.remove(resourceId);
+ if (resourceListForEntity.isEmpty()) {
+ entityResources.remove(sessionContext.getInitiatingEntity());
+ }
+ }
// remove from session's list of resources
List<String> resourceListForSession = sessionResources.get(sessionContext);
@@ -411,6 +414,8 @@ public void setResourcePriority(String resourceId, int priority) {
public List<String> getInterestedResources(Entity entity) {
List<String> resources = getResourceList(entity);
List<String> result = new ArrayList<String>();
+ if (resources == null) return result;
+
for (String resource : resources) {
ResourceState resourceState = getResourceState(resource);
if (ResourceState.isInterested(resourceState))
@@ -426,6 +431,8 @@ public void setResourcePriority(String resourceId, int priority) {
public List<String> getAvailableResources(Entity entity) {
List<String> resources = getResourceList(entity);
List<String> result = new ArrayList<String>();
+ if (resources == null) return result;
+
for (String resource : resources) {
ResourceState resourceState = getResourceState(resource);
if (resourceState == AVAILABLE || resourceState == AVAILABLE_INTERESTED) {

0 comments on commit cfbfad6

Please sign in to comment.