harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r489340 - in /harmony/enhanced/classlib/trunk/modules/rmi/src: main/java/java/rmi/server/LogStream.java test/api/java/org/apache/harmony/rmi/server/LogStreamTest.java
Date Thu, 21 Dec 2006 12:44:35 GMT
Author: apetrenko
Date: Thu Dec 21 04:44:35 2006
New Revision: 489340

URL: http://svn.apache.org/viewvc?view=rev&rev=489340
Log:
Patch for HARMONY-1691 "[claaslib][rmi]java.rmi.server.LogStream.write(byte[], int,int) does
not throw IndexOutOfBoundsException in case of boundary violation"

Modified:
    harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/java/rmi/server/LogStream.java
    harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/LogStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/java/rmi/server/LogStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/java/rmi/server/LogStream.java?view=diff&rev=489340&r1=489339&r2=489340
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/java/rmi/server/LogStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/java/rmi/server/LogStream.java
Thu Dec 21 04:44:35 2006
@@ -94,6 +94,10 @@
      */
     @Deprecated
     public void write(byte[] b, int off, int len) {
+        if (len < 0) {
+            throw new ArrayIndexOutOfBoundsException("len < 0: " + len); //$NON-NLS-1$
+        }
+
         for (int i = 0; i < len; ++i) {
             write(b[off + i]);
         }

Modified: harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/LogStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/LogStreamTest.java?view=diff&rev=489340&r1=489339&r2=489340
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/LogStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/LogStreamTest.java
Thu Dec 21 04:44:35 2006
@@ -17,6 +17,8 @@
  */
 package org.apache.harmony.rmi.server;
 
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
 import java.rmi.server.LogStream;
 import junit.framework.TestCase;
 
@@ -42,5 +44,43 @@
             // expected
         }
     }
-    
+
+    /**
+     * Test for java.rmi.server.LogStream.write(byte[], int, int)
+     * testing invalid offsets/lengths. 
+     */
+    public void testWriteArrInvalidOffLen() throws Exception {
+        // Regression test for HARMONY-1691
+        // list of invalid offsets/lengths pairs
+        int[][] invalidPairs = new int[][] {
+            { -2, 1 },
+            { 0, -6 },
+            { 6, 1 },
+            { 0, 6 } };
+
+        // store original default stream for LogStream
+        PrintStream prevOut = LogStream.getDefaultStream();
+
+        try {
+            // set empty default stream to not print garbage to System.out/err
+            LogStream.setDefaultStream(
+                    new PrintStream(new ByteArrayOutputStream()));
+            LogStream ls = LogStream.log("test");
+
+            for (int i = 0; i < invalidPairs.length; ++i) {
+                try {
+                    ls.write(new byte[] { 1, 1 },
+                            invalidPairs[i][0], invalidPairs[i][1]);
+                    fail("IndexOutOfBoundsException "
+                            + "is not thrown when off = " + invalidPairs[i][0]
+                            + ", len = " + invalidPairs[i][1]);
+                } catch (IndexOutOfBoundsException e) {
+                    //expected
+                }
+            }
+        } finally {
+            // restore original stream
+            LogStream.setDefaultStream(prevOut);
+        }
+    }
 }



Mime
View raw message