harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r957178 [2/3] - in /harmony/enhanced/java/branches/mrh: ./ classlib/ classlib/depends/build/ classlib/depends/build/platform/ classlib/modules/beans/src/main/java/java/beans/ classlib/modules/beans/src/main/java/org/apache/harmony/beans/ cl...
Date Wed, 23 Jun 2010 12:58:31 GMT
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/FloatEditor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/FloatEditor.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/FloatEditor.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/FloatEditor.java Wed Jun 23 12:58:28 2010
@@ -36,7 +36,7 @@ public final class FloatEditor extends P
 
     @Override
     public String getJavaInitializationString() {
-        return getValue()+"F";
+        return getValue() + "F"; //$NON-NLS-1$
     }
 
     @Override

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/FontEditor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/FontEditor.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/FontEditor.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/FontEditor.java Wed Jun 23 12:58:28 2010
@@ -58,14 +58,16 @@ public class FontEditor extends Panel im
     }
 
     public String getJavaInitializationString() {
-        String result = null;
-        if (value!= null) {
-            String name = value.getName();
-            int style = value.getStyle();
-            int size = value.getSize();
-            result = "new Font(" + name + "," + style + "," + size + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+        if (value != null) {
+            StringBuilder sb = new StringBuilder("new Font("); //$NON-NLS-1$
+            sb.append(value.getName());
+            sb.append(',');
+            sb.append(value.getStyle());
+            sb.append(',');
+            sb.append(value.getSize() + ")"); //$NON-NLS-1$
+            return sb.toString();
         }
-        return result;
+        return null;
     }
 
     public String[] getTags() {
@@ -77,8 +79,8 @@ public class FontEditor extends Panel im
         value = (Font)newValue;
         PropertyChangeEvent changeAllEvent = new PropertyChangeEvent(this,
                 "value", oldValue, value); //$NON-NLS-1$
-        PropertyChangeListener[] copy = new PropertyChangeListener[listeners.size()];
-        listeners.toArray(copy);
+        PropertyChangeListener[] copy = listeners
+                .toArray(new PropertyChangeListener[0]);
         for (PropertyChangeListener listener : copy) {
             listener.propertyChange(changeAllEvent);
         }

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/IntEditor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/IntEditor.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/IntEditor.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/IntEditor.java Wed Jun 23 12:58:28 2010
@@ -52,12 +52,10 @@ public final class IntEditor extends Pro
     }
 
     private String getValueAsText() {
-        String result = null;
         Object value = getValue();
         if (value != null) {
-            Integer iValue = (Integer) value;
-            result = iValue.toString();
+            return ((Integer) value).toString();
         }
-        return result;
+        return null;
     }
 }

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/LongEditor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/LongEditor.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/LongEditor.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/LongEditor.java Wed Jun 23 12:58:28 2010
@@ -36,7 +36,7 @@ public final class LongEditor extends Pr
 
     @Override
     public String getJavaInitializationString() {
-        return getValue()+"L";
+        return getValue() + "L"; //$NON-NLS-1$
     }
 
     @Override

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/ShortEditor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/ShortEditor.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/ShortEditor.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/ShortEditor.java Wed Jun 23 12:58:28 2010
@@ -36,7 +36,8 @@ public final class ShortEditor extends P
 
     @Override
     public String getJavaInitializationString() {
-        return new StringBuilder().append("((short)").append(getValue()).append(")").toString();
+        return new StringBuilder()
+                .append("((short)").append(getValue()).append(")").toString(); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     @Override

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/StringEditor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/StringEditor.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/StringEditor.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/main/java/org/apache/harmony/beans/editors/StringEditor.java Wed Jun 23 12:58:28 2010
@@ -37,7 +37,7 @@ public final class StringEditor extends 
 
     @Override
     public String getJavaInitializationString() {
-        Object value = getValue(); 
-        return value==null?"\"null\"":"\""+value+"\"";
+        Object value = getValue();
+        return value == null ? "\"null\"" : "\"" + value + "\"";
     }
 }

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java Wed Jun 23 12:58:28 2010
@@ -828,6 +828,45 @@ public class DefaultPersistenceDelegateT
         pd.writeObject(ia, enc);
     }
 
+    class MockDefaultPersistenceDelegate extends DefaultPersistenceDelegate {
+        public MockDefaultPersistenceDelegate(String[] args) {
+            super(args);
+        }
+
+        public boolean mockMutatesTo(Object obj1, Object obj2) {
+            return mutatesTo(obj1, obj2);
+        }
+    }
+
+    public void test_MutatesTo_scenario1() throws Exception {
+        MockDefaultPersistenceDelegate mockDPD = new MockDefaultPersistenceDelegate(
+                new String[1]);
+        try {
+            mockDPD.mockMutatesTo((Object) null, (Object) null);
+            fail("should throw NPE");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+
+        try {
+            mockDPD.mockMutatesTo((Object) null, (Object) "");
+            fail("should throw NPE");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+
+        assertFalse(mockDPD.mockMutatesTo((Object) "", (Object) null));
+    }
+
+    public void test_MutatesTo_scenario2() throws Exception {
+        MockDefaultPersistenceDelegate mockDPD = new MockDefaultPersistenceDelegate(
+                new String[0]);
+        assertFalse(mockDPD.mockMutatesTo((Object) null, (Object) null));
+        assertFalse(mockDPD.mockMutatesTo((Object) null, (Object) ""));
+        assertFalse(mockDPD.mockMutatesTo((Object) "", (Object) null));
+        assertTrue(mockDPD.mockMutatesTo((Object) "", (Object) ""));
+    }
+
     /*
      * BeanInfo for the MockBean below.
      */

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventHandlerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventHandlerTest.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventHandlerTest.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventHandlerTest.java Wed Jun 23 12:58:28 2010
@@ -106,6 +106,13 @@ public class EventHandlerTest extends Te
 
         assertEquals(invocationObject, handler.getTarget());
         assertEquals(invocationObject.getSomeText(), getText());
+        try {
+            handler.invoke(proxy, null, new Object[] { new ActionEvent(this, 0,
+                    "") });
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
     }
 
     /**

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/FeatureDescriptorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/FeatureDescriptorTest.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/FeatureDescriptorTest.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/FeatureDescriptorTest.java Wed Jun 23 12:58:28 2010
@@ -251,11 +251,25 @@ public class FeatureDescriptorTest exten
         fd.setValue(attributeName, value);
         assertSame(value, fd.getValue(attributeName));
 
-        Object newValue = null;
         try {
-            fd.setValue(attributeName, newValue);
-            fail("Should throw NullPointerException.");
+            fd.setValue(null, value);
+            fail("Should throw NullPointerException");
         } catch (NullPointerException e) {
+            // Expected
+        }
+
+        try {
+            fd.setValue(attributeName, null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+
+        try {
+            fd.setValue(null, null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
         }
     }
 

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java Wed Jun 23 12:58:28 2010
@@ -122,6 +122,11 @@ public class IntrospectorTest extends Te
         }
     }
 
+    public void testBeanDescriptor_Same() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MockJavaBean.class);
+        assertSame(beanInfo.getBeanDescriptor(), beanInfo.getBeanDescriptor());
+    }
+
     /**
      * The test checks the getMethodDescriptor method
      * 

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java Wed Jun 23 12:58:28 2010
@@ -102,15 +102,14 @@ public class PropertyEditorManagerTest e
     public void testFindEditor_TypeNull() {
         try {
             PropertyEditorManager.findEditor(null);
-            fail("Should throw NullPointerException.");
+            fail("Should throw NullPointerException");
         } catch (NullPointerException e) {
-            // expected
+            // Expected
         }
     }
 
     public void testFindEditor_TypeNoEditor() {
-        PropertyEditor editor = PropertyEditorManager.findEditor(MockFoo.class);
-        assertNull(editor);
+        assertNull(PropertyEditorManager.findEditor(MockFoo.class));
     }
 
     public void testGetEditorSearchPath_default() {
@@ -157,9 +156,9 @@ public class PropertyEditorManagerTest e
     public void testRegisterEditorType_Null() {
         try {
             PropertyEditorManager.registerEditor(null, ButtonEditor.class);
-            fail("Should throw NullPointerException.");
+            fail("Should throw NullPointerException");
         } catch (NullPointerException e) {
-            // expected
+            // Expected
         }
     }
 
@@ -171,6 +170,7 @@ public class PropertyEditorManagerTest e
         PropertyEditorManager.setEditorSearchPath(new String[] { null });
         assertEquals(1, PropertyEditorManager.getEditorSearchPath().length);
         assertNull(PropertyEditorManager.getEditorSearchPath()[0]);
+        assertNull(PropertyEditorManager.findEditor(PropertyEditorManagerTest.class));
         PropertyEditorManager.setEditorSearchPath(original);
     }
 
@@ -204,8 +204,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Boolean.TYPE);
         try {
             editor.setAsText(null);
-            fail("Should throw a NPException");
+            fail("Should throw NullPointerException");
         } catch (NullPointerException e) {
+            // Expected
         }
     }
 
@@ -213,13 +214,15 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Boolean.TYPE);
         try {
             editor.setAsText("yes");
-            fail("Should throw a IllegalArgumentException");
+            fail("Should throw IllegalArgumentException");
         } catch (IllegalArgumentException e) {
+            // Expected
         }
         try {
             editor.setAsText("***true***");
-            fail("Should throw a IllegalArgumentException");
+            fail("Should throw IllegalArgumentException");
         } catch (IllegalArgumentException e) {
+            // Expected
         }
     }
 
@@ -269,8 +272,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Byte.TYPE);
         try {
             editor.setAsText(null);
-            fail("Should throw a NumberFormatException");
+            fail("Should throw NumberFormatException");
         } catch (NumberFormatException e) {
+            // Expected
         }
     }
 
@@ -278,8 +282,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Byte.TYPE);
         try {
             editor.setAsText("invalid");
-            fail("Should throw a NumberFormatException");
+            fail("Should throw NumberFormatException");
         } catch (NumberFormatException e) {
+            // Expected
         }
     }
 
@@ -287,8 +292,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Byte.TYPE);
         try {
             editor.setAsText("128");
-            fail("Should throw a NumberFormatException");
+            fail("Should throw NumberFormatException");
         } catch (NumberFormatException e) {
+            // Expected
         }
     }
 
@@ -306,8 +312,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Double.TYPE);
         try {
             editor.setAsText(null);
-            fail("Should throw a NullPointerException");
+            fail("Should throw NullPointerException");
         } catch (NullPointerException e) {
+            // Expected
         }
     }
 
@@ -315,8 +322,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Double.TYPE);
         try {
             editor.setAsText("invalid");
-            fail("Should throw a NumberFormatException");
+            fail("Should throw NumberFormatException");
         } catch (NumberFormatException e) {
+            // Expected
         }
     }
 
@@ -335,8 +343,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Float.TYPE);
         try {
             editor.setAsText(null);
-            fail("Should throw a NullPointerException");
+            fail("Should throw NullPointerException");
         } catch (NullPointerException e) {
+            // Expected
         }
     }
 
@@ -344,8 +353,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Float.TYPE);
         try {
             editor.setAsText("invalid");
-            fail("Should throw a NumberFormatException");
+            fail("Should throw NumberFormatException");
         } catch (NumberFormatException e) {
+            // Expected
         }
     }
 
@@ -364,8 +374,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Long.TYPE);
         try {
             editor.setAsText(null);
-            fail("Should throw a NumberFormatException");
+            fail("Should throw NumberFormatException");
         } catch (NumberFormatException e) {
+            // Expected
         }
     }
 
@@ -373,8 +384,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Long.TYPE);
         try {
             editor.setAsText("invalid");
-            fail("Should throw a NumberFormatException");
+            fail("Should throw NumberFormatException");
         } catch (NumberFormatException e) {
+            // Expected
         }
     }
 
@@ -394,8 +406,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Short.TYPE);
         try {
             editor.setAsText(null);
-            fail("Should throw a NumberFormatException");
+            fail("Should throw NumberFormatException");
         } catch (NumberFormatException e) {
+            // Expected
         }
     }
 
@@ -403,8 +416,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Short.TYPE);
         try {
             editor.setAsText("invalid");
-            fail("Should throw a NumberFormatException");
+            fail("Should throw NumberFormatException");
         } catch (NumberFormatException e) {
+            // Expected
         }
     }
 
@@ -423,8 +437,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Integer.TYPE);
         try {
             editor.setAsText(null);
-            fail("Should throw a NumberFormatException");
+            fail("Should throw NumberFormatException");
         } catch (NumberFormatException e) {
+            // Expected
         }
     }
 
@@ -432,9 +447,9 @@ public class PropertyEditorManagerTest e
         PropertyEditor editor = PropertyEditorManager.findEditor(Integer.TYPE);
         try {
             editor.setAsText("invalid");
-            fail("Should throw a NumberFormatException");
+            fail("Should throw NumberFormatException");
         } catch (NumberFormatException e) {
-
+            // Expected
         }
     }
 
@@ -775,17 +790,17 @@ public class PropertyEditorManagerTest e
 
         try {
             e2.setValue(null);
-            fail("Should throw an error");
+            fail("Should throw MockError");
         } catch (MockError e) {
-            // expected
+            // Expected
             assertNull(e2.getValue());
         }
         
         try {
             e2.setValue(new Font("Arial", Font.BOLD, 10));
-            fail("Should throw an error");
+            fail("Should throw MockError");
         } catch (MockError e) {
-            // expected
+            // Expected
         }
     }
     
@@ -802,10 +817,11 @@ public class PropertyEditorManagerTest e
         }
 
     }
+
     public void testColorEditor() throws Exception{
         PropertyEditor e2 = PropertyEditorManager.findEditor(Color.class);
         assertNull(e2.getValue());
-        assertEquals("null", e2.getAsText());
+        assertEquals("", e2.getAsText());
         e2.setValue(Color.RED);
         e2.setAsText(e2.getAsText());
         assertNull(e2.getTags());
@@ -828,31 +844,36 @@ public class PropertyEditorManagerTest e
 
         try {
             e2.setValue(Color.yellow);
-            fail("Should throw an error");
+            fail("Should throw MockError");
         } catch (MockError e) {
-            // expected
+            // Expected
         }
 
         assertEquals("255,255,0", e2.getAsText());
 
         try {
             e2.setAsText(null);
-            fail("Should throw NPE");
+            fail("Should throw NullPointerException");
         } catch (NullPointerException e) {
-            // expected
+            // Expected
         }
 
         try {
             e2.setAsText("text");
             fail("Should throw IllegalArgumentException");
         } catch (IllegalArgumentException e) {
-            // expected
+            // Expected
         }
 
         e2.removePropertyChangeListener(listener);
         e2.setAsText("255,255,255");
         assertEquals("java.awt.Color[r=255,g=255,b=255]", ((Color) e2
                 .getValue()).toString());
+
+        Color value1 = (Color) e2.getValue();
+        e2.setAsText("255,255,255");
+        Color value2 = (Color) e2.getValue();
+        assertNotSame(value1, value2);
     }
     
     public void testGetSetEditorPath() throws Exception{

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java Wed Jun 23 12:58:28 2010
@@ -30,6 +30,7 @@ import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Arrays;
+import java.util.List;
 import java.awt.image.BufferedImage;
 import java.awt.image.RenderedImage;
 import java.net.URL;
@@ -38,7 +39,8 @@ import org.apache.harmony.x.imageio.inte
 public final class ImageIO {
 
     private static final IIORegistry registry = IIORegistry.getDefaultInstance();
-
+    private static final Cache cacheInfo =  new Cache();
+    
     private ImageIO() {}
     
 
@@ -47,24 +49,20 @@ public final class ImageIO {
         throw new NotImplementedException();
     }
 
-    public static void setUseCache(boolean useCache) throws NotImplementedException {
-        // TODO: implement
+    public static void setUseCache(boolean useCache) {
+        cacheInfo.setUseCache(useCache);
     }
 
-    public static boolean getUseCache()  throws NotImplementedException {
-        // TODO: implement
-        return false;
+    public static boolean getUseCache() {
+        return cacheInfo.getUseCache();
     }
 
-    public static void setCacheDirectory(File cacheDirectory) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public static void setCacheDirectory(File cacheDirectory) {
+        cacheInfo.setCacheDirectory(cacheDirectory);
     }
 
-    public static File getCacheDirectory() throws NotImplementedException {
-        // TODO: implement
-        //-- null indicates system-dep default temporary directory
-        return null;
+    public static File getCacheDirectory() {
+        return cacheInfo.getCacheDirectory();
     }
 
     public static ImageInputStream createImageInputStream(Object input)
@@ -104,7 +102,7 @@ public final class ImageIO {
     }
 
     public static String[] getReaderFormatNames() {
-        ArrayList<String> FormatNames = new ArrayList<String>();
+        List<String> FormatNames = new ArrayList<String>();
 
         Iterator<ImageReaderSpi> it = registry.getServiceProviders(ImageReaderSpi.class, true);
         while (it.hasNext()) {
@@ -116,7 +114,7 @@ public final class ImageIO {
     }
 
     public static String[] getReaderMIMETypes() {
-        ArrayList<String> MIMETypes = new ArrayList<String>();
+        List<String> MIMETypes = new ArrayList<String>();
 
         Iterator<ImageReaderSpi> it = registry.getServiceProviders(ImageReaderSpi.class, true);
         while (it.hasNext()) {
@@ -413,6 +411,46 @@ public final class ImageIO {
         return rt;
     }
 
+    private static class Cache {
+        private boolean useCache = true;
+        private File cacheDirectory = null;
+        
+        public Cache() {
+        }
+    	
+        public File getCacheDirectory() {
+            return cacheDirectory;
+        }
+    	
+        public void setCacheDirectory(File cacheDirectory) {
+            if ((cacheDirectory != null) && (!cacheDirectory.isDirectory())) {
+                throw new IllegalArgumentException(Messages.getString("imageio.0B"));
+            }
+            
+            SecurityManager security = System.getSecurityManager();
+            if (security != null) {
+                String filepath;
+                
+                if (cacheDirectory == null) {
+                    filepath = System.getProperty("java.io.tmpdir");
+                } else {
+                    filepath = cacheDirectory.getPath();
+                }
+                
+                security.checkWrite(filepath);
+            }
+            
+            this.cacheDirectory = cacheDirectory;
+        }
+        
+        public boolean getUseCache() {
+            return useCache;
+        }
+        
+        public void setUseCache(boolean useCache) {
+            this.useCache = useCache;
+        }
+    }
 
     /**
      * Filter to match spi by format name

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIOServiceProvider.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIOServiceProvider.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIOServiceProvider.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/IIOServiceProvider.java Wed Jun 23 12:58:28 2010
@@ -21,7 +21,6 @@ package javax.imageio.spi;
 
 import java.util.Locale;
 
-import org.apache.harmony.luni.util.NotImplementedException;
 import org.apache.harmony.x.imageio.internal.nls.Messages;
 
 public abstract class IIOServiceProvider implements RegisterableService {
@@ -40,18 +39,16 @@ public abstract class IIOServiceProvider
         this.version = version;
     }
 
-    public IIOServiceProvider() throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public IIOServiceProvider() {
+        // the default impl. does nothing
     }
 
     public void onRegistration(ServiceRegistry registry, Class<?> category) {
         // the default impl. does nothing
     }
 
-    public void onDeregistration(ServiceRegistry registry, Class<?> category) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public void onDeregistration(ServiceRegistry registry, Class<?> category) {
+        // the default impl. does nothing
     }
 
     public String getVendorName() {

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageInputStreamSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageInputStreamSpi.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageInputStreamSpi.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageInputStreamSpi.java Wed Jun 23 12:58:28 2010
@@ -23,15 +23,12 @@ import java.io.File;
 import java.io.IOException;
 import javax.imageio.stream.ImageInputStream;
 
-import org.apache.harmony.luni.util.NotImplementedException;
-
 public abstract class ImageInputStreamSpi extends IIOServiceProvider implements
         RegisterableService {
     protected Class<?> inputClass;
 
-    protected ImageInputStreamSpi() throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    protected ImageInputStreamSpi() {
+        // the default impl. does nothing
     }
 
     public ImageInputStreamSpi(String vendorName, String version, Class<?> inputClass) {

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageOutputStreamSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageOutputStreamSpi.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageOutputStreamSpi.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageOutputStreamSpi.java Wed Jun 23 12:58:28 2010
@@ -21,8 +21,6 @@ package javax.imageio.spi;
 
 import javax.imageio.stream.ImageOutputStream;
 
-import org.apache.harmony.luni.util.NotImplementedException;
-
 import java.io.IOException;
 import java.io.File;
 
@@ -30,9 +28,8 @@ public abstract class ImageOutputStreamS
         RegisterableService {
     protected Class<?> outputClass;
 
-    protected ImageOutputStreamSpi() throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    protected ImageOutputStreamSpi() {
+        // the default impl. does nothing
     }
 
     public ImageOutputStreamSpi(String vendorName, String version, Class<?> outputClass) {

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageReaderSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageReaderSpi.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageReaderSpi.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageReaderSpi.java Wed Jun 23 12:58:28 2010
@@ -22,8 +22,6 @@ package javax.imageio.spi;
 import javax.imageio.stream.ImageInputStream;
 import javax.imageio.ImageReader;
 
-import org.apache.harmony.luni.util.NotImplementedException;
-
 import java.io.IOException;
 import org.apache.harmony.x.imageio.internal.nls.Messages;
 
@@ -34,9 +32,8 @@ public abstract class ImageReaderSpi ext
     protected Class[] inputTypes;
     protected String[] writerSpiNames;
 
-    protected ImageReaderSpi() throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    protected ImageReaderSpi() {
+        // the default impl. does nothing 
     }
 
     public ImageReaderSpi(String vendorName, String version, String[] names, String[] suffixes,
@@ -78,9 +75,12 @@ public abstract class ImageReaderSpi ext
 
     public abstract ImageReader createReaderInstance(Object extension) throws IOException;
 
-    public boolean isOwnReader(ImageReader reader) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public boolean isOwnReader(ImageReader reader) {
+        if (reader == null) {
+            throw new IllegalArgumentException(Messages.getString("imageio.97"));
+        }
+        
+        return reader.getClass().getName().equals(pluginClassName);
     }
 
     public String[] getImageWriterSpiNames() {

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageWriterSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageWriterSpi.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageWriterSpi.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ImageWriterSpi.java Wed Jun 23 12:58:28 2010
@@ -23,8 +23,6 @@ import javax.imageio.stream.ImageInputSt
 import javax.imageio.ImageTypeSpecifier;
 import javax.imageio.ImageWriter;
 
-import org.apache.harmony.luni.util.NotImplementedException;
-
 import java.awt.image.RenderedImage;
 import java.io.IOException;
 import org.apache.harmony.x.imageio.internal.nls.Messages;
@@ -36,9 +34,8 @@ public abstract class ImageWriterSpi ext
     protected Class[] outputTypes;
     protected String[] readerSpiNames;
 
-    protected ImageWriterSpi() throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    protected ImageWriterSpi() {
+        // the default impl. does nothing
     }
 
     public ImageWriterSpi(String vendorName, String version, String[] names,
@@ -90,9 +87,12 @@ public abstract class ImageWriterSpi ext
 
     public abstract ImageWriter createWriterInstance(Object extension) throws IOException;
 
-    public boolean isOwnWriter(ImageWriter writer) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public boolean isOwnWriter(ImageWriter writer) {
+        if (writer == null) {
+            throw new IllegalArgumentException(Messages.getString("imageio.96"));
+        }
+        
+        return writer.getClass().getName().equals(pluginClassName);
     }
 
     public String[] getImageReaderSpiNames() {

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/javax/imageio/spi/ServiceRegistry.java Wed Jun 23 12:58:28 2010
@@ -65,24 +65,22 @@ public class ServiceRegistry {
         categories.addProvider(provider, null);
     }
 
-    public <T> boolean deregisterServiceProvider(T provider, Class<T> category) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public <T> boolean deregisterServiceProvider(T provider, Class<T> category) {
+        return categories.removeProvider(provider, category);
     }
 
-    public void deregisterServiceProvider(Object provider) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public void deregisterServiceProvider(Object provider) {
+        categories.removeProvider(provider);
     }
 
-    @SuppressWarnings("unchecked")
+//    @SuppressWarnings("unchecked")
     public <T> Iterator<T> getServiceProviders(Class<T> category, Filter filter, boolean useOrdering) {
-        return new FilteredIterator<T>(filter, (Iterator<T>)categories.getProviders(category, useOrdering));
+        return new FilteredIterator<T>(filter, (Iterator<T>) categories.getProviders(category, useOrdering));
     }
 
-    @SuppressWarnings("unchecked")
+//    @SuppressWarnings("unchecked")
     public <T> Iterator<T> getServiceProviders(Class<T> category, boolean useOrdering) {
-        return (Iterator<T>)categories.getProviders(category, useOrdering);
+        return (Iterator<T>) categories.getProviders(category, useOrdering);
     }
 
     public <T> T getServiceProviderByClass(Class<T> providerClass) throws NotImplementedException {
@@ -90,24 +88,20 @@ public class ServiceRegistry {
         throw new NotImplementedException();
     }
 
-    public <T> boolean setOrdering(Class<T> category, T firstProvider, T secondProvider) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public <T> boolean setOrdering(Class<T> category, T firstProvider, T secondProvider) {
+        return categories.setOrdering(category, firstProvider, secondProvider);
     }
 
-    public <T> boolean unsetOrdering(Class<T> category, T firstProvider, T secondProvider) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public <T> boolean unsetOrdering(Class<T> category, T firstProvider, T secondProvider) {
+        return categories.unsetOrdering(category, firstProvider, secondProvider);
     }
 
-    public void deregisterAll(Class<?> category) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public void deregisterAll(Class<?> category) {
+        categories.removeAll(category);
     }
 
-    public void deregisterAll() throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public void deregisterAll() {
+        categories.removeAll();
     }
 
     @Override
@@ -116,9 +110,12 @@ public class ServiceRegistry {
         //deregisterAll();
     }
 
-    public boolean contains(Object provider) throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public boolean contains(Object provider) {
+        if (provider == null) {
+            throw new IllegalArgumentException(Messages.getString("imageio.5E"));
+        }
+        
+        return categories.contains(provider);
     }
 
     public Iterator<Class<?>> getCategories() {
@@ -138,6 +135,37 @@ public class ServiceRegistry {
             this.registry = registry;
         }
 
+        boolean contains(Object provider) {
+            for (Map.Entry<Class<?>, ProvidersMap> e : categories.entrySet()) {
+                ProvidersMap providers = e.getValue();
+                if (providers.contains(provider)) {
+                    return true;
+                }
+            }
+            
+            return false;
+        }
+
+        <T> boolean setOrdering(Class<T> category, T firstProvider, T secondProvider) {
+            ProvidersMap providers = categories.get(category);
+            
+            if (providers == null) {
+                throw new IllegalArgumentException(Messages.getString("imageio.92", category));
+            }
+            
+            return providers.setOrdering(firstProvider, secondProvider);
+        }
+        
+        <T> boolean unsetOrdering(Class<T> category, T firstProvider, T secondProvider) {
+            ProvidersMap providers = categories.get(category);
+            
+            if (providers == null) {
+                throw new IllegalArgumentException(Messages.getString("imageio.92", category));
+            }
+            
+            return providers.unsetOrdering(firstProvider, secondProvider);
+        }
+        
         //-- TODO: useOrdering
         Iterator<?> getProviders(Class<?> category, boolean useOrdering) {
             ProvidersMap providers = categories.get(category);
@@ -183,6 +211,9 @@ public class ServiceRegistry {
         }
 
         private boolean addToNamed(Object provider, Class<?> category) {
+            if (!category.isAssignableFrom(provider.getClass())) {
+                throw new ClassCastException();
+            }
             Object obj = categories.get(category);
 
             if (null == obj) {
@@ -201,25 +232,167 @@ public class ServiceRegistry {
             }
             return rt;
         }
+        
+        boolean removeProvider(Object provider, Class<?> category) {
+            if (provider == null) {
+                throw new IllegalArgumentException(Messages.getString("imageio.5E"));
+            }
+            
+            if (!category.isAssignableFrom(provider.getClass())) {
+                throw new ClassCastException();
+            }
+            
+            Object obj = categories.get(category);
+            
+            if (obj == null) {
+                throw new IllegalArgumentException(Messages.getString("imageio.92", category));
+            }
+            
+            return ((ProvidersMap) obj).removeProvider(provider, registry, category);
+        }
+        
+        void removeProvider(Object provider) {
+            if (provider == null) {
+                throw new IllegalArgumentException(Messages.getString("imageio.5E"));
+            }
+            
+            for (Entry<Class<?>, ProvidersMap> e : categories.entrySet()) {
+                ProvidersMap providers = e.getValue();
+                providers.removeProvider(provider, registry, e.getKey());
+            }
+        }
+        
+        void removeAll(Class<?> category) {
+            Object obj = categories.get(category);
+            
+            if (obj == null) {
+                throw new IllegalArgumentException(Messages.getString("imageio.92", category));
+            }
+            
+            ((ProvidersMap) obj).clear(registry);         
+        }
+        
+        void removeAll() {
+            for ( Map.Entry<Class<?>, ProvidersMap> e : categories.entrySet()) {
+                removeAll(e.getKey());                
+            }
+        }
     }
 
     private static class ProvidersMap {
-        //-- TODO: providers ordering support
 
         Map<Class<?>, Object> providers = new HashMap<Class<?>, Object>();
+        Map<Object, ProviderNode> nodeMap = new HashMap<Object, ProviderNode>();
 
         boolean addProvider(Object provider) {
-            return providers.put(provider.getClass(), provider) != null;
+            ProviderNode node =  new ProviderNode(provider);
+            nodeMap.put(provider, node);
+            Object obj = providers.put(provider.getClass(), provider);
+            
+            if (obj !=  null) {
+                nodeMap.remove(obj);
+                return false;
+            }
+            
+            return true;
+        }
+
+        boolean contains(Object provider) {
+            return providers.containsValue(provider);
+        }
+
+        boolean removeProvider(Object provider,
+                ServiceRegistry registry, Class<?> category) {
+            
+            Object obj = providers.get(provider.getClass());
+            if ((obj == null) || (obj != provider)) {
+                return false;
+            }
+            
+            providers.remove(provider.getClass());
+            nodeMap.remove(provider);
+            
+            if (provider instanceof RegisterableService) {
+                ((RegisterableService) provider).onDeregistration(registry, category);
+            }            
+            
+            return true;
+        }
+        
+        void clear(ServiceRegistry registry) {
+            for (Map.Entry<Class<?>, Object> e : providers.entrySet()) {
+                Object provider = e.getValue();
+                
+                if (provider instanceof RegisterableService) {
+                    ((RegisterableService) provider).onDeregistration(registry, e.getKey());
+                }
+            }
+            
+            providers.clear();
+            nodeMap.clear();
         }
 
         Iterator<Class<?>> getProviderClasses() {
             return providers.keySet().iterator();
         }
 
-        //-- TODO ordering
-        Iterator<?> getProviders(boolean userOrdering) {
+        Iterator<?> getProviders(boolean useOrdering) {
+            if (useOrdering) {
+                return new OrderedProviderIterator(nodeMap.values().iterator());              
+            }
+            
             return providers.values().iterator();
         }
+        
+        public <T> boolean setOrdering(T firstProvider, T secondProvider) {
+            if (firstProvider == secondProvider) {
+                throw new IllegalArgumentException(Messages.getString("imageio.98"));
+            }
+            
+            if ((firstProvider == null) || (secondProvider == null)) {
+                throw new IllegalArgumentException(Messages.getString("imageio.5E"));
+            }
+           
+            ProviderNode firstNode = nodeMap.get(firstProvider);
+            ProviderNode secondNode = nodeMap.get(secondProvider);
+                    
+            // if the ordering is already set, return false
+            if ((firstNode == null) || (firstNode.contains(secondNode))) {
+                return false;
+            }
+            
+            // put secondProvider into firstProvider's outgoing nodes list
+            firstNode.addOutEdge(secondNode);
+            // increase secondNode's incoming edge by 1
+            secondNode.addInEdge();         
+            
+            return true;
+        }
+        
+        public <T> boolean unsetOrdering(T firstProvider, T secondProvider) {
+            if (firstProvider == secondProvider) {
+                throw new IllegalArgumentException(Messages.getString("imageio.98"));
+            }
+            
+            if ((firstProvider == null) || (secondProvider == null)) {
+                throw new IllegalArgumentException(Messages.getString("imageio.5E"));
+            }
+            
+            ProviderNode firstNode = nodeMap.get(firstProvider);
+            ProviderNode secondNode = nodeMap.get(secondProvider); 
+                    
+            // if the ordering is not set, return false
+            if ((firstNode == null) || (!firstNode.contains(secondNode))) {
+                return false;
+            }
+                    
+            // remove secondProvider from firstProvider's outgoing nodes list
+            firstNode.removeOutEdge(secondNode);
+            // decrease secondNode's incoming edge by 1
+            secondNode.removeInEdge();
+                    
+            return true;            
+        }
     }
 
     private static class FilteredIterator<E> implements Iterator<E> {
@@ -265,4 +438,116 @@ public class ServiceRegistry {
             }
         }
     }
+    
+    private static class ProviderNode {
+        // number of incoming edges
+        private int incomingEdges;  
+        // all outgoing nodes
+        private Set<Object> outgoingNodes; 
+        private Object provider;
+                
+        public ProviderNode(Object provider) {
+            incomingEdges = 0;
+            outgoingNodes = new HashSet<Object>();
+            this.provider = provider;
+        }
+            
+        public Object getProvider() {
+            return provider;
+        }
+        
+        public Iterator<Object> getOutgoingNodes() {
+            return outgoingNodes.iterator();
+        }
+        
+        public boolean addOutEdge(Object secondProvider) {
+            return outgoingNodes.add(secondProvider);
+        }
+        
+        public <T> boolean removeOutEdge(Object provider) {
+            return outgoingNodes.remove(provider);
+        }
+        
+        public void addInEdge() {
+            incomingEdges++;
+        }
+        
+        public void removeInEdge() {
+            incomingEdges--;
+        }
+        
+        public int getIncomingEdges() {
+            return incomingEdges;
+        }
+        
+        public boolean contains(Object provider) {
+            return outgoingNodes.contains(provider);
+        }
+    }
+
+    /**
+     * The iterator implements Kahn topological sorting algorithm.
+     * @see <a href="http://en.wikipedia.org/wiki/Topological_sorting">Wikipedia</a>
+     * for further reference.
+     */
+    private static class OrderedProviderIterator implements Iterator {
+
+        // the stack contains nodes which has no lesser nodes
+        // except those already returned by the iterator
+        private Stack<ProviderNode> firstNodes = new Stack<ProviderNode>();
+
+        // a dynamic counter of incoming nodes
+        // when a node is returned by iterator, the counters for connected
+        // nodes decrement
+        private Map<ProviderNode, Integer> incomingEdges = new HashMap<ProviderNode, Integer>();
+        
+        public OrderedProviderIterator(Iterator it) {
+            // find all the nodes that with no incoming edges and
+            // add them to firstNodes
+            while (it.hasNext()) {
+                ProviderNode node = (ProviderNode) it.next();
+                incomingEdges.put(node, new Integer(node.getIncomingEdges()));
+                if (node.getIncomingEdges() == 0) {
+                    firstNodes.push(node);
+                }
+            }
+        }
+            
+        public boolean hasNext() {
+            return !firstNodes.empty();
+        }
+
+        public Object next() {
+            if (firstNodes.empty()) {
+               throw new NoSuchElementException();
+            }
+                            
+            // get a node from firstNodes
+            ProviderNode node = firstNodes.pop();
+                            
+            // find all the outgoing nodes
+            Iterator it = node.getOutgoingNodes();
+            while (it.hasNext()) {
+                ProviderNode outNode = (ProviderNode) it.next();
+                
+                // remove the incoming edge from the node.
+                int edges = incomingEdges.get(outNode);
+                edges--;
+                incomingEdges.put(outNode, new Integer(edges));
+                
+                // add to the firstNodes if this node's incoming edge is equal to 0
+                if (edges == 0) {
+                    firstNodes.push(outNode);
+                }
+            }
+            
+            incomingEdges.remove(node);
+                            
+            return node.getProvider();
+        }
+        
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+    }
 }

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties Wed Jun 23 12:58:28 2010
@@ -100,7 +100,7 @@ imageio.52=input == null!
 imageio.53=image cannot be NULL
 imageio.54=output cannot be NULL
 imageio.55=MIMEType cannot be NULL
-imageio.56=Use deregisterServiceprovider instead of Iterator.remove()
+imageio.56=Use deregisterServiceProvider instead of Iterator.remove()
 imageio.57=format names array cannot be NULL or empty
 imageio.58=Plugin class name cannot be NULL
 imageio.59=output types array cannot be NULL or empty
@@ -108,7 +108,7 @@ imageio.5A=vendor name cannot be NULL
 imageio.5B=version name cannot be NULL
 imageio.5C=input types array cannot be NULL or empty
 imageio.5D=categories iterator should not be NULL
-imageio.5E=provider should be != NULL
+imageio.5E=Provider should be != NULL
 imageio.5F=raster should not be NULL
 imageio.60=no thumbnails were set
 imageio.61=newChild == null!
@@ -166,4 +166,5 @@ imageio.94=Output {0} is not supported
 imageio.95=Input is not an instance of java.io.RandomAccessFile
 imageio.96=Writer cannot be null
 imageio.97=Reader cannot be null
+imageio.98=Ordered providers cannot be equal
 

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriter.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriter.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageWriter.java Wed Jun 23 12:58:28 2010
@@ -70,7 +70,7 @@ public class PNGImageWriter extends Imag
     private native int encode(byte[] input, int bytesInBuffer, int bytePixelSize, Object ios, int imageWidth,
             int imageHeight, int bitDepth, int colorType, int[] palette, int i, boolean b);
 
-    protected PNGImageWriter(ImageWriterSpi iwSpi) {
+    public PNGImageWriter(ImageWriterSpi iwSpi) {
         super(iwSpi);
     }
 

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/test/java/javax/imageio/ImageIOTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/test/java/javax/imageio/ImageIOTest.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/test/java/javax/imageio/ImageIOTest.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/imageio/src/test/java/javax/imageio/ImageIOTest.java Wed Jun 23 12:58:28 2010
@@ -17,9 +17,15 @@
 
 package javax.imageio;
 
+import java.io.File;
 import java.net.URL;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import junit.framework.TestCase;
 
@@ -45,4 +51,98 @@ public class ImageIOTest extends TestCas
 
         return img;
     }
+    
+    public void testCache() throws Exception {
+        ImageIO.setUseCache(true);
+        assertTrue("Failed to enable cache", ImageIO.getUseCache());
+        ImageIO.setUseCache(false);
+        assertFalse("Failed to disable cache", ImageIO.getUseCache());
+        
+        ImageIO.setCacheDirectory(null);
+        assertNull("Failed to set cache directory", ImageIO.getCacheDirectory());
+        
+        try {
+            ImageIO.setCacheDirectory(new File(""));
+            fail("IllegalArgumentException expected");
+        } 
+        catch (IllegalArgumentException expected) {
+            //OK
+        }
+    }
+
+    private void testFormat(String format) {
+        ImageReader reader = ImageIO.getImageReadersByFormatName(format).next();
+        ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next();
+
+        assertEquals("getImageReader() returns an incorrect reader for " + format,
+            ImageIO.getImageReader(writer).getClass(), reader.getClass());
+        assertEquals("getImageWriter() returns an incorrect writer for " + format,
+            ImageIO.getImageWriter(reader).getClass(), writer.getClass());
+    }
+    
+    // assume we have exactly one reader/writer pair
+    public void testGetJpegReaderWriter() throws Exception {
+        testFormat("jpeg");
+    }
+
+    // assume we have exactly one reader/writer pair
+    public void testGetPngReaderWriter() throws Exception {
+        testFormat("png");
+    }
+ 	
+    // GIF has no writer
+    // public void testGetGifReaderWriter() throws Exception {
+    //     testFormat("gif");
+    // }
+
+    public void testGetNullReaderWriter() throws Exception {
+    	try {
+            ImageIO.getImageWriter(null);
+            fail("Expected IllegalArgumentException");
+        }
+        catch (IllegalArgumentException expected) {
+            // Ok
+        }
+
+        try {
+            ImageIO.getImageReader(null);
+            fail("Expected IllegalArgumentException");
+        }
+        catch (IllegalArgumentException expected) {
+            // Ok
+        }
+    }
+        
+    public void testGetReaderMIMETypes() {
+        Set<String> expectedMIMETypes = new HashSet<String>(Arrays.asList(new String[] {
+            "image/gif", "image/x-png", "image/png", "image/jpeg" } ));
+        
+        Set<String> actualMIMETypes = new HashSet<String>(Arrays.asList(ImageIO.getReaderMIMETypes()));
+        assertTrue(actualMIMETypes.containsAll(expectedMIMETypes));
+    }
+    
+    public void testGetWriterMIMETypes() {
+        Set<String> expectedMIMETypes = new HashSet<String>(Arrays.asList(new String[] {
+            "image/x-png", "image/png", "image/jpeg" } ));
+        
+        Set<String> actualMIMETypes = new HashSet<String>(Arrays.asList(ImageIO.getWriterMIMETypes()));
+        assertTrue(actualMIMETypes.containsAll(expectedMIMETypes));
+    }
+    
+    public void testGetReaderFormatNames() {
+        Set<String> expectedFormatNames = new HashSet<String>(Arrays.asList(new String[] {
+            "JPG", "jpg", "GIF", "gif", "JPEG", "jpeg", "PNG", "png" } ));
+        
+        Set<String> actualFormatNames = new HashSet<String>(Arrays.asList(ImageIO.getReaderFormatNames()));
+        assertTrue(actualFormatNames.containsAll(expectedFormatNames));
+    }
+    
+    public void testGetWriterFormatNames() {
+        Set<String> expectedFormatNames = new HashSet<String>(Arrays.asList(new String[] {
+            "JPG", "jpg", "JPEG", "jpeg", "PNG", "png" } ));
+        
+        Set<String> actualFormatNames = new HashSet<String>(Arrays.asList(ImageIO.getWriterFormatNames()));
+        assertTrue(actualFormatNames.containsAll(expectedFormatNames));
+    }
+
 }

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86.drl.interm
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86.drl.interm?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86.drl.interm (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86.drl.interm Wed Jun 23 12:58:28 2010
@@ -1,2 +1,2 @@
 #2315
-org/apache/harmony/luni/tests/java/net/InetAddressTest.java
+org/apache/harmony/luni/tests/java/net/InetAddressThreadTest.java

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86.ibm?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86.ibm (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86.ibm Wed Jun 23 12:58:28 2010
@@ -1,2 +1,2 @@
 org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java
-org/apache/harmony/luni/tests/java/net/InetAddressTest.java
+org/apache/harmony/luni/tests/java/net/InetAddressThreadTest.java

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86_64.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86_64.drl?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86_64.drl (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86_64.drl Wed Jun 23 12:58:28 2010
@@ -1,2 +1,2 @@
-org/apache/harmony/luni/tests/java/net/InetAddressTest.java
+org/apache/harmony/luni/tests/java/net/InetAddressThreadTest.java
 org/apache/harmony/luni/tests/java/net/MulticastSocketTest.java

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86_64.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86_64.ibm?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86_64.ibm (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.linux.x86_64.ibm Wed Jun 23 12:58:28 2010
@@ -1,2 +1,2 @@
 org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java
-org/apache/harmony/luni/tests/java/net/InetAddressTest.java
+org/apache/harmony/luni/tests/java/net/InetAddressThreadTest.java

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.zos.s390.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.zos.s390.ibm?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.zos.s390.ibm (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.zos.s390.ibm Wed Jun 23 12:58:28 2010
@@ -1,4 +1,4 @@
 org/apache/harmony/luni/tests/java/util/PropertiesTest.java
 org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java
 org/apache/harmony/luni/tests/java/lang/PackageTest.java
-org/apache/harmony/luni/tests/java/net/InetAddressTest.java
+org/apache/harmony/luni/tests/java/net/InetAddressThreadTest.java

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.zos.s390x.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.zos.s390x.ibm?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.zos.s390x.ibm (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/make/exclude.zos.s390x.ibm Wed Jun 23 12:58:28 2010
@@ -1,4 +1,4 @@
 org/apache/harmony/luni/tests/java/util/PropertiesTest.java
 org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java
 org/apache/harmony/luni/tests/java/lang/PackageTest.java
-org/apache/harmony/luni/tests/java/net/InetAddressTest.java
+org/apache/harmony/luni/tests/java/net/InetAddressThreadTest.java

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/InputStreamReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/InputStreamReader.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/InputStreamReader.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/InputStreamReader.java Wed Jun 23 12:58:28 2010
@@ -101,7 +101,7 @@ public class InputStreamReader extends R
                     CodingErrorAction.REPLACE);
         } catch (IllegalArgumentException e) {
             throw (UnsupportedEncodingException)
-                    new UnsupportedEncodingException().initCause(e);
+                    new UnsupportedEncodingException(enc).initCause(e);
         }
         bytes.limit(0);
     }

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/ObjectInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/ObjectInputStream.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/ObjectInputStream.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/ObjectInputStream.java Wed Jun 23 12:58:28 2010
@@ -30,13 +30,11 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 
-import org.apache.harmony.misc.accessors.ObjectAccessor;
-import org.apache.harmony.misc.accessors.AccessorFactory;
-
 import org.apache.harmony.kernel.vm.VM;
 import org.apache.harmony.luni.internal.nls.Messages;
-import org.apache.harmony.luni.internal.nls.Messages;
 import org.apache.harmony.luni.util.PriviAction;
+import org.apache.harmony.misc.accessors.AccessorFactory;
+import org.apache.harmony.misc.accessors.ObjectAccessor;
 
 /**
  * A specialized {@link InputStream} that is able to read (deserialize) Java

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/PrintStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/PrintStream.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/PrintStream.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/io/PrintStream.java Wed Jun 23 12:58:28 2010
@@ -175,7 +175,7 @@ public class PrintStream extends FilterO
             throw new NullPointerException();
         }
         if (!Charset.isSupported(csn)) {
-            throw new UnsupportedEncodingException();
+            throw new UnsupportedEncodingException(csn);
         }
         encoding = csn;
     }

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/lang/String.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/lang/String.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/lang/String.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/lang/String.java Wed Jun 23 12:58:28 2010
@@ -1323,7 +1323,20 @@ public final class String implements Ser
             return this;
 
         String rs = replacement.toString();
-        StringBuilder buffer = new StringBuilder(count);
+
+        // special case if the string to match is empty then
+        // match at the start, inbetween each character and at the end
+        if ("".equals(ts)) {
+            StringBuilder buffer = new StringBuilder(count + (rs.length() * (count + 1)));
+            buffer.append(rs);
+            for(int i=0; i<count; i++) {
+                buffer.append(value[offset + i]);
+                buffer.append(rs);
+            }
+            return buffer.toString();
+        }
+
+        StringBuilder buffer = new StringBuilder(count + rs.length());
         int tl = target.length();
         int tail = 0;
         do {
@@ -1405,12 +1418,15 @@ public final class String implements Ser
         if (start == 0 && end == count) {
             return this;
         }
-        // NOTE last character not copied!
-        // Fast range check.
-        if (0 <= start && start <= end && end <= count) {
-            return new String(offset + start, end - start, value);
+        if (start < 0) {
+            throw new StringIndexOutOfBoundsException(start);
+        } else if (start > end) {
+            throw new StringIndexOutOfBoundsException(end - start);
+        } else if (end > count) {
+            throw new StringIndexOutOfBoundsException(end);
         }
-        throw new StringIndexOutOfBoundsException();
+        // NOTE last character not copied!
+        return new String(offset + start, end - start, value);
     }
 
     /**

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/NetworkInterface.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/NetworkInterface.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/NetworkInterface.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/NetworkInterface.java Wed Jun 23 12:58:28 2010
@@ -166,7 +166,11 @@ public final class NetworkInterface exte
                      * since we don't have a port in this case we pass in
                      * NO_PORT
                      */
-                    security.checkConnect(element.getHostName(),
+                    String hostName = element.getHostName();
+                    if(hostName.contains("::")){
+                        hostName = getFullFormOfCompressedIPV6Address(hostName);
+                    }
+                    security.checkConnect(hostName,
                             CHECK_CONNECT_NO_PORT);
                     accessibleAddresses.add(element);
                 } catch (SecurityException e) {
@@ -182,6 +186,62 @@ public final class NetworkInterface exte
 
         return new Vector<InetAddress>(0).elements();
     }
+    
+    private String getFullFormOfCompressedIPV6Address(String compressed) {
+        StringBuilder fullForm = new StringBuilder(39);
+        final int NUM_OF_IPV6_FIELDS = 8;
+
+        String[] fields = compressed.split(":");
+        // the number of compressed fields
+        int numOfCompressedFields;
+        
+        if (compressed.startsWith("::")) { // compressed head part
+            compressed = compressed.replace("::", "");
+            fields = compressed.split(":");
+            numOfCompressedFields = NUM_OF_IPV6_FIELDS - fields.length;
+            restoreCompressedFieldsWithZero(fullForm, numOfCompressedFields);
+            appendNonZeroFields(fullForm, fields);
+        } else if (compressed.endsWith("::")) { // compressed tail part
+            compressed = compressed.replace("::", "");
+            fields = compressed.split(":");
+            numOfCompressedFields = NUM_OF_IPV6_FIELDS - fields.length;
+            appendNonZeroFields(fullForm, fields);
+            restoreCompressedFieldsWithZero(fullForm, numOfCompressedFields);
+        } else { // compressed middle part
+            numOfCompressedFields = NUM_OF_IPV6_FIELDS - fields.length + 1;
+            for (String field : fields) {
+                if (field.equals("")) {
+                    // for compressed fields add 0
+                    restoreCompressedFieldsWithZero(fullForm, numOfCompressedFields);
+                } else {
+                    fullForm.append(field);
+                    // add colon
+                    fullForm.append(":");
+                }
+            }
+        }
+        // delete the excess colon
+        fullForm.deleteCharAt(fullForm.length() - 1);
+
+        return fullForm.toString();
+    }
+
+    private void appendNonZeroFields(StringBuilder fullForm,
+            String[] fields) {
+        for (int i = 0; i < fields.length; i++) {
+            fullForm.append(fields[i]);
+            fullForm.append(":");
+        }
+    }
+
+    private void restoreCompressedFieldsWithZero(StringBuilder fullForm,
+            int numOfCompressedFields) {
+        for (int i = 0; i < numOfCompressedFields; i++) {
+            fullForm.append("0");
+            // add colon
+            fullForm.append(":");
+        }
+    }
 
     /**
      * Gets the human-readable name associated with this network interface.

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URI.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URI.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URI.java Wed Jun 23 12:58:28 2010
@@ -41,6 +41,8 @@ public final class URI implements Compar
 
     static final String someLegal = unreserved + punct;
 
+    static final String queryLegal =  unreserved + reserved + "\\";
+    
     static final String allLegal = unreserved + reserved;
 
     private String string;
@@ -453,7 +455,7 @@ public final class URI implements Compar
         private void validateQuery(String uri, String query, int index)
                 throws URISyntaxException {
             try {
-                URIEncoderDecoder.validate(query, allLegal);
+                URIEncoderDecoder.validate(query, queryLegal);
             } catch (URISyntaxException e) {
                 throw new URISyntaxException(uri, Messages.getString("luni.89", e //$NON-NLS-1$
                         .getReason()), index + e.getIndex());

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLClassLoader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLClassLoader.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLClassLoader.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLClassLoader.java Wed Jun 23 12:58:28 2010
@@ -664,9 +664,6 @@ public class URLClassLoader extends Secu
      */
     @Override
     public Enumeration<URL> findResources(final String name) throws IOException {
-        if (name == null) {
-            return null;
-        }
         ArrayList<URL> result = AccessController.doPrivileged(
                 new PrivilegedAction<ArrayList<URL>>() {
                     public ArrayList<URL> run() {
@@ -694,6 +691,9 @@ public class URLClassLoader extends Secu
     }
 
     void findResourcesImpl(String name, ArrayList<URL> result) {
+        if (name == null) {
+            return;
+        }
         int n = 0;
         while (true) {
             URLHandler handler = getHandler(n++);

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLStreamHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLStreamHandler.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLStreamHandler.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/net/URLStreamHandler.java Wed Jun 23 12:58:28 2010
@@ -85,22 +85,19 @@ public abstract class URLStreamHandler {
      * @see URL
      */
     protected void parseURL(URL u, String str, int start, int end) {
-        // For compatibility, refer to Harmony-2941
-        if (str.startsWith("//", start) //$NON-NLS-1$
-                && str.indexOf('/', start + 2) == -1
-                && end <= Integer.MIN_VALUE + 1) {
-            throw new StringIndexOutOfBoundsException(end - 2 - start);
-        }
-        if (end < start) {
+        if (end < start || end < 0) {
+            // Checks to ensure string index exception ahead of
+            // security exception for compatibility.
+            if (end <= Integer.MIN_VALUE + 1 && (start >= str.length() || start < 0)
+                    || str.startsWith("//", start) && str.indexOf('/', start + 2) == -1) { //$NON-NLS-1$
+                throw new StringIndexOutOfBoundsException(end);
+            }
             if (this != u.strmHandler) {
                 throw new SecurityException();
             }
             return;
         }
-        String parseString = ""; //$NON-NLS-1$
-        if (start < end) {
-            parseString = str.substring(start, end);
-        }
+        String parseString = str.substring(start, end);
         end -= start;
         int fileIdx = 0;
 

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/util/Scanner.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/util/Scanner.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/util/Scanner.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/java/util/Scanner.java Wed Jun 23 12:58:28 2010
@@ -2017,6 +2017,8 @@ public final class Scanner implements It
         return negative;
     }
 
+    private int tokenStart = 0;
+    private int tokenEnd = 0;
     /*
      * Find the prefixed delimiter and posefixed delimiter in the input resource
      * and set the start index and end index of Matcher region. If postfixed
@@ -2031,11 +2033,13 @@ public final class Scanner implements It
         matcher.usePattern(delimiter);
         matcher.region(findStartIndex, bufferLength);
 
-        tokenStartIndex = findPreDelimiter();
-        if (setHeadTokenRegion(tokenStartIndex)) {
+        findPreDelimiter();
+        if (setHeadTokenRegion(tokenStart)) {
             return true;
         }
-        tokenEndIndex = findPostDelimiter();
+        findPostDelimiter();
+        tokenStartIndex = tokenStart;
+        tokenEndIndex = tokenEnd;
         // If the second delimiter is not found
         if (-1 == tokenEndIndex) {
             // Just first Delimiter Exists
@@ -2053,8 +2057,8 @@ public final class Scanner implements It
     /*
      * Find prefix delimiter
      */
-    private int findPreDelimiter() {
-        int tokenStartIndex;
+    private void findPreDelimiter() {
+    	tokenStart = 0;
         boolean findComplete = false;
         while (!findComplete) {
             if (matcher.find()) {
@@ -2074,13 +2078,14 @@ public final class Scanner implements It
                     readMore();
                     resetMatcher();
                 } else {
-                    return -1;
+                    tokenStart = -1;
+                    return;
                 }
             }
         }
-        tokenStartIndex = matcher.end();
+
+        tokenStart = matcher.end();
         findStartIndex = matcher.end();
-        return tokenStartIndex;
     }
 
     /*
@@ -2113,8 +2118,8 @@ public final class Scanner implements It
     /*
      * Find postfix delimiter
      */
-    private int findPostDelimiter() {
-        int tokenEndIndex = 0;
+    private void findPostDelimiter() {
+        tokenEnd = 0;
         boolean findComplete = false;
         while (!findComplete) {
             if (matcher.find()) {
@@ -2128,13 +2133,16 @@ public final class Scanner implements It
                     readMore();
                     resetMatcher();
                 } else {
-                    return -1;
+                    tokenStart = findStartIndex;
+                    tokenEnd = -1;
+                    return;
                 }
             }
         }
-        tokenEndIndex = matcher.start();
+
+        tokenStart = findStartIndex;
+        tokenEnd = matcher.start();
         findStartIndex = matcher.start();
-        return tokenEndIndex;
     }
 
     /*
@@ -2143,13 +2151,12 @@ public final class Scanner implements It
      * true, otherwise set to false.
      */
     private void readMore() {
-        int oldPosition = buffer.position();
-        int oldBufferLength = bufferLength;
         // Increase capacity if empty space is not enough
         if (bufferLength >= buffer.capacity()) {
             expandBuffer();
         }
-
+        int oldPosition = buffer.position();
+        int oldBufferLength = bufferLength;
         // Read input resource
         int readCount = 0;
         try {
@@ -2183,14 +2190,66 @@ public final class Scanner implements It
 
     // Expand the size of internal buffer.
     private void expandBuffer() {
-        int oldPosition = buffer.position();
-        int oldCapacity = buffer.capacity();
+        //inital new indexes values
+        int nFindStartIndex = 0;
+        int nPreStartIndex = 0;
+        int nBufferLength = 0;
+        int nLimit = 0;
+        int nPostion = 0;       
+        int nCachehasNextIndex = 0;
+
+        //store old buffer set
+        int oldLength = bufferLength;
+        int oldPostion = buffer.position();
         int oldLimit = buffer.limit();
-        int newCapacity = oldCapacity * DIPLOID;
-        char[] newBuffer = new char[newCapacity];
-        System.arraycopy(buffer.array(), 0, newBuffer, 0, oldLimit);
-        buffer = CharBuffer.wrap(newBuffer, 0, newCapacity);
-        buffer.position(oldPosition);
-        buffer.limit(oldLimit);
+        int oldCapacity = buffer.capacity();
+        
+        //new start index for new buffer
+        int startIndex = 0;
+        
+        if (preStartIndex == -1) {
+            startIndex = findStartIndex;
+            nPreStartIndex = -1;
+            nFindStartIndex = 0;
+        } else {
+            startIndex = preStartIndex;
+            nPreStartIndex = 0;
+            nFindStartIndex = findStartIndex - startIndex;
+        }
+        
+        int nCapacity = oldCapacity;
+        char[] newBuffer = null;
+        // set nCapacity
+        if (startIndex < oldCapacity / 2) {
+            nCapacity = nCapacity << 1;
+            newBuffer = new char[nCapacity];
+        } else {
+            newBuffer = buffer.array();
+        }
+
+        //new buffer set
+        nBufferLength = oldLength - startIndex;
+        nLimit = oldLimit - startIndex;
+        if (oldPostion < startIndex) {
+            nPostion = 0;
+        } else {
+            nPostion = oldPostion - startIndex;
+        }
+        // new CachedhasNextIndex;
+        if (cachehasNextIndex != -1) {
+            nCachehasNextIndex = cachehasNextIndex - startIndex;
+        } else {
+            nCachehasNextIndex = -1;
+        }
+        System.arraycopy(buffer.array(), startIndex, newBuffer, 0, nLimit);
+
+        buffer = CharBuffer.wrap(newBuffer, 0, nCapacity);
+        buffer.position(nPostion);
+        buffer.limit(nLimit);
+
+        preStartIndex = nPreStartIndex;
+        findStartIndex = nFindStartIndex;
+        bufferLength = nBufferLength;
+        cachehasNextIndex = nCachehasNextIndex;
     }
 }

Modified: harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java?rev=957178&r1=957177&r2=957178&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java Wed Jun 23 12:58:28 2010
@@ -28,6 +28,7 @@ import java.net.ContentHandlerFactory;
 import java.net.JarURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLDecoder;
 import java.security.AccessController;
 import java.security.Permission;
 import java.security.PrivilegedAction;
@@ -207,12 +208,14 @@ public class JarURLConnectionImpl extend
      * URLConnection}.
      */
     private void findJarEntry() throws IOException {
-        if (getEntryName() == null) {
+        String entryName = getEntryName();
+        if (entryName == null) {
             return;
         }
-        jarEntry = jarFile.getJarEntry(getEntryName());
+        String decodedName = URLDecoder.decode(entryName, "UTF-8"); //$NON-NLS-1$
+        jarEntry = jarFile.getJarEntry(decodedName);
         if (jarEntry == null) {
-            throw new FileNotFoundException(getEntryName());
+            throw new FileNotFoundException(entryName);
         }
     }
 



Mime
View raw message