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 2009/09/07 12:58:13 UTC
svn commit: r812076 - in
/harmony/enhanced/classlib/trunk/modules/luni/src/main/java: java/lang/
java/util/ org/apache/harmony/luni/internal/net/www/protocol/http/
org/apache/harmony/luni/internal/process/ org/apache/harmony/luni/util/
Author: tellison
Date: Mon Sep 7 10:58:13 2009
New Revision: 812076
URL: http://svn.apache.org/viewvc?rev=812076&view=rev
Log:
Part of HARMONY-6336 (ArrayIndexOutOfBoundsException thrown without index information; generally AIOBE is thrown without specifying the index)
Enhance more exception messages in LUNI module.
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/process/ProcessInputStream.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java?rev=812076&r1=812075&r2=812076&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java Mon Sep 7 10:58:13 2009
@@ -44,6 +44,7 @@
* the invalid index.
*/
public ArrayIndexOutOfBoundsException(int index) {
+ // K0052=Array index out of range\: {0}
super(Msg.getString("K0052", index)); //$NON-NLS-1$
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java?rev=812076&r1=812075&r2=812076&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java Mon Sep 7 10:58:13 2009
@@ -23,6 +23,7 @@
import java.lang.reflect.Array;
import org.apache.harmony.luni.internal.nls.Messages;
+import org.apache.harmony.luni.util.Msg;
/**
* {@code Collections} contains static methods which operate on
@@ -1588,7 +1589,8 @@
public static <T> void copy(List<? super T> destination,
List<? extends T> source) {
if (destination.size() < source.size()) {
- throw new ArrayIndexOutOfBoundsException();
+ // K0032=Source size {0} does not fit into destination
+ throw new ArrayIndexOutOfBoundsException(Msg.getString("K0032", source.size())); //$NON-NLS-1$
}
Iterator<? extends T> srcIt = source.iterator();
ListIterator<? super T> destIt = destination.listIterator();
@@ -1596,7 +1598,8 @@
try {
destIt.next();
} catch (NoSuchElementException e) {
- throw new ArrayIndexOutOfBoundsException();
+ // K0032=Source size {0} does not fit into destination
+ throw new ArrayIndexOutOfBoundsException(Msg.getString("K0032", source.size())); //$NON-NLS-1$
}
destIt.set(srcIt.next());
}
Modified: harmony/enhanced/classlib/trunk/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/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java?rev=812076&r1=812075&r2=812076&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java Mon Sep 7 10:58:13 2009
@@ -172,13 +172,14 @@
@Override
public int read(byte[] buf, int offset, int length) throws IOException {
- if (buf == null) {
- throw new NullPointerException();
- }
- // avoid int overflow
- if (offset < 0 || length < 0 || offset > buf.length
- || buf.length - offset < length) {
- throw new ArrayIndexOutOfBoundsException();
+ // Force buf null check first, and avoid int overflow
+ if (offset < 0 || offset > buf.length) {
+ // K002e=Offset out of bounds \: {0}
+ throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
+ }
+ if (length < 0 || buf.length - offset < length) {
+ // K0031=Length out of bounds \: {0}
+ throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
}
if (bytesRemaining <= 0) {
disconnect(false);
@@ -292,13 +293,14 @@
@Override
public int read(byte[] buf, int offset, int length) throws IOException {
- if (buf == null) {
- throw new NullPointerException();
- }
- // avoid int overflow
- if (offset < 0 || length < 0 || offset > buf.length
- || buf.length - offset < length) {
- throw new ArrayIndexOutOfBoundsException();
+ // Force buf null check first, and avoid int overflow
+ if (offset > buf.length || offset < 0) {
+ // K002e=Offset out of bounds \: {0}
+ throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
+ }
+ if (length < 0 || buf.length - offset < length) {
+ // K0031=Length out of bounds \: {0}
+ throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
}
if (bytesRemaining <= 0) {
readChunkSize();
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/process/ProcessInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/process/ProcessInputStream.java?rev=812076&r1=812075&r2=812076&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/process/ProcessInputStream.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/process/ProcessInputStream.java Mon Sep 7 10:58:13 2009
@@ -20,6 +20,8 @@
import java.io.FileDescriptor;
import java.io.IOException;
+import org.apache.harmony.luni.util.Msg;
+
class ProcessInputStream extends java.io.InputStream {
private long handle;
@@ -120,10 +122,13 @@
if (handle == -1) {
return -1;
}
- if ((nbytes < 0 || nbytes > buffer.length)
- || (offset < 0 || offset > buffer.length)
- || ((nbytes + offset) > buffer.length)) {
- throw new ArrayIndexOutOfBoundsException();
+ if (nbytes > buffer.length || nbytes < 0) {
+ // K0031=Length out of bounds \: {0}
+ throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", nbytes)); //$NON-NLS-1$
+ }
+ if (offset < 0 || offset > buffer.length - nbytes) {
+ // K002e=Offset out of bounds \: {0}
+ throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
}
return readImpl(buffer, offset, nbytes, handle);
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties?rev=812076&r1=812075&r2=812076&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties Mon Sep 7 10:58:13 2009
@@ -324,4 +324,5 @@
KA028=Cannot set protocol version when stream in use
KA029=Can't find resource for bundle {0}, key {1}
KA030=Write end dead
-K0031=Length out of bounds \: {0}
\ No newline at end of file
+K0031=Length out of bounds \: {0}
+K0032=Source size {0} does not fit into destination