You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/11/14 21:32:14 UTC

svn commit: r714129 - in /maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-expression/src: main/java/org/apache/maven/plugin/coreit/PropertyUtil.java test/java/org/apache/maven/plugin/coreit/PropertyUtilTest.java

Author: bentmann
Date: Fri Nov 14 12:32:14 2008
New Revision: 714129

URL: http://svn.apache.org/viewvc?rev=714129&view=rev
Log:
o Fixed cycle detection

Modified:
    maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-expression/src/main/java/org/apache/maven/plugin/coreit/PropertyUtil.java
    maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/PropertyUtilTest.java

Modified: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-expression/src/main/java/org/apache/maven/plugin/coreit/PropertyUtil.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-expression/src/main/java/org/apache/maven/plugin/coreit/PropertyUtil.java?rev=714129&r1=714128&r2=714129&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-expression/src/main/java/org/apache/maven/plugin/coreit/PropertyUtil.java (original)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-expression/src/main/java/org/apache/maven/plugin/coreit/PropertyUtil.java Fri Nov 14 12:32:14 2008
@@ -68,8 +68,9 @@
      */
     private static void store( Properties props, String key, Object obj, Collection visited )
     {
-        if ( obj != null )
+        if ( obj != null && !visited.contains( obj ) )
         {
+            visited.add( obj );
             if ( ( obj instanceof String ) || ( obj instanceof Number ) || ( obj instanceof Boolean )
                 || ( obj instanceof File ) )
             {
@@ -83,7 +84,7 @@
                 for ( Iterator it = coll.iterator(); it.hasNext(); index++ )
                 {
                     Object elem = it.next();
-                    store( props, key + "." + index, elem );
+                    store( props, key + "." + index, elem, visited );
                 }
             }
             else if ( obj instanceof Map )
@@ -94,7 +95,7 @@
                 for ( Iterator it = map.entrySet().iterator(); it.hasNext(); index++ )
                 {
                     Map.Entry entry = (Map.Entry) it.next();
-                    store( props, key + "." + entry.getKey(), entry.getValue() );
+                    store( props, key + "." + entry.getKey(), entry.getValue(), visited );
                 }
             }
             else if ( obj.getClass().isArray() )
@@ -104,12 +105,11 @@
                 for ( int index = 0; index < length; index++ )
                 {
                     Object elem = Array.get( obj, index );
-                    store( props, key + "." + index, elem );
+                    store( props, key + "." + index, elem, visited );
                 }
             }
-            else if ( obj != null && !visited.contains( obj ) )
+            else if ( obj != null )
             {
-                visited.add( obj );
                 Class type = obj.getClass();
                 Method[] methods = type.getMethods();
                 for ( int i = 0; i < methods.length; i++ )
@@ -133,8 +133,8 @@
                         // just ignore
                     }
                 }
-                visited.remove( obj );
             }
+            visited.remove( obj );
         }
     }
 

Modified: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/PropertyUtilTest.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/PropertyUtilTest.java?rev=714129&r1=714128&r2=714129&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/PropertyUtilTest.java (original)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-expression/src/test/java/org/apache/maven/plugin/coreit/PropertyUtilTest.java Fri Nov 14 12:32:14 2008
@@ -93,6 +93,16 @@
         assertEquals( 2, props.size() );
     }
 
+    public void testStoreCycle()
+    {
+        Object[] arr = { null };
+        arr[0] = Collections.singleton( Collections.singletonMap( "key", arr ) );
+
+        Properties props = new Properties();
+        PropertyUtil.store( props, "cycle", arr );
+        assertTrue( "Should not die because of stack overflow", true );
+    }
+
     public void testGetPropertyName()
     {
         assertEquals( "name", PropertyUtil.getPropertyName( "getName" ) );