harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r548269 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/serial/SerialClob.java test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java
Date Mon, 18 Jun 2007 09:13:09 GMT
Author: tonywu
Date: Mon Jun 18 02:13:07 2007
New Revision: 548269

URL: http://svn.apache.org/viewvc?view=rev&rev=548269
Log:
Apply patch HARMONY-4208 ([classlib][sql] javax.sql.rowset.serial.SerialClob.getSubString
throws StringIndexOutOfBoundsException when the length value is overflow
)

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java?view=diff&rev=548269&r1=548268&r2=548269
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java
Mon Jun 18 02:13:07 2007
@@ -98,13 +98,18 @@
     }
 
     public String getSubString(long pos, int length) throws SerialException {
+        checkValidation();
         if (pos < 1 || pos > len) {
             throw new SerialException(Messages.getString("sql.21")); // $NON-NLS-1$
         }
-        if (length < 0 || length > len) {
+        if (length < 0 || pos + length > len + 1) {
             throw new SerialException(Messages.getString("sql.22")); // $NON-NLS-1$
         }
-        return new String(buf, (int) (pos - 1), length);
+        try {
+            return new String(buf, (int) (pos - 1), length);
+        } catch (StringIndexOutOfBoundsException e) {
+            throw new SerialException();
+        }
     }
 
     public long position(Clob searchClob, long start) throws SerialException,
@@ -184,5 +189,11 @@
         System.arraycopy(buf, 0, truncatedBuffer, 0, (int)length);
         buf = truncatedBuffer;
         len = length;   
+    }
+    
+    private void checkValidation() throws SerialException {
+        if(len == -1){
+            throw new SerialException(Messages.getString("sql.38")); //$NON-NLS-1$
+        }
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java?view=diff&rev=548269&r1=548268&r2=548269
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java
Mon Jun 18 02:13:07 2007
@@ -33,6 +33,8 @@
 import javax.sql.rowset.serial.SerialClob;
 import javax.sql.rowset.serial.SerialException;
 
+import org.apache.harmony.sql.tests.javax.sql.rowset.MockClob;
+
 import junit.framework.TestCase;
 
 public class SerialClobTest extends TestCase {
@@ -177,6 +179,22 @@
         } catch (SerialException e) {
             // expected
         }
+        try {
+            sub = serialClob.getSubString(3, 4);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+        
+        LongLengthClob longClob = new LongLengthClob();
+        serialClob = new SerialClob(longClob);
+        
+        try {
+            serialClob.getSubString(1, 3);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
 
     }
 
@@ -390,6 +408,12 @@
             fail("should throw SerialException");
         } catch (SerialException e) {
             // expected
+        }
+    }
+    private static class LongLengthClob extends MockClob {
+        @Override
+        public long length() throws SQLException {
+            return (long)Integer.MAX_VALUE * (long)2 + 4;
         }
     }
 



Mime
View raw message