harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r423386 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio/src: main/java/java/nio/ test/java/common/org/apache/harmony/tests/java/nio/
Date Wed, 19 Jul 2006 07:02:20 GMT
Author: pyang
Date: Wed Jul 19 00:02:18 2006
New Revision: 423386

URL: http://svn.apache.org/viewvc?rev=423386&view=rev
Log:
Fix exception compatibility problems of ByteBuffer, CharBuffer and DoubleBuffer, also add
some testcases to enforce it.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/HeapByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/CharBufferTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/DoubleBufferTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedByteBufferTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedCharBufferTest1.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedCharBufferTest2.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ByteBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ByteBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ByteBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ByteBuffer.java
Wed Jul 19 00:02:18 2006
@@ -101,12 +101,10 @@
 	 *                invalid
 	 */
 	public static ByteBuffer wrap(byte[] array, int start, int len) {
-                if (array == null) {
-                        throw new NullPointerException();
-                }
-                if ((start < 0 ) || (len < 0) || ((long)start + (long)len > array.length))
{
-                        throw new IndexOutOfBoundsException();
-                }
+        int length = array.length;
+        if ((start < 0) || (len < 0) || ((long) start + (long) len > length)) {
+            throw new IndexOutOfBoundsException();
+        }
 
 		ByteBuffer buf = BufferFactory.newByteBuffer(array);
 		buf.position = start;
@@ -427,7 +425,8 @@
 	 *                <code>remaining()</code>
 	 */
 	public ByteBuffer get(byte[] dest, int off, int len) {
-        if ((off < 0 ) || (len < 0) || ((long)off + (long)len > dest.length)) {
+        int length = dest.length;
+        if ((off < 0 ) || (len < 0) || ((long)off + (long)len > length)) {
             throw new IndexOutOfBoundsException();
         }
         
@@ -784,7 +783,8 @@
 	 *                If no changes may be made to the contents of this buffer
 	 */
 	public ByteBuffer put(byte[] src, int off, int len) {
-        if ((off < 0 ) || (len < 0) || ((long)off + (long)len > src.length)) {
+        int length = src.length;
+        if ((off < 0 ) || (len < 0) || ((long)off + (long)len > length)) {
             throw new IndexOutOfBoundsException();
         }
         

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharArrayBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharArrayBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharArrayBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharArrayBuffer.java
Wed Jul 19 00:02:18 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -64,7 +64,8 @@
 	}
 
     public final CharBuffer get(char[] dest, int off, int len) {
-        if ((off < 0 ) || (len < 0) || off + len > dest.length) {
+        int length = dest.length;
+        if ((off < 0 ) || (len < 0) || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharBuffer.java
Wed Jul 19 00:02:18 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -91,12 +91,11 @@
 	 *                invalid
 	 */
 	public static CharBuffer wrap(char[] array, int start, int len) {
-                if (array == null) {
-                        throw new NullPointerException();
-                }
-                if ((start < 0 ) || (len < 0) || (long)start + (long)len > array.length)
{
-                        throw new IndexOutOfBoundsException();
-                }
+        int length = array.length;
+        if ((start < 0) || (len < 0)
+                || (long) start + (long) len > length) {
+            throw new IndexOutOfBoundsException();
+        }
 
 		CharBuffer buf = BufferFactory.newCharBuffer(array);
 		buf.position = start;
@@ -382,7 +381,8 @@
 	 *                <code>remaining()</code>
 	 */
 	public CharBuffer get(char[] dest, int off, int len) {
-        if ((off < 0 ) || (len < 0) || (long)off + (long)len > dest.length) {
+        int length = dest.length;
+        if ((off < 0 ) || (len < 0) || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
         
@@ -553,7 +553,8 @@
 	 *                If no changes may be made to the contents of this buffer
 	 */
 	public CharBuffer put(char[] src, int off, int len) {
-        if ((off < 0 ) || (len < 0) || (long)off + (long)len > src.length) {
+        int length = src.length;
+        if ((off < 0 ) || (len < 0) || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
         
@@ -659,10 +660,8 @@
 	 *                If no changes may be made to the contents of this buffer
 	 */
 	public CharBuffer put(String str, int start, int end) {
-        if(str == null){
-            throw new NullPointerException();
-        }
-        if (start < 0 || end < start || end > str.length()) {
+        int length = str.length();
+        if (start < 0 || end < start || end > length) {
             throw new IndexOutOfBoundsException();
         }
         

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/CharSequenceAdapter.java
Wed Jul 19 00:02:18 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -71,7 +71,8 @@
 	}
 
     public final CharBuffer get(char[] dest, int off, int len) {
-        if ((off < 0 ) || (len < 0) || off + len > dest.length) {
+        int length = dest.length;
+        if ((off < 0 ) || (len < 0) || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {
@@ -132,7 +133,8 @@
     }
 
     public CharBuffer put(String src, int start, int end) {
-        if ((start < 0 ) || (end < 0) || start + end > src.length()) {
+        int length = src.length();
+        if ((start < 0 ) || (end < 0) || (long)start + (long)end > length) {
             throw new IndexOutOfBoundsException();
         }
         if(src == null){

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
Wed Jul 19 00:02:18 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -77,7 +77,8 @@
      * @see java.nio.ByteBuffer#get(byte[], int, int)
      */
     public final ByteBuffer get(byte[] dest, int off, int len) {
-        if ((off < 0 ) || (len < 0) || (long)off + (long)len > dest.length) {
+        int length = dest.length;
+        if ((off < 0 ) || (len < 0) || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleArrayBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleArrayBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleArrayBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleArrayBuffer.java
Wed Jul 19 00:02:18 2006
@@ -64,7 +64,8 @@
 	}
 
     public final DoubleBuffer get(double[] dest, int off, int len) {
-        if (off < 0 || len < 0 || off + len < 0 || off + len > dest.length) {
+        int length = dest.length;
+        if (off < 0 || len < 0 || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java
Wed Jul 19 00:02:18 2006
@@ -82,12 +82,10 @@
 	 *                invalid
 	 */
 	public static DoubleBuffer wrap(double[] array, int start, int len) {
-                if (array == null) {
-                        throw new NullPointerException();
-                }
-                if (start < 0 || len < 0 || start + len < 0 || start+ len > array.length)
{
-                        throw new IndexOutOfBoundsException();
-                }
+        int length = array.length;
+        if (start < 0 || len < 0 || (long)start + (long)len > length) {
+            throw new IndexOutOfBoundsException();
+        }
 
 		DoubleBuffer buf = BufferFactory.newDoubleBuffer(array);
 		buf.position = start;
@@ -294,7 +292,8 @@
 	 *                <code>remaining()</code>
 	 */
 	public DoubleBuffer get(double[] dest, int off, int len) {
-        if (off < 0 || len < 0 || off + len < 0 || off + len > dest.length) {
+        int length = dest.length;
+        if (off < 0 || len < 0 || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
         
@@ -452,7 +451,8 @@
 	 *                If no changes may be made to the contents of this buffer
 	 */
 	public DoubleBuffer put(double[] src, int off, int len) {
-        if (off < 0 || len < 0 || off + len < 0 || off + len > src.length) {
+        int length = src.length;
+        if (off < 0 || len < 0 || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
         

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/HeapByteBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/HeapByteBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/HeapByteBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/HeapByteBuffer.java
Wed Jul 19 00:02:18 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -63,7 +63,8 @@
      * @see java.nio.ByteBuffer#get(byte[], int, int)
      */
     public final ByteBuffer get(byte[] dest, int off, int len) {
-        if (off < 0 || len < 0 || off + len > dest.length) {
+        int length = dest.length;
+        if (off < 0 || len < 0 || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
Wed Jul 19 00:02:18 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -89,7 +89,7 @@
     }
 
     public CharBuffer put(String src, int start, int end) {
-        if ((start < 0 ) || (end < 0) || start + end > src.length()) {
+        if ((start < 0 ) || (end < 0) || (long)start + (long)end > src.length())
{
             throw new IndexOutOfBoundsException();
         }
         if(src == null){

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java
Wed Jul 19 00:02:18 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -118,6 +118,10 @@
 	public ByteBuffer putShort(short value) {
 		throw new ReadOnlyBufferException();
 	}
+    
+    public ByteBuffer put(ByteBuffer buf) {
+        throw new ReadOnlyBufferException();
+    }
 
 	public ByteBuffer slice() {
 		ReadOnlyDirectByteBuffer buf = new ReadOnlyDirectByteBuffer(

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java
Wed Jul 19 00:02:18 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -121,9 +121,13 @@
 		throw new ReadOnlyBufferException();
 	}
 
-	public ByteBuffer putShort(short value) {
-		throw new ReadOnlyBufferException();
-	}
+    public ByteBuffer putShort(short value) {
+        throw new ReadOnlyBufferException();
+    }
+    
+    public ByteBuffer put(ByteBuffer buf) {
+        throw new ReadOnlyBufferException();
+    }
 
 	public ByteBuffer slice() {
 		ReadOnlyHeapByteBuffer slice = new ReadOnlyHeapByteBuffer(backingArray,

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java
Wed Jul 19 00:02:18 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -101,7 +101,8 @@
 	}
 
     public CharBuffer put(char[] src, int off, int len) {
-        if (off < 0 || len < 0 || (long)len + (long)off > src.length) {
+        int length = src.length;
+        if (off < 0 || len < 0 || (long)len + (long)off > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java
Wed Jul 19 00:02:18 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -101,7 +101,8 @@
      * @see java.nio.ByteBuffer#put(byte[], int, int)
      */
     public ByteBuffer put(byte[] src, int off, int len) {
-        if (off < 0 || len < 0 || (long)off + (long)len > src.length) {
+        int length = src.length;
+        if (off < 0 || len < 0 || (long)off + (long)len > length) {
             throw new IndexOutOfBoundsException();
         }
         if (len > remaining()) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java
Wed Jul 19 00:02:18 2006
@@ -104,7 +104,8 @@
 	}
 
     public DoubleBuffer put(double[] src, int off, int len) {
-        if (off < 0 || len < 0 || (long)off + (long)len > src.length) {
+        int length = src.length;
+        if (off < 0 || len < 0 || (long)off + (long)len > length) {
 			throw new IndexOutOfBoundsException();
 		}
         if (len > remaining()) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java
Wed Jul 19 00:02:18 2006
@@ -326,6 +326,12 @@
         } catch (BufferUnderflowException e) {
             // expected
         }
+        try {
+            buf.get((byte[])null);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
     }
 
     /*
@@ -368,6 +374,24 @@
         } catch (IndexOutOfBoundsException e) {
             // expected
         }
+        try {
+            buf.get((byte[])null, -1, 0);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+        try {
+            buf.get(array, 1, Integer.MAX_VALUE);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            buf.get(array, Integer.MAX_VALUE, 1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
         assertEquals(buf.position(), 0);
 
         buf.clear();
@@ -530,6 +554,12 @@
         } catch (BufferOverflowException e) {
             // expected
         }
+        try {
+            buf.put((byte[])null);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
     }
 
     /*
@@ -588,6 +618,18 @@
         } catch (IndexOutOfBoundsException e) {
             // expected
         }
+        try {
+            buf.put(array, Integer.MAX_VALUE, 1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            buf.put((byte[])null, 2, Integer.MAX_VALUE);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
         
         assertEquals(buf.position(), 0);
 
@@ -611,6 +653,13 @@
             } catch (ReadOnlyBufferException e) {
                 // expected
             }
+            try {
+                buf.clear();
+                buf.put((ByteBuffer)null);
+                fail("Should throw Exception"); //$NON-NLS-1$
+            } catch (ReadOnlyBufferException e) {
+                // expected
+            }
             return;
         }
 
@@ -626,7 +675,13 @@
         } catch (BufferOverflowException e) {
             // expected
         }
-
+        
+        try {
+            buf.put((ByteBuffer)null);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
         loadTestData2(other);
         other.clear();
         buf.clear();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/CharBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/CharBufferTest.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/CharBufferTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/CharBufferTest.java
Wed Jul 19 00:02:18 2006
@@ -20,6 +20,7 @@
 import java.nio.BufferUnderflowException;
 import java.nio.ByteOrder;
 import java.nio.CharBuffer;
+import java.nio.FloatBuffer;
 import java.nio.InvalidMarkException;
 import java.nio.ReadOnlyBufferException;
 
@@ -364,12 +365,30 @@
 		} catch (IndexOutOfBoundsException e) {
 			// expected
 		}
-		try {
-			buf.get(array, 2, array.length);
-			fail("Should throw Exception"); //$NON-NLS-1$
-		} catch (IndexOutOfBoundsException e) {
-			// expected
-		}
+        try {
+            buf.get((char[])null, 2, -1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+        try {
+            buf.get(array, 2, array.length);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            buf.get(array, 1, Integer.MAX_VALUE);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            buf.get(array, Integer.MAX_VALUE, 1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
 		assertEquals(buf.position(), 0);
 
 		buf.clear();
@@ -499,12 +518,30 @@
 		} catch (IndexOutOfBoundsException e) {
 			// expected
 		}
-		try {
-			buf.put(array, 2, array.length);
-			fail("Should throw Exception"); //$NON-NLS-1$
-		} catch (IndexOutOfBoundsException e) {
-			// expected
-		}
+        try {
+            buf.put((char[])null, 0, -1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+        try {
+            buf.put(array, 2, array.length);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            buf.put(array, Integer.MAX_VALUE, 1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            buf.put(array, 1, Integer.MAX_VALUE);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
 		assertEquals(buf.position(), 0);
 
 		loadTestData2(array, 0, array.length);
@@ -538,6 +575,13 @@
 		} catch (BufferOverflowException e) {
 			// expected
 		}
+        try {
+            buf.flip();
+            buf.put((CharBuffer)null);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
 
 		loadTestData2(other);
 		other.clear();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/DoubleBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/DoubleBufferTest.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/DoubleBufferTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/DoubleBufferTest.java
Wed Jul 19 00:02:18 2006
@@ -322,6 +322,12 @@
             // expected
         }
         try {
+            buf.get((double[])null, 0, -1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+        try {
             buf.get(array, 2, array.length);
             fail("Should throw Exception"); //$NON-NLS-1$
         } catch (IndexOutOfBoundsException e) {
@@ -468,6 +474,12 @@
             buf.put(array, 0, -1);
             fail("Should throw Exception"); //$NON-NLS-1$
         } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            buf.put((double[])null, 0, -1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
             // expected
         }
         try {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedByteBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedByteBufferTest.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedByteBufferTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedByteBufferTest.java
Wed Jul 19 00:02:18 2006
@@ -61,6 +61,24 @@
         } catch (IndexOutOfBoundsException e) {
             // expected
         }
+        try {
+            ByteBuffer.wrap(array, 1, Integer.MAX_VALUE);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            ByteBuffer.wrap(array, Integer.MAX_VALUE, 1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            ByteBuffer.wrap((byte[])null, 1, Integer.MAX_VALUE);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
     }
     
     public void testIsDirect() {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedCharBufferTest1.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedCharBufferTest1.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedCharBufferTest1.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedCharBufferTest1.java
Wed Jul 19 00:02:18 2006
@@ -62,5 +62,22 @@
         } catch (IndexOutOfBoundsException e) {
             // expected
         }
+        try {
+            CharBuffer.wrap(array, Integer.MAX_VALUE, 1);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            CharBuffer.wrap(array, 1, Integer.MAX_VALUE);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            CharBuffer.wrap((char[])null, -1, 0);
+            fail("Should throw NPE"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+        }
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedCharBufferTest2.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedCharBufferTest2.java?rev=423386&r1=423385&r2=423386&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedCharBufferTest2.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/WrappedCharBufferTest2.java
Wed Jul 19 00:02:18 2006
@@ -60,6 +60,12 @@
         } catch (IndexOutOfBoundsException e) {
             // expected
         }
+        try {
+            CharBuffer.wrap((String)null, -1, 21);
+            fail("Should throw Exception"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
     }
     
     public void testArray() {



Mime
View raw message