You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/12/05 13:26:14 UTC

svn commit: r601315 [10/11] - in /harmony/enhanced/classlib/branches/java6: depends/build/ modules/accessibility/src/main/java/javax/accessibility/ modules/accessibility/src/test/api/java/common/javax/accessibility/ modules/awt/src/main/java/common/jav...

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java Wed Dec  5 04:25:42 2007
@@ -63,8 +63,10 @@
      * Constructs an instance with the specified bits.
      * </p>
      * 
-     * @param mostSigBits The 64 most significant bits of the UUID.
-     * @param leastSigBits The 64 least significant bits of the UUID.
+     * @param mostSigBits
+     *            The 64 most significant bits of the UUID.
+     * @param leastSigBits
+     *            The 64 least significant bits of the UUID.
      */
     public UUID(long mostSigBits, long leastSigBits) {
         super();
@@ -204,54 +206,58 @@
      * Parses a UUID string with the format defined by {@link #toString()}.
      * </p>
      * 
-     * @param uuid The UUID string to parse.
+     * @param uuid
+     *            The UUID string to parse.
      * @return A UUID instance.
-     * @throws NullPointerException if <code>uuid</code> is <code>null</code>.
-     * @throws IllegalArgumentException if <code>uuid</code> is not formatted
-     *         correctly.
+     * @throws NullPointerException
+     *             if <code>uuid</code> is <code>null</code>.
+     * @throws IllegalArgumentException
+     *             if <code>uuid</code> is not formatted correctly.
      */
     public static UUID fromString(String uuid) {
         if (uuid == null) {
             throw new NullPointerException();
         }
-        
+
         int[] position = new int[5];
         int lastPosition = 1;
         int startPosition = 0;
-        
+
         int i = 0;
-        for (; i < position.length  && lastPosition > 0; i++) {
-        	position[i] = uuid.indexOf("-", startPosition); //$NON-NLS-1$
-        	lastPosition = position[i];
-        	startPosition = position[i] + 1;
+        for (; i < position.length && lastPosition > 0; i++) {
+            position[i] = uuid.indexOf("-", startPosition); //$NON-NLS-1$
+            lastPosition = position[i];
+            startPosition = position[i] + 1;
         }
 
         // should have and only can have four "-" in UUID
-        if(i != position.length || lastPosition != -1)
-        {
-        	throw new IllegalArgumentException(Msg.getString("KA014") + uuid); //$NON-NLS-1$
-        }
-
-		long m1 = Long.parseLong(uuid.substring(0, position[0]), 16);
-		long m2 = Long.parseLong(uuid.substring(position[0]+ 1, position[1]), 16);
-		long m3 = Long.parseLong(uuid.substring(position[1] + 1, position[2]), 16);
-
-		long lsb1 = Long.parseLong(uuid.substring(position[2] + 1, position[3]), 16);
-		long lsb2 = Long.parseLong(uuid.substring(position[3]+ 1), 16);
-
-		long msb = (m1 << 32) | (m2 << 16) | m3;
-		long lsb = (lsb1 << 48) | lsb2;
-		
-		return new UUID(msb, lsb);
-	}
-
-    /**
-	 * <p>
-	 * The 64 least significant bits of the UUID.
-	 * </p>
-	 * 
-	 * @return A long value.
-	 */
+        if (i != position.length || lastPosition != -1) {
+            throw new IllegalArgumentException(Msg.getString("KA014") + uuid); //$NON-NLS-1$
+        }
+
+        long m1 = Long.parseLong(uuid.substring(0, position[0]), 16);
+        long m2 = Long.parseLong(uuid.substring(position[0] + 1, position[1]),
+                16);
+        long m3 = Long.parseLong(uuid.substring(position[1] + 1, position[2]),
+                16);
+
+        long lsb1 = Long.parseLong(
+                uuid.substring(position[2] + 1, position[3]), 16);
+        long lsb2 = Long.parseLong(uuid.substring(position[3] + 1), 16);
+
+        long msb = (m1 << 32) | (m2 << 16) | m3;
+        long lsb = (lsb1 << 48) | lsb2;
+
+        return new UUID(msb, lsb);
+    }
+
+    /**
+     * <p>
+     * The 64 least significant bits of the UUID.
+     * </p>
+     * 
+     * @return A long value.
+     */
     public long getLeastSignificantBits() {
         return leastSigBits;
     }
@@ -312,7 +318,8 @@
      * </p>
      * 
      * @return A long value.
-     * @throws UnsupportedOperationException if {@link #version()} is not 1.
+     * @throws UnsupportedOperationException
+     *             if {@link #version()} is not 1.
      */
     public long timestamp() {
         if (version != 1) {
@@ -328,7 +335,8 @@
      * </p>
      * 
      * @return A long value.
-     * @throws UnsupportedOperationException if {@link #version()} is not 1.
+     * @throws UnsupportedOperationException
+     *             if {@link #version()} is not 1.
      */
     public int clockSequence() {
         if (version != 1) {
@@ -344,7 +352,8 @@
      * </p>
      * 
      * @return A long value.
-     * @throws UnsupportedOperationException if {@link #version()} is not 1.
+     * @throws UnsupportedOperationException
+     *             if {@link #version()} is not 1.
      */
     public long node() {
         if (version != 1) {
@@ -360,7 +369,8 @@
      * significant.
      * </p>
      * 
-     * @param uuid The UUID to compare to.
+     * @param uuid
+     *            The UUID to compare to.
      * @return A value of -1, 0 or 1 if this UUID is less than, equal to or
      *         greater than <code>uuid</code>.
      */
@@ -391,7 +401,8 @@
      * then <code>true</code> is returned.
      * </p>
      * 
-     * @param object The Object to compare to.
+     * @param object
+     *            The Object to compare to.
      * @return A <code>true</code> if this UUID is equal to
      *         <code>object</code> or <code>false</code> if not.
      */
@@ -485,9 +496,12 @@
      * Resets the transient fields to match the behavior of the constructor.
      * </p>
      * 
-     * @param in The InputStream to read from.
-     * @throws IOException if <code>in</code> throws it.
-     * @throws ClassNotFoundException if <code>in</code> throws it.
+     * @param in
+     *            The InputStream to read from.
+     * @throws IOException
+     *             if <code>in</code> throws it.
+     * @throws ClassNotFoundException
+     *             if <code>in</code> throws it.
      */
     private void readObject(ObjectInputStream in) throws IOException,
             ClassNotFoundException {

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatConversionException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatConversionException.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatConversionException.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatConversionException.java Wed Dec  5 04:25:42 2007
@@ -20,10 +20,9 @@
 /**
  * The unchecked exception will be thrown out if the format conversion is
  * unknown.
- * 
- * 
  */
 public class UnknownFormatConversionException extends IllegalFormatException {
+
 	private static final long serialVersionUID = 19060418L;
 
 	private String s;

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatFlagsException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatFlagsException.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatFlagsException.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UnknownFormatFlagsException.java Wed Dec  5 04:25:42 2007
@@ -20,42 +20,41 @@
 
 /**
  * The unchecked exception will be thrown out if there is an unknown flag.
- * 
  */
 public class UnknownFormatFlagsException extends IllegalFormatException {
 
-	private static final long serialVersionUID = 19370506L;
+    private static final long serialVersionUID = 19370506L;
 
-	private String flags;
+    private String flags;
 
-	/**
-	 * Constructs an UnknownFormatFlagsException with the specified flags.
-	 * 
-	 * @param f
-	 *            The specified flags.
-	 */
-	public UnknownFormatFlagsException(String f) {
-		if (null == f) {
-			throw new NullPointerException();
-		}
-		flags = f;
-	}
+    /**
+     * Constructs an UnknownFormatFlagsException with the specified flags.
+     * 
+     * @param f
+     *            The specified flags.
+     */
+    public UnknownFormatFlagsException(String f) {
+        if (null == f) {
+            throw new NullPointerException();
+        }
+        flags = f;
+    }
 
-	/**
-	 * Returns the flags associated with the exception.
-	 * 
-	 * @return The flags associated with the exception.
-	 */
-	public String getFlags() {
-		return flags;
-	}
+    /**
+     * Returns the flags associated with the exception.
+     * 
+     * @return The flags associated with the exception.
+     */
+    public String getFlags() {
+        return flags;
+    }
 
-	/**
-	 * Returns the message associated with the exception.
-	 * 
-	 * @return The message associated with the exception.
-	 */
-	@Override
+    /**
+     * Returns the message associated with the exception.
+     * 
+     * @return The message associated with the exception.
+     */
+    @Override
     public String getMessage() {
         return Msg.getString("K034a", flags);
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java Wed Dec  5 04:25:42 2007
@@ -400,7 +400,7 @@
         }
         if (object instanceof List) {
             List<?> list = (List<?>) object;
-            if (list.size() != size()) {
+            if (list.size() != elementCount) {
                 return false;
             }
 
@@ -830,7 +830,7 @@
      */
     @Override
     protected void removeRange(int start, int end) {
-        if (start >= 0 && start <= end && end <= size()) {
+        if (start >= 0 && start <= end && end <= elementCount) {
             if (start == end) {
                 return;
             }
@@ -960,7 +960,7 @@
      * 
      * @exception IndexOutOfBoundsException
      *                when <code>start < 0 or <code>end > size()</code>
-     * @exception	IllegalArgumentException when <code>start > end</code>
+     * @exception IllegalArgumentException when <code>start > end</code>
      */
     @Override
     public synchronized List<E> subList(int start, int end) {
@@ -1022,7 +1022,7 @@
             return "[]"; //$NON-NLS-1$
         }
         int length = elementCount - 1;
-        StringBuffer buffer = new StringBuffer(size() * 16);
+        StringBuffer buffer = new StringBuffer(elementCount * 16);
         buffer.append('[');
         for (int i = 0; i < length; i++) {
             if (elementData[i] == this) {

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java Wed Dec  5 04:25:42 2007
@@ -1081,6 +1081,7 @@
         // Response Code Sample : "HTTP/1.0 200 OK"
 
         // Call connect() first since getHeaderField() doesn't return exceptions
+        connect();
         doRequest();
         if (responseCode != -1) {
             return responseCode;

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/launcher/shared/main.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/launcher/shared/main.c?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/launcher/shared/main.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/launcher/shared/main.c Wed Dec  5 04:25:42 2007
@@ -36,7 +36,7 @@
 
 #define PORT_LIB_OPTION "_org.apache.harmony.vmi.portlib"
 
-#define HY_COPYRIGHT_STRING "Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or its licensors, as applicable."
+#define HY_COPYRIGHT_STRING "Apache Harmony Launcher : (c) Copyright 1991, 2007 The Apache Software Foundation or its licensors, as applicable."
 
 /* Tools launchers will invoke HY_TOOLS_PACKAGE+"."+<execname>+"."+HY_TOOLS_MAIN_TYPE */
 #define HY_TOOLS_PACKAGE "org.apache.harmony.tools"

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/StreamTokenizerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/StreamTokenizerTest.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/StreamTokenizerTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/io/StreamTokenizerTest.java Wed Dec  5 04:25:42 2007
@@ -17,6 +17,7 @@
 
 package tests.api.java.io;
 
+import java.io.ByteArrayInputStream;
 import java.io.CharArrayReader;
 import java.io.IOException;
 import java.io.PipedInputStream;
@@ -382,6 +383,14 @@
 		assertTrue("toString failed." + st.toString(),
 			   st.toString().equals(
 						"Token[ABC], line 1"));
+
+		// Regression test for HARMONY-4070
+        byte[] data = new byte[] { (byte) '-' };
+        StreamTokenizer tokenizer = new StreamTokenizer(
+                new ByteArrayInputStream(data));
+        tokenizer.nextToken();
+        String result = tokenizer.toString();
+        assertEquals("Token['-'], line 1", result);
 	}
 
 	/**

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/ArrayListTest.java Wed Dec  5 04:25:42 2007
@@ -540,6 +540,18 @@
         list.addAll(0, collection);
         assertEquals(14, list.size());
     }
+    
+    public void test_override_size() throws Exception {
+        ArrayList testlist = new MockArrayList();
+        // though size is overriden, it should passed without exception
+        testlist.add("test_0");
+        testlist.add("test_1");
+        testlist.add("test_2");
+        testlist.add(1,"test_3");
+        testlist.get(1);
+        testlist.remove(2);
+        testlist.set(1, "test_4");
+    }
 
     public static class ArrayListExtend extends ArrayList {
 
@@ -556,6 +568,12 @@
 
         public int size() {
             return size;
+        }
+    }
+    
+    public class MockArrayList extends ArrayList {
+        public int size() {
+            return 0;
         }
     }
 

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/GregorianCalendarTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/GregorianCalendarTest.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/GregorianCalendarTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/GregorianCalendarTest.java Wed Dec  5 04:25:42 2007
@@ -145,6 +145,19 @@
         SimpleTimeZone timezone = new SimpleTimeZone(-3600 * 24 * 1000 * 2,
                 "GMT");
         GregorianCalendar gc = new GregorianCalendar(timezone);
+
+	   // Regression test for HARMONY-5195
+           Calendar c1 = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
+           c1.set(Calendar.YEAR,1999);
+           c1.set(Calendar.MONTH,Calendar.JUNE);
+           c1.set(Calendar.DAY_OF_MONTH,2);
+           c1.set(Calendar.HOUR,15);
+           c1.set(Calendar.MINUTE,34);
+           c1.set(Calendar.SECOND,16);
+           assertEquals(34,c1.get(Calendar.MINUTE));
+           c1.setTimeZone(new SimpleTimeZone(60000, "ONE MINUTE"));
+           assertEquals(35,c1.get(Calendar.MINUTE));
+
 	}
 
 	/**

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/TreeMapTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/TreeMapTest.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/TreeMapTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/TreeMapTest.java Wed Dec  5 04:25:42 2007
@@ -88,7 +88,7 @@
             if (null == o1) {
                 return -1;
             }
-            if (null == o2) {
+            if (null == o2) { // comparator should be symmetric
                 return 1;
             }
             return o1.compareTo(o2);
@@ -356,6 +356,21 @@
         treemap = new TreeMap();
 		SortedMap<String, String> headMap =  treemap.headMap("100");
 		headMap.headMap("100");
+
+	SortedMap<Integer,Integer> intMap,sub;
+        int size = 16;
+        intMap = new TreeMap<Integer,Integer>();
+        for(int i=0; i<size; i++) {
+            intMap.put(i,i);
+        }
+        sub = intMap.headMap(-1);
+        assertEquals("size should be zero",sub.size(),0);
+        assertTrue("submap should be empty",sub.isEmpty());
+        try{
+            sub.firstKey();
+            fail("java.util.NoSuchElementException should be thrown");
+        } catch(java.util.NoSuchElementException e) {
+        }
 		
 		TreeMap t = new TreeMap();
 		try {
@@ -364,6 +379,33 @@
         } catch( NullPointerException npe) {
             // expected
         }
+
+        try{
+            sub.lastKey();
+            fail("java.util.NoSuchElementException should be thrown");
+        } catch(java.util.NoSuchElementException e) {
+        }
+
+        size = 256;
+        intMap = new TreeMap<Integer,Integer>();
+        for(int i=0; i<size; i++) {
+            intMap.put(i,i);
+        }
+        sub = intMap.headMap(-1);
+        assertEquals("size should be zero",sub.size(),0);
+        assertTrue("submap should be empty",sub.isEmpty());
+        try{
+            sub.firstKey();
+            fail("java.util.NoSuchElementException should be thrown");
+        } catch(java.util.NoSuchElementException e) {
+        }
+        
+        try{
+            sub.lastKey();
+            fail("java.util.NoSuchElementException should be thrown");
+        } catch(java.util.NoSuchElementException e) {
+        }
+
     }
 
     /**
@@ -553,6 +595,21 @@
 
         // Regression for Harmony-1066
         assertTrue(tail instanceof Serializable);
+
+	SortedMap<Integer,Integer> intMap,sub;
+        int size = 16;
+        intMap = new TreeMap<Integer,Integer>();
+        for(int i=0; i<size; i++) {
+            intMap.put(i,i);
+        }
+        sub = intMap.tailMap(size);
+        assertEquals("size should be zero",sub.size(),0);
+        assertTrue("submap should be empty",sub.isEmpty());
+        try{
+            sub.firstKey();
+            fail("java.util.NoSuchElementException should be thrown");
+        } catch(java.util.NoSuchElementException e) {
+        }
         
         TreeMap t = new TreeMap();
         try {
@@ -561,6 +618,33 @@
         } catch( NullPointerException npe) {
             // expected
         }
+
+        try{
+            sub.lastKey();
+            fail("java.util.NoSuchElementException should be thrown");
+        } catch(java.util.NoSuchElementException e) {
+        }
+
+        size = 256;
+        intMap = new TreeMap<Integer,Integer>();
+        for(int i=0; i<size; i++) {
+            intMap.put(i,i);
+        }
+        sub = intMap.tailMap(size);
+        assertEquals("size should be zero",sub.size(),0);
+        assertTrue("submap should be empty",sub.isEmpty());
+        try{
+            sub.firstKey();
+            fail("java.util.NoSuchElementException should be thrown");
+        } catch(java.util.NoSuchElementException e) {
+        }
+        
+        try{
+            sub.lastKey();
+            fail("java.util.NoSuchElementException should be thrown");
+        } catch(java.util.NoSuchElementException e) {
+        }
+
     }
 
     /**

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/VectorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/VectorTest.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/VectorTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/VectorTest.java Wed Dec  5 04:25:42 2007
@@ -17,6 +17,7 @@
 
 package tests.api.java.util;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Enumeration;
@@ -26,6 +27,7 @@
 import java.util.NoSuchElementException;
 import java.util.Vector;
 
+import tests.api.java.util.ArrayListTest.MockArrayList;
 import tests.support.Support_ListTest;
 
 public class VectorTest extends junit.framework.TestCase {
@@ -907,6 +909,22 @@
 		String result = v.toString();
 		assertTrue("should contain self ref", result.indexOf("(this") > -1);
 	}
+    
+    public void test_override_size() throws Exception {
+        Vector v = new Vector(); 
+        Vector testv = new MockVector();
+        // though size is overriden, it should passed without exception
+        testv.add(1);
+        testv.add(2);
+        testv.clear();
+        
+        testv.add(1);
+        testv.add(2);
+        v.add(1);
+        v.add(2);
+        // RI's bug here
+        assertTrue(testv.equals(v));
+    }
 
 	/**
 	 * @tests java.util.Vector#trimToSize()
@@ -922,6 +940,13 @@
 	protected Vector vectorClone(Vector s) {
 		return (Vector) s.clone();
 	}
+    
+    public class MockVector extends Vector{
+        @Override
+        public synchronized int size() {
+            return 0;
+        }
+    }
 
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java Wed Dec  5 04:25:42 2007
@@ -22,8 +22,11 @@
 import java.io.OutputStream;
 import java.util.ArrayList;
 
+import org.apache.harmony.pack200.bytecode.Attribute;
+import org.apache.harmony.pack200.bytecode.BCIRenumberedAttribute;
 import org.apache.harmony.pack200.bytecode.ByteCode;
 import org.apache.harmony.pack200.bytecode.CodeAttribute;
+import org.apache.harmony.pack200.bytecode.LineNumberTableAttribute;
 import org.apache.harmony.pack200.bytecode.OperandManager;
 
 /**
@@ -342,6 +345,7 @@
         operandManager.setSegment(segment);
 
         int i = 0;
+        ArrayList orderedCodeAttributes = segment.getClassBands().getOrderedCodeAttributes();
         for (int c = 0; c < classCount; c++) {
            int numberOfMethods = methodFlags[c].length;
            for (int m = 0; m < numberOfMethods; m++) {
@@ -360,7 +364,22 @@
                    CodeAttribute attr = new CodeAttribute(maxStack, maxLocal,
                            methodByteCodePacked[c][m], segment, operandManager);
                    methodAttributes[c][m].add(attr);
-                   i++;
+                   // Should I add all the attributes in here?
+                 ArrayList currentAttributes = (ArrayList)orderedCodeAttributes.get(i);
+                 for(int index=0;index < currentAttributes.size(); index++) {
+                     Attribute currentAttribute = (Attribute)currentAttributes.get(index);
+                     // TODO: The line below adds the LocalVariableTable
+                     // and LineNumber attributes. Currently things are
+                     // broken because these tables don't get renumbered
+                     // properly. Commenting out the add so the class files
+                     // will verify.
+                     //attr.attributes.add(currentAttribute);
+                     // Fix up the line numbers if needed
+                     if(currentAttribute.hasBCIRenumbering()) {
+                         ((BCIRenumberedAttribute)currentAttribute).renumber(attr.byteCodeOffsets);
+                     }
+                 }
+                 i++;
                }
            }
        }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java Wed Dec  5 04:25:42 2007
@@ -20,10 +20,10 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Iterator;
 
 import org.apache.harmony.pack200.IcBands.ICTuple;
+import org.apache.harmony.pack200.bytecode.Attribute;
 import org.apache.harmony.pack200.bytecode.CPClass;
 import org.apache.harmony.pack200.bytecode.CPUTF8;
 import org.apache.harmony.pack200.bytecode.ConstantValueAttribute;
@@ -997,6 +997,27 @@
 
     public long[][] getFieldFlags() {
         return fieldFlags;
+    }
+
+    /**
+     * Answer an ArrayList of ArrayLists which hold the the code attributes
+     * corresponding to all classes in order.
+     * 
+     * If a class doesn't have any attributes, the corresponding element in this
+     * list will be an empty ArrayList.
+     * @return ArrayList
+     */
+    public ArrayList getOrderedCodeAttributes() {
+        ArrayList orderedAttributeList = new ArrayList();
+        for(int classIndex=0; classIndex < codeAttributes.length; classIndex++) {
+            ArrayList currentAttributes = new ArrayList();
+            for(int attributeIndex = 0; attributeIndex < codeAttributes[classIndex].size(); attributeIndex++) {
+                Attribute attribute = (Attribute)codeAttributes[classIndex].get(attributeIndex);
+                currentAttributes.add(attribute);
+            }
+            orderedAttributeList.add(currentAttributes);
+        }
+        return orderedAttributeList;
     }
 
     public ArrayList[][] getMethodAttributes() {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java Wed Dec  5 04:25:42 2007
@@ -17,7 +17,6 @@
 package org.apache.harmony.pack200;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 
 import org.apache.harmony.pack200.bytecode.CPClass;
 import org.apache.harmony.pack200.bytecode.CPDouble;
@@ -29,7 +28,6 @@
 import org.apache.harmony.pack200.bytecode.CPMethodRef;
 import org.apache.harmony.pack200.bytecode.CPString;
 import org.apache.harmony.pack200.bytecode.CPUTF8;
-import org.apache.harmony.pack200.bytecode.ClassFileEntry;
 import org.apache.harmony.pack200.bytecode.ConstantPoolEntry;
 
 public class SegmentConstantPool {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentUtils.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentUtils.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentUtils.java Wed Dec  5 04:25:42 2007
@@ -92,4 +92,19 @@
 	private SegmentUtils() {
 		// Intended to be a helper class
 	}
+	
+    /**
+     * This is a debugging message to aid the developer in writing this
+     * class. If the property 'debug.pack200' is set, this will
+	 * generate messages to stderr; otherwise, it will be silent.
+     * 
+     * @param message
+     * @deprecated this may be removed from production code
+     */
+    public static void debug(String message) {
+        if (System.getProperty("debug.pack200") != null) {
+            System.err.println(message);
+        }
+    }
+
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/Attribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/Attribute.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/Attribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/Attribute.java Wed Dec  5 04:25:42 2007
@@ -20,59 +20,82 @@
 import java.io.IOException;
 
 public abstract class Attribute extends ClassFileEntry {
-	private final CPUTF8 attributeName;
+    private final CPUTF8 attributeName;
 
-	private int attributeNameIndex;
+    private int attributeNameIndex;
 
-	public Attribute(String attributeName) {
-		this.attributeName = new CPUTF8(attributeName);
-	}
-
-	protected void doWrite(DataOutputStream dos) throws IOException {
-		dos.writeShort(attributeNameIndex);
-		dos.writeInt(getLength());
-		writeBody(dos);
-	}
-
-	public boolean equals(Object obj) {
-		if (this == obj)
-			return true;
-		if (obj == null)
-			return false;
-		if (this.getClass() != obj.getClass())
-			return false;
-		final Attribute other = (Attribute) obj;
-		if (attributeName == null) {
-			if (other.attributeName != null)
-				return false;
-		} else if (!attributeName.equals(other.attributeName))
-			return false;
-		return true;
-	}
-
-	protected CPUTF8 getAttributeName() {
-		return attributeName;
-	}
-
-	protected abstract int getLength();
-
-	protected ClassFileEntry[] getNestedClassFileEntries() {
-		return new ClassFileEntry[] { getAttributeName() };
-	}
-
-	public int hashCode() {
-		final int PRIME = 31;
-		int result = 1;
-		result = PRIME * result
-				+ ((attributeName == null) ? 0 : attributeName.hashCode());
-		return result;
-	}
-
-	protected void resolve(ClassConstantPool pool) {
-		super.resolve(pool);
-		attributeNameIndex = pool.indexOf(attributeName);
-	}
+    public Attribute(String attributeName) {
+        this.attributeName = new CPUTF8(attributeName);
+    }
+
+    protected void doWrite(DataOutputStream dos) throws IOException {
+        dos.writeShort(attributeNameIndex);
+        dos.writeInt(getLength());
+        writeBody(dos);
+    }
+
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (this.getClass() != obj.getClass())
+            return false;
+        final Attribute other = (Attribute) obj;
+        if (attributeName == null) {
+            if (other.attributeName != null)
+                return false;
+        } else if (!attributeName.equals(other.attributeName))
+            return false;
+        return true;
+    }
+
+    protected CPUTF8 getAttributeName() {
+        return attributeName;
+    }
+
+    protected abstract int getLength();
+
+    /**
+     * Answer the length of the receiver including its header (the u2 for the
+     * attribute name and the u4 for the attribute length). This is relevant
+     * when attributes are nested within other attributes - the outer attribute
+     * needs to take the inner attribute headers into account when calculating
+     * its length.
+     * 
+     * @return int adjusted length
+     */
+    protected int getLengthIncludingHeader() {
+        return getLength() + 2 + 4;
+    }
+
+    protected ClassFileEntry[] getNestedClassFileEntries() {
+        return new ClassFileEntry[] { getAttributeName() };
+    }
+
+    /**
+     * Answer true if the receiver needs to have BCI renumbering applied to it;
+     * otherwise answer false.
+     * 
+     * @return boolean BCI renumbering required
+     */
+    public boolean hasBCIRenumbering() {
+        return false;
+    }
+
+    public int hashCode() {
+        final int PRIME = 31;
+        int result = 1;
+        result = PRIME * result
+                + ((attributeName == null) ? 0 : attributeName.hashCode());
+        return result;
+    }
+
+    protected void resolve(ClassConstantPool pool) {
+        super.resolve(pool);
+        attributeNameIndex = pool.indexOf(attributeName);
+    }
 
-	protected abstract void writeBody(DataOutputStream dos) throws IOException;
+    protected abstract void writeBody(DataOutputStream dos) throws IOException;
 
-}
\ No newline at end of file
+}

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java Wed Dec  5 04:25:42 2007
@@ -18,7 +18,9 @@
 
 import java.io.DataOutputStream;
 import java.io.IOException;
+
 import org.apache.harmony.pack200.Segment;
+import org.apache.harmony.pack200.SegmentUtils;
 import org.apache.harmony.pack200.bytecode.forms.ByteCodeForm;
 
 public class ByteCode extends ClassFileEntry {
@@ -33,6 +35,9 @@
 	private int[][] nestedPositions;
 	private int[] rewrite;
 
+    private int byteCodeOffset = -1;
+    private int byteCodeTarget = -1;
+
 	protected ByteCode(int opcode) {
 		this(opcode, ClassFileEntry.NONE);
 	}
@@ -131,12 +136,12 @@
 				
 				case 4:
 					// TODO: need to handle wides?
-					System.out.println("Need to handle wides");
+					SegmentUtils.debug("Need to handle wides");
 					// figure out and if so, handle and put a break here.
 					// break;
 				
 				default: 
-					System.out.println("Unhandled resolve " + this);
+					SegmentUtils.debug("Unhandled resolve " + this);
 				}
 			}
 		}
@@ -181,7 +186,7 @@
 	 */
 	public void setOperandInt(int operand, int position) {
 		int firstOperandIndex = getByteCodeForm().firstOperandIndex();
-		int byteCodeFormLength = getByteCodeForm().operandLength();
+		int byteCodeFormLength = getByteCodeForm().getRewrite().length;
 		if (firstOperandIndex < 1) {
 			// No operand rewriting permitted for this bytecode
 			throw new Error("Trying to rewrite " + this + " that has no rewrite");
@@ -191,11 +196,26 @@
 			throw new Error("Trying to rewrite " + this + " with an int at position " + position + " but this won't fit in the rewrite array");
 		}
 		
-		rewrite[firstOperandIndex + position] = (operand & 0xFF00) >> 8;
-		rewrite[firstOperandIndex + position + 1] = operand & 0xFF;		
+	    rewrite[firstOperandIndex + position] = (operand & 0xFF00) >> 8;
+	    rewrite[firstOperandIndex + position + 1] = operand & 0xFF;
 	}
 	
 	/**
+	 * This is just like setOperandInt, but takes special care when the
+	 * operand is less than 0 to make sure it's written correctly.
+	 * @param operand int to set the rewrite bytes to
+	 * @param position int position of the operands in the rewrite bytes
+	 */
+	public void setOperandSignedInt(int operand, int position) {
+	    if(operand >= 0) {
+	        setOperandInt(operand, position);
+	    } else {
+	        int twosComplementOperand = 0x10000 + operand;
+	        setOperandInt(twosComplementOperand, position);
+	    }
+	}
+
+	/**
 	 * Given an int operand, treat it as a byte and set
 	 * the rewrite byte for that position to that value.
 	 * Mask of anything beyond 0xFF.
@@ -260,4 +280,66 @@
 	public int[] getNestedPosition(int index) {
 		return getNestedPositions()[index];
 	}
+
+    /**
+     * This method will answer true if the receiver is
+     * a multi-bytecode instruction (such as
+     * aload0_putfield_super); otherwise, it will answer
+     * false.
+     * 
+     * @return boolean true if multibytecode, false otherwise
+     */
+	public boolean hasMultipleByteCodes() {
+		return getByteCodeForm().hasMultipleByteCodes();
+	}
+
+    /**
+     * ByteCodes may need to know their position in the
+     * code array (in particular, label byte codes need
+     * to know where they are in order to calculate their
+     * targets). This method lets the CodeAttribute specify
+     * where the byte code is.
+     * 
+     * Since there are no aload0+label instructions, this
+     * method doesn't worry about multioperation bytecodes.
+     * 
+     * @param byteCodeOffset int position in code array.
+     */
+    public void setByteCodeIndex(int byteCodeOffset) {
+        this.byteCodeOffset = byteCodeOffset;
+    }
+
+
+    public int getByteCodeIndex() {
+        return byteCodeOffset;
+    }
+    
+    /**
+     * Some ByteCodes (in particular, LabelForm bytecodes)
+     * have to keep track of a byteCodeTarget. This is
+     * initially an offset in the CodeAttribute array
+     * relative to the byteCodeOffset, but later gets fixed
+     * up to point to the absolute position in the CodeAttribute
+     * array. This method sets the target.
+     * 
+     * @param byteCodeTarget int index in array
+     */
+    public void setByteCodeTarget(int byteCodeTarget) {
+        this.byteCodeTarget = byteCodeTarget;
+    }
+    
+    public int getByteCodeTarget() {
+        return byteCodeTarget;
+    }
+    
+    /**
+     * Some ByteCodes (in particular, those with the Label
+     * form) need to be fixed up after all the bytecodes
+     * in the CodeAttribute have been added. (This can't
+     * be done beforehand because the CodeAttribute needs
+     * to be complete before targets can be assigned.)
+     */
+    public void applyByteCodeTargetFixup(CodeAttribute codeAttribute) {
+        getByteCodeForm().fixUpByteCodeTarget(this, codeAttribute);
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java Wed Dec  5 04:25:42 2007
@@ -21,8 +21,10 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+
 import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.pack200.Segment;
+import org.apache.harmony.pack200.SegmentUtils;
 
 
 public class ClassConstantPool {
@@ -60,7 +62,12 @@
 	public int indexOf(ClassFileEntry entry) {
 		if (!resolved)
 			throw new IllegalStateException("Constant pool is not yet resolved; this does not make any sense");
-		return entries.indexOf(entry) + 1;
+		int entryIndex = entries.indexOf(entry);
+		// If the entry isn't found, answer -1. Otherwise answer the entry.
+		if(entryIndex != -1) {
+		    return entryIndex + 1;
+		}
+		return -1;
 	}
 
 	public int size() {
@@ -74,7 +81,7 @@
 	}
 
 	public void resolve(Segment segment) {
-		System.out.println("\n\nResolving (Segment.resolve(Segment)");
+		SegmentUtils.debug("\n\nResolving (Segment.resolve(Segment)");
 		HashMap sortMap = new HashMap();
 		List cpAll = null;
 		// TODO: HACK - this is a 1.5 api.
@@ -101,7 +108,7 @@
 			}
 		}
 		for(int xindex=0; xindex < sortedList.size(); xindex++) {
-			System.out.println(sortedList.get(xindex));
+			SegmentUtils.debug(sortedList.get(xindex).toString());
 		}
 		resolve();
 	}

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFile.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFile.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFile.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFile.java Wed Dec  5 04:25:42 2007
@@ -56,7 +56,7 @@
 			fields[i].write(dos);
 		}
 		dos.writeShort(methods.length);
-		for(int i=0;i<methods.length;i++) {
+        for(int i=0;i<methods.length;i++) {
 			methods[i].write(dos);
 		}
 		dos.writeShort(attributes.length);

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CodeAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CodeAttribute.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CodeAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CodeAttribute.java Wed Dec  5 04:25:42 2007
@@ -25,89 +25,115 @@
 import org.apache.harmony.pack200.Segment;
 
 public class CodeAttribute extends Attribute {
-	public List attributes = new ArrayList();
-	public List byteCodes = new ArrayList();
-	public int codeLength;
-	public List exceptionTable = new ArrayList(); // of ExceptionTableEntry
-	// instances
-	public int maxLocals;
-	public int maxStack;
-
-	public CodeAttribute(int maxStack, int maxLocals, byte codePacked[],
-			Segment segment, OperandManager operandManager) {
-		super("Code"); //$NON-NLS-1$
-		this.maxLocals = maxLocals;
-		this.maxStack = maxStack;
-		this.codeLength = 0;
-		for (int i = 0; i < codePacked.length; i++) {
-			ByteCode byteCode = ByteCode.getByteCode(codePacked[i] & 0xff);
-			byteCode.extractOperands(operandManager, segment);
-			byteCodes.add(byteCode);
-			this.codeLength += byteCode.getLength();
-		}
-	}
-
-	protected int getLength() {
-		int attributesSize = 0;
-		Iterator it = attributes.iterator();
-		while (it.hasNext()) {
-			Attribute attribute = (Attribute) it.next();
-			attributesSize += attribute.getLength();
-		}
-		return 2 + 2 + 4 + codeLength + exceptionTable.size() * (2 + 2 + 2 + 2)
-				+ 2 + attributesSize;
-	}
-
-	protected ClassFileEntry[] getNestedClassFileEntries() {
-		ArrayList nestedEntries = new ArrayList();
-		nestedEntries.add(getAttributeName());
-		nestedEntries.addAll(byteCodes);
-		ClassFileEntry[] nestedEntryArray = new ClassFileEntry[nestedEntries.size()];
-		nestedEntries.toArray(nestedEntryArray);
-		return nestedEntryArray;
-	}
-
-	protected void resolve(ClassConstantPool pool) {
-		super.resolve(pool);
-		Iterator it = attributes.iterator();
-		while (it.hasNext()) {
-			Attribute attribute = (Attribute) it.next();
-			attribute.resolve(pool);
-		}
-		it = byteCodes.iterator();
-		while (it.hasNext()) {
-			ByteCode byteCode = (ByteCode) it.next();
-			byteCode.resolve(pool);
-		}
-	}
-
-	public String toString() {
-		// TODO More Info here later
-		return "Code: " + getLength() + " bytes";
-	}
-
-	protected void writeBody(DataOutputStream dos) throws IOException {
-		dos.writeShort(maxStack);
-		dos.writeShort(maxLocals);
-		dos.writeInt(codeLength);
-		Iterator it = byteCodes.iterator();
-		while (it.hasNext()) {
-			ByteCode byteCode = (ByteCode) it.next();
-			byteCode.write(dos);
-		}
-		dos.writeShort(exceptionTable.size());
-		Iterator exceptionTableEntries = exceptionTable.iterator();
-		while (exceptionTableEntries.hasNext()) {
-			ExceptionTableEntry entry = (ExceptionTableEntry) exceptionTableEntries
-					.next();
-			entry.write(dos);
-		}
-		dos.writeShort(attributes.size());
-		it = attributes.iterator();
-		while (it.hasNext()) {
-			Attribute attribute = (Attribute) it.next();
-			attribute.write(dos);
-		}
-	}
+    public List attributes = new ArrayList();
+    // instances
+    public List byteCodeOffsets = new ArrayList();
+    public List byteCodes = new ArrayList();
+    public int codeLength;
+    public List exceptionTable = new ArrayList(); // of ExceptionTableEntry
+    public int maxLocals;
+    public int maxStack;
+
+    public CodeAttribute(int maxStack, int maxLocals, byte codePacked[],
+            Segment segment, OperandManager operandManager) {
+        super("Code"); //$NON-NLS-1$
+        this.maxLocals = maxLocals;
+        this.maxStack = maxStack;
+        this.codeLength = 0;
+        byteCodeOffsets.add(new Integer(0));
+        for (int i = 0; i < codePacked.length; i++) {
+            ByteCode byteCode = ByteCode.getByteCode(codePacked[i] & 0xff);
+            // Setting the offset must happen before extracting operands
+            // because label bytecodes need to know their offsets.
+            byteCode.setByteCodeIndex(i);
+            byteCode.extractOperands(operandManager, segment);
+            byteCodes.add(byteCode);
+            codeLength += byteCode.getLength();
+            int lastBytecodePosition = ((Integer) byteCodeOffsets
+                    .get(byteCodeOffsets.size() - 1)).intValue();
+            // This code assumes all multiple byte bytecodes are
+            // replaced by a single-byte bytecode followed by
+            // another bytecode.
+            if (byteCode.hasMultipleByteCodes()) {
+                byteCodeOffsets.add(new Integer(lastBytecodePosition + 1));
+            }
+            // I've already added the first element (at 0) before
+            // entering this loop, so make sure I don't add one
+            // after the last element.
+            if (i < (codePacked.length - 1)) {
+                byteCodeOffsets.add(new Integer(lastBytecodePosition
+                        + byteCode.getLength()));
+            }
+        }
+        // Now that all the bytecodes know their positions and
+        // sizes, fix up the byte code targets
+        for (int i = 0; i < codePacked.length; i++) {
+            ByteCode byteCode = (ByteCode)byteCodes.get(i);
+            byteCode.applyByteCodeTargetFixup(this);
+        }
+    }
+
+    protected int getLength() {
+        int attributesSize = 0;
+        Iterator it = attributes.iterator();
+        while (it.hasNext()) {
+            Attribute attribute = (Attribute) it.next();
+            attributesSize += attribute.getLengthIncludingHeader();
+        }
+        return 2 + 2 + 4 + codeLength + 2 + exceptionTable.size()
+                * (2 + 2 + 2 + 2) + 2 + attributesSize;
+    }
+
+    protected ClassFileEntry[] getNestedClassFileEntries() {
+        ArrayList nestedEntries = new ArrayList();
+        nestedEntries.add(getAttributeName());
+        nestedEntries.addAll(byteCodes);
+        ClassFileEntry[] nestedEntryArray = new ClassFileEntry[nestedEntries
+                .size()];
+        nestedEntries.toArray(nestedEntryArray);
+        return nestedEntryArray;
+    }
+
+    protected void resolve(ClassConstantPool pool) {
+        super.resolve(pool);
+        Iterator it = attributes.iterator();
+        while (it.hasNext()) {
+            Attribute attribute = (Attribute) it.next();
+            attribute.resolve(pool);
+        }
+        it = byteCodes.iterator();
+        while (it.hasNext()) {
+            ByteCode byteCode = (ByteCode) it.next();
+            byteCode.resolve(pool);
+        }
+    }
+
+    public String toString() {
+        return "Code: " + getLength() + " bytes";
+    }
+
+    protected void writeBody(DataOutputStream dos) throws IOException {
+        dos.writeShort(maxStack);
+        dos.writeShort(maxLocals);
+        dos.writeInt(codeLength);
+        Iterator it = byteCodes.iterator();
+        while (it.hasNext()) {
+            ByteCode byteCode = (ByteCode) it.next();
+            byteCode.write(dos);
+        }
+        dos.writeShort(exceptionTable.size());
+        Iterator exceptionTableEntries = exceptionTable.iterator();
+        while (exceptionTableEntries.hasNext()) {
+            ExceptionTableEntry entry = (ExceptionTableEntry) exceptionTableEntries
+                    .next();
+            entry.write(dos);
+        }
+        dos.writeShort(attributes.size());
+        it = attributes.iterator();
+        while (it.hasNext()) {
+            Attribute attribute = (Attribute) it.next();
+            attribute.write(dos);
+        }
+    }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LineNumberTableAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LineNumberTableAttribute.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LineNumberTableAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LineNumberTableAttribute.java Wed Dec  5 04:25:42 2007
@@ -18,8 +18,9 @@
 
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.List;
 
-public class LineNumberTableAttribute extends Attribute {
+public class LineNumberTableAttribute extends BCIRenumberedAttribute {
 
     private int line_number_table_length;
     private int[] start_pcs;
@@ -44,8 +45,22 @@
         }
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.harmony.pack200.bytecode.ClassFileEntry#toString()
+     */
     public String toString() {
         return "LineNumberTable: " + line_number_table_length + " lines";
     }
 
+	/* (non-Javadoc)
+	 * @see org.apache.harmony.pack200.bytecode.Attribute#resolve(org.apache.harmony.pack200.bytecode.ClassConstantPool)
+	 */
+	protected void resolve(ClassConstantPool pool) {
+		pool.add(getAttributeName());
+		super.resolve(pool);
+	}
+
+    protected int[] getStartPCs() {
+        return start_pcs;
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LocalVariableTableAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LocalVariableTableAttribute.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LocalVariableTableAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LocalVariableTableAttribute.java Wed Dec  5 04:25:42 2007
@@ -18,9 +18,9 @@
 
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.List;
 
-public class LocalVariableTableAttribute extends Attribute {
-
+public class LocalVariableTableAttribute extends BCIRenumberedAttribute {
 
     private int local_variable_table_length;
     private int[] start_pcs;
@@ -60,9 +60,15 @@
 
     protected void resolve(ClassConstantPool pool) {
         super.resolve(pool);
+        pool.add(getAttributeName());
         name_indexes = new int[local_variable_table_length];
         descriptor_indexes = new int[local_variable_table_length];
         for (int i = 0; i < local_variable_table_length; i++) {
+            // TODO: is this the right place to add the names and descriptors?
+            // Maybe some API to say where they should be added if they're not
+            // already in the cp?
+            pool.add(names[i]);
+            pool.add(descriptors[i]);
             names[i].resolve(pool);
             descriptors[i].resolve(pool);
             name_indexes[i] = pool.indexOf(names[i]);
@@ -71,7 +77,35 @@
     }
     
     public String toString() {
-        return "LocalVariableTable: " + + local_variable_table_length + " varaibles";
+        return "LocalVariableTable: " + + local_variable_table_length + " variables";
+    }
+
+    protected int[] getStartPCs() {
+        return start_pcs;
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.harmony.pack200.bytecode.BCIRenumberedAttribute#renumber(java.util.List)
+     */
+    public void renumber(List byteCodeOffsets) {
+        // First fix up the start_pcs
+        super.renumber(byteCodeOffsets);
+        // Next fix up the lengths
+        int maxLength = ((Integer)byteCodeOffsets.get(byteCodeOffsets.size() - 1)).intValue();
+        for(int index=0; index < lengths.length; index++) {
+            // Need to special case when the length is greater than the size
+            int revisedLength = -1;
+            int encodedLength = lengths[index];
+            // Length can either be an index into the byte code offsets, or one beyond the
+            // end of the byte code offsets. Need to determine which this is.
+            if(encodedLength == byteCodeOffsets.size()) {
+                // Pointing to one past the end of the byte code array
+                revisedLength = maxLength - start_pcs[index] + 1;
+            } else {
+                // We're indexed into the byte code array
+                revisedLength = ((Integer)byteCodeOffsets.get(encodedLength)).intValue();                
+            }
+            lengths[index] = revisedLength;
+        }
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/OperandManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/OperandManager.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/OperandManager.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/OperandManager.java Wed Dec  5 04:25:42 2007
@@ -166,14 +166,6 @@
 		return bcInitRef[bcInitRefIndex++];
 	}
 
-	public static void main(String args[]) {
-		int foo[] = {1, 172, 3, 4};
-		OperandManager op = new OperandManager(foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo, foo);
-		for(int index=0; index < 4; index++) {
-			System.out.println(op.nextByte());
-		}
-	}
-
 	public void setSegment(Segment segment) {
 		this.segment = segment;
 	}

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ByteCodeForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ByteCodeForm.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ByteCodeForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ByteCodeForm.java Wed Dec  5 04:25:42 2007
@@ -20,6 +20,7 @@
 import java.util.Map;
 
 import org.apache.harmony.pack200.bytecode.ByteCode;
+import org.apache.harmony.pack200.bytecode.CodeAttribute;
 import org.apache.harmony.pack200.bytecode.OperandManager;
 
 public class ByteCodeForm {
@@ -295,7 +296,7 @@
         byteCodeArray[229] = new SuperFieldRefForm(229, "aload_0_invokestatic_super", new int[] {42, 184, -1, -1});
         byteCodeArray[230] = new ThisInitMethodRefForm(230, "invokespecial_this_init", new int[] {183, -1, -1});
         byteCodeArray[231] = new SuperInitMethodRefForm(231, "invokespecial_super_init", new int[] {183, -1, -1});
-        byteCodeArray[232] = new NewInitMethodRefForm(232, "invokespecial_new_init", new int[] {184, -1, -1});
+        byteCodeArray[232] = new NewInitMethodRefForm(232, "invokespecial_new_init", new int[] {183, -1, -1});
         byteCodeArray[233] = new ClassRefForm(233, "cldc", new int[] {18, -1}); 
         byteCodeArray[234] = new IntRefForm(234, "ildc", new int[] {18, -1});
         byteCodeArray[235] = new FloatRefForm(235, "fldc", new int[] {18, -1});
@@ -541,6 +542,29 @@
         return false;
     }
 
+    
+    /**
+     * This method will answer true if the receiver is
+     * a multi-bytecode instruction (such as
+     * aload0_putfield_super); otherwise, it will answer
+     * false.
+     * 
+     * @return boolean true if multibytecode, false otherwise
+     */
+    public boolean hasMultipleByteCodes() {
+    	if(rewrite.length > 1) {
+             // Currently, all multi-bytecode instructions
+             // begin with aload_0, so this is how we test.
+    		if(rewrite[0] == 42) {
+    			// If there's an instruction (not a negative
+    			// number, which is an operand) after the
+    			// aload_0, it's a multibytecode instruction.
+    			return(rewrite[1] > 0);
+    		}
+    	}
+    	return false;
+    }
+    
     /**
      * When passed a byteCode, an OperandTable and a
      * SegmentConstantPool, this method will set the
@@ -553,5 +577,18 @@
     public void setByteCodeOperands(ByteCode byteCode,
             OperandManager operandManager) {
         throw new Error("My subclass should have implemented this");        
+    }
+
+    /**
+     * The ByteCodeForm knows how to fix up a bytecode if
+     * it needs to be fixed up because it holds a Label
+     * bytecode.
+     * @param byteCode a ByteCode to be fixed up
+     * @param codeAttribute a CodeAttribute used to determine how
+     *   the ByteCode should be fixed up.
+     */
+    public void fixUpByteCodeTarget(ByteCode byteCode, CodeAttribute codeAttribute) {
+        // Most ByteCodeForms don't have any fixing up to do.
+        return;
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LabelForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LabelForm.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LabelForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LabelForm.java Wed Dec  5 04:25:42 2007
@@ -17,6 +17,7 @@
 package org.apache.harmony.pack200.bytecode.forms;
 
 import org.apache.harmony.pack200.bytecode.ByteCode;
+import org.apache.harmony.pack200.bytecode.CodeAttribute;
 import org.apache.harmony.pack200.bytecode.OperandManager;
 
 /**
@@ -47,17 +48,34 @@
     }
 
     /* (non-Javadoc)
-     * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool)
+     * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#fixUpByteCodeTarget(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.CodeAttribute)
      */
-    public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
-        // TODO: if this is widened, probably need to do something
-        // different from setOperandInt().
-        byteCode.setOperandInt(operandManager.nextLabel(), 0);
+    public void fixUpByteCodeTarget(ByteCode byteCode, CodeAttribute codeAttribute) {
+        // LabelForms need to fix up the target of label operations
+        int originalTarget = byteCode.getByteCodeTarget();
+        int sourceIndex = byteCode.getByteCodeIndex();
+        int absoluteInstructionTargetIndex = sourceIndex + originalTarget;
+        int targetValue = ((Integer)codeAttribute.byteCodeOffsets.get(absoluteInstructionTargetIndex)).intValue();
+        int sourceValue = ((Integer)codeAttribute.byteCodeOffsets.get(sourceIndex)).intValue();
+        // The operand is the difference between the source instruction
+        // and the destination instruction.
+        // TODO: Probably have to do something other than setOperandInt if this is widened.
+        byteCode.setOperandSignedInt(targetValue - sourceValue, 0);
         if(widened) {
             byteCode.setNestedPositions(new int[][] {{0,4}});
         } else {
             byteCode.setNestedPositions(new int[][] {{0,2}});
         }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool)
+     */
+    public void setByteCodeOperands(ByteCode byteCode,
+            OperandManager operandManager) {
+        byteCode.setByteCodeTarget(operandManager.nextLabel());
+        // The byte code operands actually get set later -
+        // once we have all the bytecodes - in fixUpByteCodeTarget().
+        return;
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java Wed Dec  5 04:25:42 2007
@@ -31,6 +31,8 @@
 import org.apache.harmony.pack200.Segment;
 import org.apache.harmony.pack200.SegmentConstantPool;
 import org.apache.harmony.pack200.SegmentHeader;
+import org.apache.harmony.pack200.bytecode.Attribute;
+import org.apache.harmony.pack200.bytecode.LineNumberTableAttribute;
 
 import junit.framework.TestCase;
 
@@ -179,6 +181,19 @@
             }
             return attributes;
         }
+        
+        public ArrayList getOrderedCodeAttributes() {
+            int totalMethods = 0;
+            for(int classIndex = 0; classIndex < numMethods.length; classIndex++) {
+                totalMethods = totalMethods + numMethods[classIndex];
+            }
+            ArrayList orderedAttributeList = new ArrayList();
+            for(int classIndex=0; classIndex < totalMethods; classIndex++) {
+                ArrayList currentAttributes = new ArrayList();
+                orderedAttributeList.add(currentAttributes);
+            }
+            return orderedAttributeList;
+        }
     }
 
     public class MockSegment extends AbstractBandsTestCase.MockSegment {
@@ -364,7 +379,9 @@
                 (byte) 162, (byte) 163, (byte) 164, (byte) 165, (byte) 166,
                 (byte) 167, (byte) 168, (byte) 170, (byte) 171, (byte) 198, (byte) 199, (byte) 200, (byte) 201, (byte) 255,
                 0, 0, // bc_case_count (required by tableswitch (170) and lookupswitch (171))
-                8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}; // bc_label band
+//                Now that we're actually doing real label lookup, need valid labels
+//                8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }; // bc_label band                
+                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // bc_label band
         InputStream in = new ByteArrayInputStream(bytes);
         bcBands.unpack(in);
         assertEquals(16, bcBands.getMethodByteCodePacked()[0][0].length);

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java Wed Dec  5 04:25:42 2007
@@ -70,6 +70,8 @@
 
     public void setDelete() {
         isDelete = true;
+        isUpdate = false;
+        isInsert = false;
     }
 
     public void undoDelete() {
@@ -82,6 +84,8 @@
 
     public void setInsert() {
         isInsert = true;
+        isUpdate = false;
+        isDelete = false;
     }
 
     public boolean isInsert() {
@@ -90,6 +94,8 @@
 
     public void setUpdate() {
         isUpdate = true;
+        isInsert = false;
+        isDelete = false;
     }
 
     public void undoUpdate() {

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java Wed Dec  5 04:25:42 2007
@@ -52,7 +52,6 @@
 import javax.sql.RowSetInternal;
 import javax.sql.RowSetListener;
 import javax.sql.RowSetMetaData;
-import javax.sql.RowSetWriter;
 import javax.sql.rowset.BaseRowSet;
 import javax.sql.rowset.CachedRowSet;
 import javax.sql.rowset.RowSetMetaDataImpl;
@@ -139,7 +138,7 @@
     }
 
     public void acceptChanges() throws SyncProviderException {
-        if (currentRow == insertRow) {
+        if (currentRow == insertRow && currentRow != null) {
             throw new SyncProviderException();
         }
 
@@ -152,25 +151,28 @@
     }
 
     public void acceptChanges(Connection con) throws SyncProviderException {
-        if (currentRow == insertRow) {
+        if (currentRow == insertRow && currentRow != null) {
             // TODO add error messages
             throw new SyncProviderException();
         }
 
         try {
-            setUrl(con.getMetaData().getURL());
-            RowSetWriter rowSetWriter = syncProvider.getRowSetWriter();
-            CachedRowSetImpl input = (CachedRowSetImpl) createCopy();
-            rowSetWriter.writeData(input);
+            CachedRowSetWriter rowSetWriter = (CachedRowSetWriter) syncProvider
+                    .getRowSetWriter();
+            rowSetWriter.setConnection(con);
+            int beforeWriteIndex = currentRowIndex;
+            rowSetWriter.writeData(this);
+            absolute(beforeWriteIndex);
             /*
              * FIXME: if no conflicts happen when writeData, then call
              * setOriginalRow()
              */
             notifyRowSetChanged();
+
+        } catch (SyncProviderException e) {
+            throw e;
         } catch (SQLException e) {
-            // TODO deal with the exception
-            e.printStackTrace();
-            throw new SyncProviderException();
+            throw new SyncProviderException(e.getMessage());
         }
     }
 
@@ -338,7 +340,7 @@
             ps.setObject(i + 1, params[i]);
 
         if (ps.execute()) {
-            populate(ps.getResultSet());
+            doPopulate(ps.getResultSet(), true);
         }
     }
 
@@ -391,25 +393,51 @@
         return false;
     }
 
-    public void populate(ResultSet data) throws SQLException {
-        populate(data, -1);
+    public void populate(ResultSet rs) throws SQLException {
+        doPopulate(rs, false);
     }
 
     public void populate(ResultSet rs, int startRow) throws SQLException {
+        if (startRow == 1) {
+            rs.beforeFirst();
+        } else if (startRow <= 0 || !rs.absolute(startRow - 1)) {
+            // rowset.7=Not a valid cursor
+            throw new SQLException(Messages.getString("rowset.7")); //$NON-NLS-1$
+        }
+
+        doPopulate(rs, true);
+    }
+
+    private void doPopulate(ResultSet rs, boolean isPaging) throws SQLException {
         meta = copyMetaData(rs.getMetaData());
 
-        new CachedRowSetReader(rs, startRow).readData(this);
+        /*
+         * this method not support paging, so before readData set pageSize and
+         * maxRowsto 0 and restore previous values after readData
+         */
+        if (!isPaging) {
+            int prePageSize = getPageSize();
+            setPageSize(0);
+            int preMaxRows = getMaxRows();
+            setMaxRows(0);
+            // FIXME use SyncProvider to get RowSetReader
+            new CachedRowSetReader(rs).readData(this);
+            setPageSize(prePageSize);
+            setMaxRows(preMaxRows);
+        } else {
+            // FIXME use SyncProvider to get RowSetReader
+            new CachedRowSetReader(rs).readData(this);
+        }
 
         setTableName(rs.getMetaData().getTableName(1));
 
         originalResultSet = new CachedRowSetImpl();
-        new CachedRowSetReader(this, startRow).readData(originalResultSet);
+        // FIXME use SyncProvider to get RowSetReader
+        new CachedRowSetReader(this).readData(originalResultSet);
         originalResultSet.setMetaData((RowSetMetaData) (getMetaData()));
 
         // recovery the states
-        currentRow = null;
-        currentRowIndex = 0;
-
+        beforeFirst();
     }
 
     // deep copy of ResultSetMetaData
@@ -843,7 +871,6 @@
     }
 
     public int getInt(int columnIndex) throws SQLException {
-        checkCursorValid();
         checkValidRow();
         Object value = currentRow.getObject(columnIndex);
         if (value == null) {
@@ -997,11 +1024,9 @@
             // rowset.4=Not an insert row
             throw new SQLException(Messages.getString("rowset.4"));
         }
-        currentRow.setInsert();
+        insertRow.setInsert();
         rows.add(insertRow);
-        currentRowIndex++;
-        // TODO insert the data into database
-        // insertRowToDB(rows);
+        insertRow = null;
     }
 
     public boolean isAfterLast() throws SQLException {
@@ -1037,19 +1062,22 @@
     }
 
     public void moveToCurrentRow() throws SQLException {
-
-        if (currentRow == insertRow) {
+        if (rememberedCursorPosition != -1) {
             currentRowIndex = rememberedCursorPosition;
-            currentRow = rows.get(currentRowIndex - 1);
+            if (currentRowIndex >= 1 && currentRowIndex <= size()) {
+                currentRow = rows.get(currentRowIndex - 1);
+            } else {
+                currentRow = null;
+            }
+            rememberedCursorPosition = -1;
         }
-
     }
 
     public void moveToInsertRow() throws SQLException {
         insertRow = new CachedRow(new Object[columnCount]);
         currentRow = insertRow;
         rememberedCursorPosition = currentRowIndex;
-        currentRowIndex = rows.size();
+        currentRowIndex = -1;
     }
 
     public boolean next() throws SQLException {
@@ -1096,21 +1124,23 @@
     }
 
     public boolean rowInserted() throws SQLException {
-
-        /**
-         * FIXME: Determin the currentRow if have had a insertion 1. Need
-         * traverse the rows and find if the data hava been added
-         */
+        if (currentRow == null || currentRow == insertRow) {
+            // TODO add error message
+            throw new SQLException();
+        }
         return currentRow.isInsert();
     }
 
     public boolean rowUpdated() throws SQLException {
-
-        boolean sign = false;
-        for (int i = 0; i < meta.getColumnCount(); ++i) {
-            sign = currentRow.getUpdateMask(i) | sign;
+        if (!currentRow.isUpdate()) {
+            return false;
+        } else {
+            boolean sign = false;
+            for (int i = 0; i < meta.getColumnCount(); ++i) {
+                sign = currentRow.getUpdateMask(i) | sign;
+            }
+            return sign;
         }
-        return sign;
     }
 
     public void updateArray(int columnIndex, Array x) throws SQLException {
@@ -1133,12 +1163,12 @@
 
     public void updateBigDecimal(int columnIndex, BigDecimal x)
             throws SQLException {
-        throw new NotImplementedException();
+        currentRow.updateObject(columnIndex, x);
     }
 
     public void updateBigDecimal(String columnName, BigDecimal x)
             throws SQLException {
-        throw new NotImplementedException();
+        updateBigDecimal(getIndexByName(columnName), x);
     }
 
     public void updateBinaryStream(int columnIndex, InputStream x, int length)
@@ -1202,27 +1232,27 @@
     }
 
     public void updateDate(int columnIndex, Date x) throws SQLException {
-        throw new NotImplementedException();
+        currentRow.updateObject(columnIndex, x);
     }
 
     public void updateDate(String columnName, Date x) throws SQLException {
-        throw new NotImplementedException();
+        updateDate(getIndexByName(columnName), x);
     }
 
     public void updateDouble(int columnIndex, double x) throws SQLException {
-        throw new NotImplementedException();
+        currentRow.updateObject(columnIndex, x);
     }
 
     public void updateDouble(String columnName, double x) throws SQLException {
-        throw new NotImplementedException();
+        updateDouble(getIndexByName(columnName), x);
     }
 
     public void updateFloat(int columnIndex, float x) throws SQLException {
-        throw new NotImplementedException();
+        currentRow.updateObject(columnIndex, x);
     }
 
     public void updateFloat(String columnName, float x) throws SQLException {
-        throw new NotImplementedException();
+        updateFloat(getIndexByName(columnName), x);
     }
 
     public void updateInt(int columnIndex, int x) throws SQLException {
@@ -1234,11 +1264,11 @@
     }
 
     public void updateLong(int columnIndex, long x) throws SQLException {
-        throw new NotImplementedException();
+        currentRow.updateObject(columnIndex, x);
     }
 
     public void updateLong(String columnName, long x) throws SQLException {
-        throw new NotImplementedException();
+        updateLong(getIndexByName(columnName), x);
     }
 
     public void updateNull(int columnIndex) throws SQLException {
@@ -1281,7 +1311,7 @@
             // TODO add error messages
             throw new SQLException();
         }
-        rows.set(currentRowIndex, currentRow);
+        currentRow.setUpdate();
         notifyRowChanged();
     }
 
@@ -1302,21 +1332,21 @@
     }
 
     public void updateTime(int columnIndex, Time x) throws SQLException {
-        throw new NotImplementedException();
+        currentRow.updateObject(columnIndex, x);
     }
 
     public void updateTime(String columnName, Time x) throws SQLException {
-        throw new NotImplementedException();
+        updateTime(getIndexByName(columnName), x);
     }
 
     public void updateTimestamp(int columnIndex, Timestamp x)
             throws SQLException {
-        throw new NotImplementedException();
+        currentRow.updateObject(columnIndex, x);
     }
 
     public void updateTimestamp(String columnName, Timestamp x)
             throws SQLException {
-        throw new NotImplementedException();
+        updateTimestamp(getIndexByName(columnName), x);
     }
 
     public boolean wasNull() throws SQLException {

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java?rev=601315&r1=601314&r2=601315&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetReader.java Wed Dec  5 04:25:42 2007
@@ -23,47 +23,47 @@
 
 import javax.sql.RowSetInternal;
 import javax.sql.RowSetReader;
-import javax.sql.rowset.CachedRowSet;
 
 public class CachedRowSetReader implements RowSetReader {
 
     private ResultSet rs;
 
-    private int startRow;
-
     private ResultSetMetaData metadata;
 
-    public CachedRowSetReader(ResultSet rs, int startRow) throws SQLException {
+    public CachedRowSetReader(ResultSet rs) throws SQLException {
         this.rs = rs;
-        this.startRow = startRow;
         this.metadata = rs.getMetaData();
     }
 
+    /**
+     * TODO disable all listeners
+     */
     public void readData(RowSetInternal theCaller) throws SQLException {
-        int pageSize = ((CachedRowSet)theCaller).getPageSize();
+        CachedRowSetImpl cachedRowSet = (CachedRowSetImpl) theCaller;
+        int pageSize = cachedRowSet.getPageSize();
+        int maxRows = cachedRowSet.getMaxRows();
+
         ArrayList<CachedRow> data = new ArrayList<CachedRow>();
-        int columnCount = metadata.getColumnCount();        
-        int tempCursor = 0;
-        
-        if (startRow >= 0) {
-            if (rs.getType() == ResultSet.TYPE_FORWARD_ONLY)
-                throw new SQLException();
-            else {
-                rs.beforeFirst();
-                for (int j = 1; j++ < startRow; rs.next())
-                    ;
-            }
-        }
-        
-        while ((rs.next())) {            
+        int columnCount = metadata.getColumnCount();
+
+        while (rs.next()) {
             Object[] columnData = new Object[columnCount];
             for (int i = 0; i < columnCount; i++) {
-                columnData[i] = rs.getObject(i+1);
+                columnData[i] = rs.getObject(i + 1);
+            }
+
+            data.add(new CachedRow(columnData));
+
+            if (maxRows > 0 && maxRows == data.size()) {
+                break;
+            }
+
+            if (pageSize > 0 && data.size() == pageSize) {
+                break;
             }
-            if((pageSize>0)&&(pageSize<++tempCursor)) break;
-            data.add(new CachedRow(columnData));            
-            
+
         }
-        ((CachedRowSetImpl) theCaller).setRows(data, columnCount);
+
+        cachedRowSet.setRows(data, columnCount);
     }
 }