[jbosscache-commits] JBoss Cache SVN: r5958 - in core/trunk/src: test/java/org/jboss/cache and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Jun 5 06:34:51 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-06-05 06:34:51 -0400 (Thu, 05 Jun 2008)
New Revision: 5958

Modified:
   core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
   core/trunk/src/test/java/org/jboss/cache/DataContainerTest.java
Log:
JBCACHE-1361: NPE when doing a recursive evict

Modified: core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java	2008-06-05 10:07:17 UTC (rev 5957)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java	2008-06-05 10:34:51 UTC (rev 5958)
@@ -239,7 +239,7 @@
       NodeSPI node = peek(fqn, false);
       if (recursive)
       {
-         recursiveAddEvictionNodes(node, result);
+         if (node != null) recursiveAddEvictionNodes(node, result);
       }
       else
       {
@@ -263,14 +263,14 @@
       return result;
    }
 
-   private void recursiveAddEvictionNodes(NodeSPI node, List<Fqn> result)
+   private void recursiveAddEvictionNodes(NodeSPI<?, ?> node, List<Fqn> result)
    {
-      for (NodeSPI child : (Set<NodeSPI>) node.getChildrenDirect())
+      for (NodeSPI<?, ?> child : node.getChildrenDirect())
       {
          recursiveAddEvictionNodes(child, result);
       }
       Fqn fqn = node.getFqn();
-      if (node != null && !fqn.isRoot() && !node.isResident())
+      if (!fqn.isRoot() && !node.isResident())
       {
          result.add(fqn);
       }
@@ -289,6 +289,9 @@
 
    /**
     * Returns a debug string with optional details of contents.
+    *
+    * @param details if true, details are printed
+    * @return detailed contents of the container
     */
    @SuppressWarnings("deprecation")
    public String toString(boolean details)
@@ -358,6 +361,8 @@
     * Prints information about the contents of the nodes in the cache's current
     * in-memory state.  Does not load any previously evicted nodes from a
     * cache loader, so evicted nodes will not be included.
+    *
+    * @return details
     */
    public String printDetails()
    {
@@ -370,6 +375,8 @@
 
    /**
     * Returns lock information.
+    *
+    * @return lock info
     */
    public String printLockInfo()
    {
@@ -397,6 +404,8 @@
     * the cache. Since this method doesn't acquire any locks, the number might
     * be incorrect, or the method might even throw a
     * ConcurrentModificationException
+    *
+    * @return number of attribs
     */
    public int getNumberOfAttributes()
    {

Modified: core/trunk/src/test/java/org/jboss/cache/DataContainerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/DataContainerTest.java	2008-06-05 10:07:17 UTC (rev 5957)
+++ core/trunk/src/test/java/org/jboss/cache/DataContainerTest.java	2008-06-05 10:34:51 UTC (rev 5958)
@@ -203,6 +203,23 @@
    }
 
    /**
+    * tests {@link DataContainerImpl#getNodesForEviction(Fqn, boolean)} in a recursive scenario.
+    */
+   public void testGetNodesForEvictionRecursiveNullNodes()
+   {
+      container.removeFromDataStructure(nodes.ad, true);
+      //check for root first
+      List<Fqn> result = container.getNodesForEviction(Fqn.ROOT, true);
+      assert result.size() == 3 : "all children are considered for eviction";
+
+      //check normal
+      // this node does not exist!!  Should NOT throw a NPE.
+      result = container.getNodesForEviction(nodes.ad, true);
+      assert result.isEmpty() : "Should be empty";
+   }
+
+
+   /**
     * tests {@link DataContainerImpl#getNumberOfNodes()}
     */
    public void testGetNumberOfNodes()




More information about the jbosscache-commits mailing list