felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1186839 - in /felix/trunk/configadmin/src: main/java/org/apache/felix/cm/file/ConfigurationHandler.java test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java
Date Thu, 20 Oct 2011 14:44:27 GMT
Author: fmeschbe
Date: Thu Oct 20 14:44:27 2011
New Revision: 1186839

URL: http://svn.apache.org/viewvc?rev=1186839&view=rev
Log:
FELIX-3046 Ensure empty arrays and collections are written out to the files and read again

Modified:
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java
    felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java?rev=1186839&r1=1186838&r2=1186839&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java
(original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java
Thu Oct 20 14:44:27 2011
@@ -96,8 +96,8 @@ public class ConfigurationHandler
 
     protected static final String CRLF = "\r\n";
 
-    protected static final Map type2Code;
     protected static final Map code2Type;
+    protected static final Map type2Code;
 
     // set of valid characters for "symblic-name"
     private static final BitSet NAME_CHARS;
@@ -336,23 +336,23 @@ public class ConfigurationHandler
         List list = new ArrayList();
         for ( ;; )
         {
-            if ( !checkNext( pr, TOKEN_VAL_OPEN ) )
+            int c = read(pr);
+            if ( c == TOKEN_VAL_OPEN )
             {
-                return null;
-            }
+                Object value = readSimple( typeCode, pr );
+                if ( value == null )
+                {
+                    // abort due to error
+                    return null;
+                }
 
-            Object value = readSimple( typeCode, pr );
-            if ( value == null )
-            {
-                // abort due to error
-                return null;
-            }
+                ensureNext( pr, TOKEN_VAL_CLOS );
 
-            ensureNext( pr, TOKEN_VAL_CLOS );
+                list.add( value );
 
-            list.add( value );
+                c = read( pr );
+            }
 
-            int c = read( pr );
             if ( c == TOKEN_ARR_CLOS )
             {
                 Class type = ( Class ) code2Type.get( new Integer( typeCode ) );
@@ -380,23 +380,23 @@ public class ConfigurationHandler
         Collection collection = new ArrayList();
         for ( ;; )
         {
-            if ( !checkNext( pr, TOKEN_VAL_OPEN ) )
+            int c = read( pr );
+            if ( c == TOKEN_VAL_OPEN )
             {
-                return null;
-            }
+                Object value = readSimple( typeCode, pr );
+                if ( value == null )
+                {
+                    // abort due to error
+                    return null;
+                }
 
-            Object value = readSimple( typeCode, pr );
-            if ( value == null )
-            {
-                // abort due to error
-                return null;
-            }
+                ensureNext( pr, TOKEN_VAL_CLOS );
 
-            ensureNext( pr, TOKEN_VAL_CLOS );
+                collection.add( value );
 
-            collection.add( value );
+                c = read( pr );
+            }
 
-            int c = read( pr );
             if ( c == TOKEN_VEC_CLOS )
             {
                 return collection;
@@ -676,11 +676,6 @@ public class ConfigurationHandler
     private static void writeArray( Writer out, Object arrayValue ) throws IOException
     {
         int size = Array.getLength( arrayValue );
-        if ( size == 0 )
-        {
-            return;
-        }
-
         writeType( out, arrayValue.getClass().getComponentType() );
         out.write( TOKEN_ARR_OPEN );
         for ( int i = 0; i < size; i++ )
@@ -697,22 +692,25 @@ public class ConfigurationHandler
     {
         if ( collection.isEmpty() )
         {
-            return;
+            out.write( TOKEN_VEC_OPEN );
+            out.write( TOKEN_VEC_CLOS );
         }
+        else
+        {
+            Iterator ci = collection.iterator();
+            Object firstElement = ci.next();
 
-        Iterator ci = collection.iterator();
-        Object firstElement = ci.next();
-
-        writeType( out, firstElement.getClass() );
-        out.write( TOKEN_VEC_OPEN );
-        writeSimple( out, firstElement );
+            writeType( out, firstElement.getClass() );
+            out.write( TOKEN_VEC_OPEN );
+            writeSimple( out, firstElement );
 
-        while ( ci.hasNext() )
-        {
-            out.write( TOKEN_COMMA );
-            writeSimple( out, ci.next() );
+            while ( ci.hasNext() )
+            {
+                out.write( TOKEN_COMMA );
+                writeSimple( out, ci.next() );
+            }
+            out.write( TOKEN_VEC_CLOS );
         }
-        out.write( TOKEN_VEC_CLOS );
     }
 
 

Modified: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java?rev=1186839&r1=1186838&r2=1186839&view=diff
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java
(original)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerTest.java
Thu Oct 20 14:44:27 2011
@@ -22,6 +22,7 @@ package org.apache.felix.cm.file;
 import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Array;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.Enumeration;
@@ -115,6 +116,15 @@ public class FilePersistenceManagerTest 
     }
 
 
+    public void testEmptyArray() throws IOException
+    {
+        check( "StringArray", new String[0] );
+        check( "IntArray", new int[0] );
+        check( "CharArray", new char[0] );
+        check( "ShortArray", new short[0] );
+    }
+
+
     public void testVector() throws IOException
     {
         check( "StringVector", new Vector( Arrays.asList( new String[]
@@ -124,6 +134,15 @@ public class FilePersistenceManagerTest 
     }
 
 
+    public void testEmptyVector() throws IOException
+    {
+        check( "StringArray", new Vector() );
+        check( "IntArray", new Vector() );
+        check( "CharArray", new Vector() );
+        check( "ShortArray", new Vector() );
+    }
+
+
     public void testList() throws IOException
     {
         check( "StringList", Arrays.asList( new String[]
@@ -133,6 +152,15 @@ public class FilePersistenceManagerTest 
     }
 
 
+    public void testEmptyList() throws IOException
+    {
+        check( "StringArray", new ArrayList(0) );
+        check( "IntArray", new ArrayList(0) );
+        check( "CharArray", new ArrayList(0) );
+        check( "ShortArray", new ArrayList(0) );
+    }
+
+
     public void testMultiValue() throws IOException
     {
         Dictionary props = new Hashtable();



Mime
View raw message