harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r812158 - in /harmony/enhanced/classlib/trunk/modules/nio/src/main/java: common/java/nio/channels/Channels.java common/org/apache/harmony/nio/internal/nls/messages.properties unix/org/apache/harmony/nio/internal/EpollSelectorImpl.java
Date Mon, 07 Sep 2009 14:36:07 GMT
Author: tellison
Date: Mon Sep  7 14:36:07 2009
New Revision: 812158

URL: http://svn.apache.org/viewvc?rev=812158&view=rev
Log:
Part of HARMONY-6336 (ArrayIndexOutOfBoundsException thrown without index information; generally
AIOBE is thrown without specifying the index)
Enhance exception messages for NIO module.

Modified:
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/channels/Channels.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/unix/org/apache/harmony/nio/internal/EpollSelectorImpl.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/channels/Channels.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/channels/Channels.java?rev=812158&r1=812157&r2=812158&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/channels/Channels.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/channels/Channels.java
Mon Sep  7 14:36:07 2009
@@ -28,7 +28,9 @@
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CharsetEncoder;
+
 import org.apache.harmony.nio.internal.IOUtil;
+import org.apache.harmony.nio.internal.nls.Messages;
 
 /**
  * This class provides several utilities to get I/O streams from channels.
@@ -242,8 +244,13 @@
         public synchronized int read(byte[] target, int offset, int length)
                 throws IOException {
             // avoid int overflow, check null target
-            if (length + offset > target.length || length < 0 || offset < 0) {
-                throw new ArrayIndexOutOfBoundsException();
+            if (offset > target.length || offset < 0) {
+                // nio.0C=Offset out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Messages.getString("nio.0C", offset));
//$NON-NLS-1$
+            }
+            if (length < 0 || offset > target.length - length) {
+                // nio.0D=Length out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Messages.getString("nio.0D", length));
//$NON-NLS-1$
             }
             if (0 == length) {
                 return 0;
@@ -271,9 +278,15 @@
         @Override
         public synchronized int read(byte[] target, int offset, int length)
                 throws IOException {
-            // avoid int overflow, check null target
-            if (length + offset > target.length || length < 0 || offset < 0) {
-                throw new ArrayIndexOutOfBoundsException();
+            // Force null target check first!
+            if (offset > target.length || offset < 0) {
+                // nio.0C=Offset out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Messages.getString("nio.0C", offset));
//$NON-NLS-1$
+            }
+            
+            if (length < 0 || length > target.length - offset) {
+                // nio.0D=Length out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Messages.getString("nio.0D", length));
//$NON-NLS-1$
             }
             if (0 == length) {
                 return 0;
@@ -306,8 +319,13 @@
         public synchronized void write(byte[] source, int offset, int length)
                 throws IOException {
             // avoid int overflow, check null source
-            if (length + offset > source.length || length < 0 || offset < 0) {
-                throw new ArrayIndexOutOfBoundsException();
+            if (offset > source.length || offset < 0) {
+                // nio.0C=Offset out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Messages.getString("nio.0C", offset));
//$NON-NLS-1$
+            }
+            if (length < 0 || offset > source.length - length) {
+                // nio.0D=Length out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Messages.getString("nio.0D", length));
//$NON-NLS-1$
             }
             if (0 == length) {
                 return;

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/nls/messages.properties?rev=812158&r1=812157&r2=812158&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/nls/messages.properties
Mon Sep  7 14:36:07 2009
@@ -26,3 +26,5 @@
 nio.09=Unknown file channel type: {0}
 nio.0A=Lock position and size must be non-negative.
 nio.0B=New position must be non-negative.
+nio.0C=Offset out of bounds \: {0}
+nio.0D=Length out of bounds \: {0}

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/unix/org/apache/harmony/nio/internal/EpollSelectorImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/unix/org/apache/harmony/nio/internal/EpollSelectorImpl.java?rev=812158&r1=812157&r2=812158&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/unix/org/apache/harmony/nio/internal/EpollSelectorImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/unix/org/apache/harmony/nio/internal/EpollSelectorImpl.java
Mon Sep  7 14:36:07 2009
@@ -539,7 +539,7 @@
                 }
             }
 
-            throw new ArrayIndexOutOfBoundsException();
+            throw new ArrayIndexOutOfBoundsException(key);
         }
 
         private E putEntry(int key, Entry<E> entry) {



Mime
View raw message