From 0701cf10b389a3b27e5f428abe64ea4cd27805ec Mon Sep 17 00:00:00 2001
From: ctissot <ctissot@localhost>
Date: Mon, 10 Mar 2008 13:15:01 +0000
Subject: [PATCH] Fix for issue #3036: Searching for the workflow candidate might generate an exception

---
 opendj-sdk/opends/src/server/org/opends/server/core/NetworkGroupNamingContexts.java |   54 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/core/NetworkGroupNamingContexts.java b/opendj-sdk/opends/src/server/org/opends/server/core/NetworkGroupNamingContexts.java
index f65fa96..957994f 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/core/NetworkGroupNamingContexts.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/core/NetworkGroupNamingContexts.java
@@ -27,7 +27,9 @@
 package org.opends.server.core;
 
 
-import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 
 /**
@@ -36,21 +38,34 @@
 public class NetworkGroupNamingContexts
 {
   // List of naming contexts.
-  private ArrayList<WorkflowTopologyNode> namingContexts = null;
+  private List<WorkflowTopologyNode> namingContexts;
+  // If list of naming contexts is returned, ensure it is immutable
+  private List<WorkflowTopologyNode> _namingContexts;
 
   // List of public naming contexts.
-  private ArrayList<WorkflowTopologyNode> publicNamingContexts = null;
+  private List<WorkflowTopologyNode> publicNamingContexts;
+  // If list of public naming contexts is returned, ensure it is immutable
+  private List<WorkflowTopologyNode> _publicNamingContexts;
 
   // List of private naming contexts.
-  private ArrayList<WorkflowTopologyNode> privateNamingContexts = null;
+  private List<WorkflowTopologyNode> privateNamingContexts;
+  // If list of private naming contexts is returned, ensure it is immutable
+  private List<WorkflowTopologyNode> _privateNamingContexts;
 
   /**
    * Create a list of naming contexts for a network group.
    */
   public NetworkGroupNamingContexts()
   {
-    // create the lists of naming contexts
-    resetLists();
+    namingContexts  = new CopyOnWriteArrayList<WorkflowTopologyNode>();
+    _namingContexts = Collections.unmodifiableList(namingContexts);
+
+    privateNamingContexts  = new CopyOnWriteArrayList<WorkflowTopologyNode>();
+    _privateNamingContexts =
+                            Collections.unmodifiableList(privateNamingContexts);
+
+    publicNamingContexts  = new CopyOnWriteArrayList<WorkflowTopologyNode>();
+    _publicNamingContexts = Collections.unmodifiableList(publicNamingContexts);
   }
 
 
@@ -59,9 +74,9 @@
    */
   public void resetLists()
   {
-    namingContexts        = new ArrayList<WorkflowTopologyNode>();
-    privateNamingContexts = new ArrayList<WorkflowTopologyNode>();
-    publicNamingContexts  = new ArrayList<WorkflowTopologyNode>();
+    namingContexts.clear();
+    privateNamingContexts.clear();
+    publicNamingContexts.clear();
   }
 
 
@@ -92,33 +107,42 @@
   /**
    * Get the list of naming contexts.
    *
+   * <br>Note: the returned iterable instance is immutable and attempts to
+   * remove elements will throw an UnsupportedOperationException exception.
+   *
    * @return the list of all the naming contexts
    */
-  public ArrayList<WorkflowTopologyNode> getNamingContexts()
+  public Iterable<WorkflowTopologyNode> getNamingContexts()
   {
-    return namingContexts;
+    return _namingContexts;
   }
 
 
   /**
    * Get the list of private naming contexts.
    *
+   * <br>Note: the returned iterable instance is immutable and attempts to
+   * remove elements will throw an UnsupportedOperationException exception.
+   *
    * @return the list of private naming contexts
    */
-  public ArrayList<WorkflowTopologyNode> getPrivateNamingContexts()
+  public Iterable<WorkflowTopologyNode> getPrivateNamingContexts()
   {
-    return privateNamingContexts;
+    return _privateNamingContexts;
   }
 
 
   /**
    * Get the list of public naming contexts.
    *
+   * <br>Note: the returned iterable instance is immutable and attempts to
+   * remove elements will throw an UnsupportedOperationException exception.
+   *
    * @return the list of public naming contexts
    */
-  public ArrayList<WorkflowTopologyNode> getPublicNamingContexts()
+  public Iterable<WorkflowTopologyNode> getPublicNamingContexts()
   {
-    return publicNamingContexts;
+    return _publicNamingContexts;
   }
 
 

--
Gitblit v1.10.0