diff options
author | Elliott Hughes <enh@google.com> | 2012-12-04 14:03:53 -0800 |
---|---|---|
committer | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2013-07-12 00:14:17 +0100 |
commit | a23d6eb8e2c9a09c07224e50b226adb7c14a932f (patch) | |
tree | 828be1b18cf644a76604104bbc593a1036eb86fe | |
parent | f96064dfa4191cf58a7d96326002fc6e3423a123 (diff) | |
download | libcore-a23d6eb8e2c9a09c07224e50b226adb7c14a932f.zip libcore-a23d6eb8e2c9a09c07224e50b226adb7c14a932f.tar.gz libcore-a23d6eb8e2c9a09c07224e50b226adb7c14a932f.tar.bz2 |
Add detail messages to all the easy IllegalArgumentException cases.
Noticed during my recent Matcher change.
Change-Id: I415d911b26d0ee548ca04d56bba7fc3d4e6b3f88
57 files changed, 189 insertions, 193 deletions
diff --git a/luni/src/main/java/java/io/BufferedReader.java b/luni/src/main/java/java/io/BufferedReader.java index 03ecf9f..95a23e9 100644 --- a/luni/src/main/java/java/io/BufferedReader.java +++ b/luni/src/main/java/java/io/BufferedReader.java @@ -190,7 +190,7 @@ public class BufferedReader extends Reader { @Override public void mark(int markLimit) throws IOException { if (markLimit < 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("markLimit < 0:" + markLimit); } synchronized (lock) { checkNotClosed(); diff --git a/luni/src/main/java/java/io/StringReader.java b/luni/src/main/java/java/io/StringReader.java index 9f8ff13..5579d62 100644 --- a/luni/src/main/java/java/io/StringReader.java +++ b/luni/src/main/java/java/io/StringReader.java @@ -83,7 +83,7 @@ public class StringReader extends Reader { @Override public void mark(int readLimit) throws IOException { if (readLimit < 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("readLimit < 0: " + readLimit); } synchronized (lock) { diff --git a/luni/src/main/java/java/io/StringWriter.java b/luni/src/main/java/java/io/StringWriter.java index f0b1d18..2946483 100644 --- a/luni/src/main/java/java/io/StringWriter.java +++ b/luni/src/main/java/java/io/StringWriter.java @@ -49,11 +49,11 @@ public class StringWriter extends Writer { * writer. * * @param initialSize - * the intial size of the target string buffer. + * the initial size of the target string buffer. */ public StringWriter(int initialSize) { if (initialSize < 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("initialSize < 0: " + initialSize); } buf = new StringBuffer(initialSize); lock = buf; diff --git a/luni/src/main/java/java/lang/System.java b/luni/src/main/java/java/lang/System.java index df84c61..8908f56 100644 --- a/luni/src/main/java/java/lang/System.java +++ b/luni/src/main/java/java/lang/System.java @@ -409,58 +409,44 @@ public final class System { /** * Returns the value of a particular system property. The {@code * defaultValue} will be returned if no such property has been found. - * - * @param prop - * the name of the system property to look up. - * @param defaultValue - * the return value if the system property with the given name - * does not exist. - * @return the value of the specified system property or the {@code - * defaultValue} if the property does not exist. - */ - public static String getProperty(String prop, String defaultValue) { - if (prop.isEmpty()) { - throw new IllegalArgumentException(); - } - return getProperties().getProperty(prop, defaultValue); + */ + public static String getProperty(String name, String defaultValue) { + checkPropertyName(name); + return getProperties().getProperty(name, defaultValue); } /** * Sets the value of a particular system property. * - * @param prop - * the name of the system property to be changed. - * @param value - * the value to associate with the given property {@code prop}. * @return the old value of the property or {@code null} if the property * didn't exist. */ - public static String setProperty(String prop, String value) { - if (prop.isEmpty()) { - throw new IllegalArgumentException(); - } - return (String) getProperties().setProperty(prop, value); + public static String setProperty(String name, String value) { + checkPropertyName(name); + return (String) getProperties().setProperty(name, value); } /** * Removes a specific system property. * - * @param key - * the name of the system property to be removed. * @return the property value or {@code null} if the property didn't exist. * @throws NullPointerException - * if the argument {@code key} is {@code null}. + * if the argument is {@code null}. * @throws IllegalArgumentException - * if the argument {@code key} is empty. + * if the argument is empty. */ - public static String clearProperty(String key) { - if (key == null) { - throw new NullPointerException("key == null"); + public static String clearProperty(String name) { + checkPropertyName(name); + return (String) getProperties().remove(name); + } + + private static void checkPropertyName(String name) { + if (name == null) { + throw new NullPointerException("name == null"); } - if (key.isEmpty()) { - throw new IllegalArgumentException(); + if (name.isEmpty()) { + throw new IllegalArgumentException("name is empty"); } - return (String) getProperties().remove(key); } /** diff --git a/luni/src/main/java/java/lang/Thread.java b/luni/src/main/java/java/lang/Thread.java index 210b90c..5e98430 100644 --- a/luni/src/main/java/java/lang/Thread.java +++ b/luni/src/main/java/java/lang/Thread.java @@ -792,7 +792,7 @@ public class Thread implements Runnable { */ public final void join(long millis, int nanos) throws InterruptedException { if (millis < 0 || nanos < 0 || nanos >= NANOS_PER_MILLI) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("bad timeout: millis=" + millis + ",nanos=" + nanos); } // avoid overflow: if total > 292,277 years, just wait forever diff --git a/luni/src/main/java/java/net/DatagramSocket.java b/luni/src/main/java/java/net/DatagramSocket.java index c01f3af..790ebc9 100644 --- a/luni/src/main/java/java/net/DatagramSocket.java +++ b/luni/src/main/java/java/net/DatagramSocket.java @@ -614,7 +614,7 @@ public class DatagramSocket { public void setTrafficClass(int value) throws SocketException { checkOpen(); if (value < 0 || value > 255) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Value doesn't fit in an unsigned byte: " + value); } impl.setOption(SocketOptions.IP_TOS, Integer.valueOf(value)); } diff --git a/luni/src/main/java/java/net/HttpCookie.java b/luni/src/main/java/java/net/HttpCookie.java index 057afef..ce1a8d2 100644 --- a/luni/src/main/java/java/net/HttpCookie.java +++ b/luni/src/main/java/java/net/HttpCookie.java @@ -445,7 +445,7 @@ public final class HttpCookie implements Cloneable { public HttpCookie(String name, String value) { String ntrim = name.trim(); // erase leading and trailing whitespace if (!isValidName(ntrim)) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Invalid name: " + name); } this.name = ntrim; @@ -650,11 +650,11 @@ public final class HttpCookie implements Cloneable { * * @throws IllegalArgumentException if v is neither 0 nor 1 */ - public void setVersion(int v) { - if (v != 0 && v != 1) { - throw new IllegalArgumentException(); + public void setVersion(int newVersion) { + if (newVersion != 0 && newVersion != 1) { + throw new IllegalArgumentException("Bad version: " + newVersion); } - version = v; + version = newVersion; } @Override public Object clone() { diff --git a/luni/src/main/java/java/net/Socket.java b/luni/src/main/java/java/net/Socket.java index 7661f28..a9e0bc3 100644 --- a/luni/src/main/java/java/net/Socket.java +++ b/luni/src/main/java/java/net/Socket.java @@ -909,7 +909,7 @@ public class Socket { public void setTrafficClass(int value) throws SocketException { checkOpenAndCreate(true); if (value < 0 || value > 255) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Value doesn't fit in an unsigned byte: " + value); } impl.setOption(SocketOptions.IP_TOS, Integer.valueOf(value)); } diff --git a/luni/src/main/java/java/net/URISyntaxException.java b/luni/src/main/java/java/net/URISyntaxException.java index 957ea31..70fe6a1 100644 --- a/luni/src/main/java/java/net/URISyntaxException.java +++ b/luni/src/main/java/java/net/URISyntaxException.java @@ -56,7 +56,7 @@ public class URISyntaxException extends Exception { } if (index < -1) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad index: " + index); } this.input = input; diff --git a/luni/src/main/java/java/nio/DatagramChannelImpl.java b/luni/src/main/java/java/nio/DatagramChannelImpl.java index 4d2fc5a..a23010e 100644 --- a/luni/src/main/java/java/nio/DatagramChannelImpl.java +++ b/luni/src/main/java/java/nio/DatagramChannelImpl.java @@ -253,7 +253,8 @@ class DatagramChannelImpl extends DatagramChannel implements FileDescriptorChann } if (isConnected() && !connectAddress.equals(isa)) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Connected to " + connectAddress + + ", not " + socketAddress); } synchronized (writeLock) { diff --git a/luni/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java b/luni/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java index ab76e8e..04b4730 100644 --- a/luni/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java +++ b/luni/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java @@ -130,7 +130,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel { throw new ClosedChannelException(); } if (!((interestSet & ~validOps()) == 0)) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("no valid ops in interest set: " + interestSet); } synchronized (blockingLock) { diff --git a/luni/src/main/java/java/security/AlgorithmParameterGenerator.java b/luni/src/main/java/java/security/AlgorithmParameterGenerator.java index 3edc167..61548d7 100644 --- a/luni/src/main/java/java/security/AlgorithmParameterGenerator.java +++ b/luni/src/main/java/java/security/AlgorithmParameterGenerator.java @@ -146,7 +146,7 @@ public class AlgorithmParameterGenerator { public static AlgorithmParameterGenerator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { if (provider == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("provider == null"); } if (algorithm == null) { throw new NullPointerException("algorithm == null"); diff --git a/luni/src/main/java/java/security/KeyFactory.java b/luni/src/main/java/java/security/KeyFactory.java index 8d39003..3bd05b9 100644 --- a/luni/src/main/java/java/security/KeyFactory.java +++ b/luni/src/main/java/java/security/KeyFactory.java @@ -127,7 +127,7 @@ public class KeyFactory { public static KeyFactory getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { if (provider == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("provider == null"); } if (algorithm == null) { throw new NullPointerException("algorithm == null"); diff --git a/luni/src/main/java/java/security/KeyPairGenerator.java b/luni/src/main/java/java/security/KeyPairGenerator.java index 5c17d79..8a713d0 100644 --- a/luni/src/main/java/java/security/KeyPairGenerator.java +++ b/luni/src/main/java/java/security/KeyPairGenerator.java @@ -140,7 +140,7 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi { public static KeyPairGenerator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { if (provider == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("provider == null"); } if (algorithm == null) { throw new NullPointerException("algorithm == null"); diff --git a/luni/src/main/java/java/security/KeyStore.java b/luni/src/main/java/java/security/KeyStore.java index 3d856f7..5b4ff84 100644 --- a/luni/src/main/java/java/security/KeyStore.java +++ b/luni/src/main/java/java/security/KeyStore.java @@ -179,7 +179,7 @@ public class KeyStore { public static KeyStore getInstance(String type, Provider provider) throws KeyStoreException { // check parameters if (provider == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("provider == null"); } if (type == null) { throw new NullPointerException("type == null"); diff --git a/luni/src/main/java/java/security/MessageDigest.java b/luni/src/main/java/java/security/MessageDigest.java index 6f1bf21..658b41f 100644 --- a/luni/src/main/java/java/security/MessageDigest.java +++ b/luni/src/main/java/java/security/MessageDigest.java @@ -149,7 +149,7 @@ public abstract class MessageDigest extends MessageDigestSpi { public static MessageDigest getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { if (provider == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("provider == null"); } if (algorithm == null) { throw new NullPointerException("algorithm == null"); diff --git a/luni/src/main/java/java/security/SecureRandom.java b/luni/src/main/java/java/security/SecureRandom.java index 6ed631c..1b62c35 100644 --- a/luni/src/main/java/java/security/SecureRandom.java +++ b/luni/src/main/java/java/security/SecureRandom.java @@ -209,7 +209,7 @@ public class SecureRandom extends Random { public static SecureRandom getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { if (provider == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("provider == null"); } if (algorithm == null) { throw new NullPointerException("algorithm == null"); diff --git a/luni/src/main/java/java/security/Signature.java b/luni/src/main/java/java/security/Signature.java index be89654..b2bd122 100644 --- a/luni/src/main/java/java/security/Signature.java +++ b/luni/src/main/java/java/security/Signature.java @@ -168,7 +168,7 @@ public abstract class Signature extends SignatureSpi { throw new NullPointerException("algorithm == null"); } if (provider == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("provider == null"); } return getSignatureInstance(algorithm, provider); } diff --git a/luni/src/main/java/java/security/cert/CertPathValidator.java b/luni/src/main/java/java/security/cert/CertPathValidator.java index ddf78bf..b871b71 100644 --- a/luni/src/main/java/java/security/cert/CertPathValidator.java +++ b/luni/src/main/java/java/security/cert/CertPathValidator.java @@ -157,7 +157,7 @@ public class CertPathValidator { public static CertPathValidator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { if (provider == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("provider == null"); } if (algorithm == null) { throw new NullPointerException("algorithm == null"); diff --git a/luni/src/main/java/java/sql/Date.java b/luni/src/main/java/java/sql/Date.java index 2434fbd..34ca5bd 100644 --- a/luni/src/main/java/java/sql/Date.java +++ b/luni/src/main/java/java/sql/Date.java @@ -81,7 +81,7 @@ public class Date extends java.util.Date { @Deprecated @Override public int getHours() { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -94,7 +94,7 @@ public class Date extends java.util.Date { @Deprecated @Override public int getMinutes() { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -107,7 +107,7 @@ public class Date extends java.util.Date { @Deprecated @Override public int getSeconds() { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -121,7 +121,7 @@ public class Date extends java.util.Date { @Deprecated @Override public void setHours(int theHours) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -135,7 +135,7 @@ public class Date extends java.util.Date { @Deprecated @Override public void setMinutes(int theMinutes) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -149,7 +149,7 @@ public class Date extends java.util.Date { @Deprecated @Override public void setSeconds(int theSeconds) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -212,7 +212,7 @@ public class Date extends java.util.Date { */ public static Date valueOf(String dateString) { if (dateString == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("dateString == null"); } int firstIndex = dateString.indexOf('-'); int secondIndex = dateString.indexOf('-', firstIndex + 1); diff --git a/luni/src/main/java/java/sql/Time.java b/luni/src/main/java/java/sql/Time.java index bccce68..913379c 100644 --- a/luni/src/main/java/java/sql/Time.java +++ b/luni/src/main/java/java/sql/Time.java @@ -76,7 +76,7 @@ public class Time extends Date { @Deprecated @Override public int getDate() { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -90,7 +90,7 @@ public class Time extends Date { @Deprecated @Override public int getDay() { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -104,7 +104,7 @@ public class Time extends Date { @Deprecated @Override public int getMonth() { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -118,7 +118,7 @@ public class Time extends Date { @Deprecated @Override public int getYear() { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -131,7 +131,7 @@ public class Time extends Date { @Deprecated @Override public void setDate(int i) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -144,7 +144,7 @@ public class Time extends Date { @Deprecated @Override public void setMonth(int i) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -157,7 +157,7 @@ public class Time extends Date { @Deprecated @Override public void setYear(int i) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("unimplemented"); } /** @@ -223,7 +223,7 @@ public class Time extends Date { */ public static Time valueOf(String timeString) { if (timeString == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("timeString == null"); } int firstIndex = timeString.indexOf(':'); int secondIndex = timeString.indexOf(':', firstIndex + 1); diff --git a/luni/src/main/java/java/sql/Timestamp.java b/luni/src/main/java/java/sql/Timestamp.java index 463ea8b..b9d777f 100644 --- a/luni/src/main/java/java/sql/Timestamp.java +++ b/luni/src/main/java/java/sql/Timestamp.java @@ -82,7 +82,7 @@ public class Timestamp extends Date { throws IllegalArgumentException { super(theYear, theMonth, theDate, theHour, theMinute, theSecond); if (theNano < 0 || theNano > 999999999) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("ns out of range: " + theNano); } nanos = theNano; } diff --git a/luni/src/main/java/java/text/AttributedString.java b/luni/src/main/java/java/text/AttributedString.java index d679283..289ad6d 100644 --- a/luni/src/main/java/java/text/AttributedString.java +++ b/luni/src/main/java/java/text/AttributedString.java @@ -577,8 +577,8 @@ public class AttributedString { if (attribute == null) { throw new NullPointerException("attribute == null"); } - if (text.length() == 0) { - throw new IllegalArgumentException(); + if (text.isEmpty()) { + throw new IllegalArgumentException("text is empty"); } List<Range> ranges = attributeMap.get(attribute); diff --git a/luni/src/main/java/java/text/ChoiceFormat.java b/luni/src/main/java/java/text/ChoiceFormat.java index e0a1239..014b8c7 100644 --- a/luni/src/main/java/java/text/ChoiceFormat.java +++ b/luni/src/main/java/java/text/ChoiceFormat.java @@ -168,10 +168,10 @@ public class ChoiceFormat extends NumberFormat { next = nextDouble(value.doubleValue()); break; default: - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad character '" + ch + "' in template: " + template); } if (limitCount > 0 && next <= limits[limitCount - 1]) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad template: " + template); } buffer.setLength(0); position.setIndex(index); @@ -426,7 +426,8 @@ public class ChoiceFormat extends NumberFormat { */ public void setChoices(double[] limits, String[] formats) { if (limits.length != formats.length) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("limits.length != formats.length: " + + limits.length + " != " + formats.length); } choiceLimits = limits; choiceFormats = formats; diff --git a/luni/src/main/java/java/text/Collator.java b/luni/src/main/java/java/text/Collator.java index 2ddb516..58d7047 100644 --- a/luni/src/main/java/java/text/Collator.java +++ b/luni/src/main/java/java/text/Collator.java @@ -339,7 +339,7 @@ public abstract class Collator implements Comparator<Object>, Cloneable { case Collator.NO_DECOMPOSITION: return RuleBasedCollatorICU.VALUE_OFF; } - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad mode: " + mode); } private int decompositionMode_ICU_Java(int mode) { @@ -366,7 +366,7 @@ public abstract class Collator implements Comparator<Object>, Cloneable { case Collator.IDENTICAL: return RuleBasedCollatorICU.VALUE_IDENTICAL; } - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad strength: " + value); } private int strength_ICU_Java(int value) { diff --git a/luni/src/main/java/java/text/DateFormat.java b/luni/src/main/java/java/text/DateFormat.java index b45e699..5ad4bb5 100644 --- a/luni/src/main/java/java/text/DateFormat.java +++ b/luni/src/main/java/java/text/DateFormat.java @@ -349,16 +349,14 @@ public abstract class DateFormat extends Format { * {@code Number} instance. */ @Override - public final StringBuffer format(Object object, StringBuffer buffer, - FieldPosition field) { + public final StringBuffer format(Object object, StringBuffer buffer, FieldPosition field) { if (object instanceof Date) { return format((Date) object, buffer, field); } if (object instanceof Number) { - return format(new Date(((Number) object).longValue()), buffer, - field); + return format(new Date(((Number) object).longValue()), buffer, field); } - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad class: " + object.getClass()); } /** @@ -369,8 +367,7 @@ public abstract class DateFormat extends Format { * @return the formatted string. */ public final String format(Date date) { - return format(date, new StringBuffer(), new FieldPosition(0)) - .toString(); + return format(date, new StringBuffer(), new FieldPosition(0)).toString(); } /** @@ -391,8 +388,7 @@ public abstract class DateFormat extends Format { * of the alignment field in the formatted text. * @return the string buffer. */ - public abstract StringBuffer format(Date date, StringBuffer buffer, - FieldPosition field); + public abstract StringBuffer format(Date date, StringBuffer buffer, FieldPosition field); /** * Returns an array of locales for which custom {@code DateFormat} instances @@ -874,9 +870,8 @@ public abstract class DateFormat extends Format { */ public static Field ofCalendarField(int calendarField) { if (calendarField < 0 || calendarField >= Calendar.FIELD_COUNT) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Field out of range: " + calendarField); } - return table.get(Integer.valueOf(calendarField)); } } @@ -884,14 +879,14 @@ public abstract class DateFormat extends Format { private static void checkDateStyle(int style) { if (!(style == SHORT || style == MEDIUM || style == LONG || style == FULL || style == DEFAULT)) { - throw new IllegalArgumentException("Illegal date style " + style); + throw new IllegalArgumentException("Illegal date style: " + style); } } private static void checkTimeStyle(int style) { if (!(style == SHORT || style == MEDIUM || style == LONG || style == FULL || style == DEFAULT)) { - throw new IllegalArgumentException("Illegal time style " + style); + throw new IllegalArgumentException("Illegal time style: " + style); } } } diff --git a/luni/src/main/java/java/text/NumberFormat.java b/luni/src/main/java/java/text/NumberFormat.java index c285e3d..36fdd0f 100644 --- a/luni/src/main/java/java/text/NumberFormat.java +++ b/luni/src/main/java/java/text/NumberFormat.java @@ -301,7 +301,7 @@ public abstract class NumberFormat extends Format { double dv = ((Number) object).doubleValue(); return format(dv, buffer, field); } - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad class: " + object.getClass()); } /** diff --git a/luni/src/main/java/java/text/SimpleDateFormat.java b/luni/src/main/java/java/text/SimpleDateFormat.java index f682c0b..cb1b9b9 100644 --- a/luni/src/main/java/java/text/SimpleDateFormat.java +++ b/luni/src/main/java/java/text/SimpleDateFormat.java @@ -476,8 +476,7 @@ public class SimpleDateFormat extends DateFormat { if (object instanceof Number) { return formatToCharacterIteratorImpl(new Date(((Number) object).longValue())); } - throw new IllegalArgumentException(); - + throw new IllegalArgumentException("Bad class: " + object.getClass()); } private AttributedCharacterIterator formatToCharacterIteratorImpl(Date date) { diff --git a/luni/src/main/java/java/util/ArrayList.java b/luni/src/main/java/java/util/ArrayList.java index dc7b198..d193eec 100644 --- a/luni/src/main/java/java/util/ArrayList.java +++ b/luni/src/main/java/java/util/ArrayList.java @@ -70,7 +70,7 @@ public class ArrayList<E> extends AbstractList<E> implements Cloneable, Serializ */ public ArrayList(int capacity) { if (capacity < 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("capacity < 0: " + capacity); } array = (capacity == 0 ? EmptyArray.OBJECT : new Object[capacity]); } diff --git a/luni/src/main/java/java/util/Collections.java b/luni/src/main/java/java/util/Collections.java index d49ca85..0fafcff 100644 --- a/luni/src/main/java/java/util/Collections.java +++ b/luni/src/main/java/java/util/Collections.java @@ -63,7 +63,7 @@ public class Collections { CopiesList(int length, E object) { if (length < 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("length < 0: " + length); } n = length; element = object; @@ -2648,7 +2648,7 @@ public class Collections { if (map.isEmpty()) { return new SetFromMap<E>(map); } - throw new IllegalArgumentException(); + throw new IllegalArgumentException("map not empty"); } /** diff --git a/luni/src/main/java/java/util/Date.java b/luni/src/main/java/java/util/Date.java index 0eab8dc..0e1154c 100644 --- a/luni/src/main/java/java/util/Date.java +++ b/luni/src/main/java/java/util/Date.java @@ -356,6 +356,10 @@ public class Date implements Serializable, Cloneable, Comparable<Date> { return -1; } + private static IllegalArgumentException parseError(String string) { + throw new IllegalArgumentException("Parse error: " + string); + } + /** * Returns the millisecond value of the date and time parsed from the * specified {@code String}. Many date/time formats are recognized, including IETF @@ -406,7 +410,7 @@ public class Date implements Serializable, Cloneable, Comparable<Date> { } else if ('0' <= next && next <= '9') { nextState = NUMBERS; } else if (!Character.isSpace(next) && ",+-:/".indexOf(next) == -1) { - throw new IllegalArgumentException(); + throw parseError(string); } if (state == NUMBERS && nextState != NUMBERS) { @@ -426,7 +430,7 @@ public class Date implements Serializable, Cloneable, Comparable<Date> { zoneOffset = sign == '-' ? -digit : digit; sign = 0; } else { - throw new IllegalArgumentException(); + throw parseError(string); } } else if (digit >= 70) { if (year == -1 @@ -434,7 +438,7 @@ public class Date implements Serializable, Cloneable, Comparable<Date> { || next == '/' || next == '\r')) { year = digit; } else { - throw new IllegalArgumentException(); + throw parseError(string); } } else if (next == ':') { if (hour == -1) { @@ -442,7 +446,7 @@ public class Date implements Serializable, Cloneable, Comparable<Date> { } else if (minute == -1) { minute = digit; } else { - throw new IllegalArgumentException(); + throw parseError(string); } } else if (next == '/') { if (month == -1) { @@ -450,7 +454,7 @@ public class Date implements Serializable, Cloneable, Comparable<Date> { } else if (date == -1) { date = digit; } else { - throw new IllegalArgumentException(); + throw parseError(string); } } else if (Character.isSpace(next) || next == ',' || next == '-' || next == '\r') { @@ -463,30 +467,30 @@ public class Date implements Serializable, Cloneable, Comparable<Date> { } else if (year == -1) { year = digit; } else { - throw new IllegalArgumentException(); + throw parseError(string); } } else if (year == -1 && month != -1 && date != -1) { year = digit; } else { - throw new IllegalArgumentException(); + throw parseError(string); } } else if (state == LETTERS && nextState != LETTERS) { String text = buffer.toString().toUpperCase(Locale.US); buffer.setLength(0); if (text.length() == 1) { - throw new IllegalArgumentException(); + throw parseError(string); } if (text.equals("AM")) { if (hour == 12) { hour = 0; } else if (hour < 1 || hour > 12) { - throw new IllegalArgumentException(); + throw parseError(string); } } else if (text.equals("PM")) { if (hour == 12) { hour = 0; } else if (hour < 1 || hour > 12) { - throw new IllegalArgumentException(); + throw parseError(string); } hour += 12; } else { @@ -503,7 +507,7 @@ public class Date implements Serializable, Cloneable, Comparable<Date> { zone = true; zoneOffset = value; } else { - throw new IllegalArgumentException(); + throw parseError(string); } } } @@ -549,7 +553,7 @@ public class Date implements Serializable, Cloneable, Comparable<Date> { return new Date(year - 1900, month, date, hour, minute, second) .getTime(); } - throw new IllegalArgumentException(); + throw parseError(string); } /** diff --git a/luni/src/main/java/java/util/EnumMap.java b/luni/src/main/java/java/util/EnumMap.java index a721ee3..827fb51 100644 --- a/luni/src/main/java/java/util/EnumMap.java +++ b/luni/src/main/java/java/util/EnumMap.java @@ -436,8 +436,8 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements if (map instanceof EnumMap) { initialization((EnumMap<K, V>) map); } else { - if (map.size() == 0) { - throw new IllegalArgumentException(); + if (map.isEmpty()) { + throw new IllegalArgumentException("map is empty"); } Iterator<K> iter = map.keySet().iterator(); K enumKey = iter.next(); diff --git a/luni/src/main/java/java/util/EnumSet.java b/luni/src/main/java/java/util/EnumSet.java index cc8969e..20be6f7 100644 --- a/luni/src/main/java/java/util/EnumSet.java +++ b/luni/src/main/java/java/util/EnumSet.java @@ -104,7 +104,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E> return copyOf((EnumSet<E>) c); } if (c.isEmpty()) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("empty collection"); } Iterator<E> iterator = c.iterator(); E element = iterator.next(); @@ -284,7 +284,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E> */ public static <E extends Enum<E>> EnumSet<E> range(E start, E end) { if (start.compareTo(end) > 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("start is behind end"); } EnumSet<E> set = EnumSet.noneOf(start.getDeclaringClass()); set.setRange(start, end); diff --git a/luni/src/main/java/java/util/EventObject.java b/luni/src/main/java/java/util/EventObject.java index 058e7e8..0fc92bb 100644 --- a/luni/src/main/java/java/util/EventObject.java +++ b/luni/src/main/java/java/util/EventObject.java @@ -41,7 +41,7 @@ public class EventObject implements Serializable { */ public EventObject(Object source) { if (source == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("source == null"); } this.source = source; } diff --git a/luni/src/main/java/java/util/IdentityHashMap.java b/luni/src/main/java/java/util/IdentityHashMap.java index e693f7d..904eed5 100644 --- a/luni/src/main/java/java/util/IdentityHashMap.java +++ b/luni/src/main/java/java/util/IdentityHashMap.java @@ -261,13 +261,12 @@ public class IdentityHashMap<K, V> extends AbstractMap<K, V> implements * this map. */ public IdentityHashMap(int maxSize) { - if (maxSize >= 0) { - this.size = 0; - threshold = getThreshold(maxSize); - elementData = newElementArray(computeElementArraySize()); - } else { - throw new IllegalArgumentException(); + if (maxSize < 0) { + throw new IllegalArgumentException("maxSize < 0: " + maxSize); } + size = 0; + threshold = getThreshold(maxSize); + elementData = newElementArray(computeElementArraySize()); } private int getThreshold(int maxSize) { diff --git a/luni/src/main/java/java/util/PriorityQueue.java b/luni/src/main/java/java/util/PriorityQueue.java index e09eb05..cc9bfe6 100644 --- a/luni/src/main/java/java/util/PriorityQueue.java +++ b/luni/src/main/java/java/util/PriorityQueue.java @@ -82,7 +82,7 @@ public class PriorityQueue<E> extends AbstractQueue<E> implements Serializable { */ public PriorityQueue(int initialCapacity, Comparator<? super E> comparator) { if (initialCapacity < 1) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("initialCapacity < 1: " + initialCapacity); } elements = newElementArray(initialCapacity); this.comparator = comparator; diff --git a/luni/src/main/java/java/util/Random.java b/luni/src/main/java/java/util/Random.java index b0a92ff..4a67244 100644 --- a/luni/src/main/java/java/util/Random.java +++ b/luni/src/main/java/java/util/Random.java @@ -171,18 +171,18 @@ public class Random implements Serializable { * in the half-open range [0, n). */ public int nextInt(int n) { - if (n > 0) { - if ((n & -n) == n) { - return (int) ((n * (long) next(31)) >> 31); - } - int bits, val; - do { - bits = next(31); - val = bits % n; - } while (bits - val + (n - 1) < 0); - return val; + if (n <= 0) { + throw new IllegalArgumentException("n <= 0: " + n); + } + if ((n & -n) == n) { + return (int) ((n * (long) next(31)) >> 31); } - throw new IllegalArgumentException(); + int bits, val; + do { + bits = next(31); + val = bits % n; + } while (bits - val + (n - 1) < 0); + return val; } /** diff --git a/luni/src/main/java/java/util/SimpleTimeZone.java b/luni/src/main/java/java/util/SimpleTimeZone.java index 93dc88e..0675480 100644 --- a/luni/src/main/java/java/util/SimpleTimeZone.java +++ b/luni/src/main/java/java/util/SimpleTimeZone.java @@ -546,11 +546,10 @@ public class SimpleTimeZone extends TimeZone { * the daylight savings offset in milliseconds. */ public void setDSTSavings(int milliseconds) { - if (milliseconds > 0) { - dstSavings = milliseconds; - } else { - throw new IllegalArgumentException(); + if (milliseconds <= 0) { + throw new IllegalArgumentException("milliseconds <= 0: " + milliseconds); } + dstSavings = milliseconds; } private void checkRange(int month, int dayOfWeek, int time) { diff --git a/luni/src/main/java/java/util/TimeZone.java b/luni/src/main/java/java/util/TimeZone.java index 85011bc..db475e6 100644 --- a/luni/src/main/java/java/util/TimeZone.java +++ b/luni/src/main/java/java/util/TimeZone.java @@ -171,7 +171,7 @@ public abstract class TimeZone implements Serializable, Cloneable { */ public String getDisplayName(boolean daylightTime, int style, Locale locale) { if (style != SHORT && style != LONG) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad style: " + style); } boolean useDaylight = daylightTime && useDaylightTime(); diff --git a/luni/src/main/java/java/util/Timer.java b/luni/src/main/java/java/util/Timer.java index afc745c..25ac432 100644 --- a/luni/src/main/java/java/util/Timer.java +++ b/luni/src/main/java/java/util/Timer.java @@ -433,7 +433,7 @@ public class Timer { */ public void schedule(TimerTask task, Date when) { if (when.getTime() < 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("when < 0: " + when.getTime()); } long delay = when.getTime() - System.currentTimeMillis(); scheduleImpl(task, delay < 0 ? 0 : delay, -1, false); @@ -454,7 +454,7 @@ public class Timer { */ public void schedule(TimerTask task, long delay) { if (delay < 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("delay < 0: " + delay); } scheduleImpl(task, delay, -1, false); } diff --git a/luni/src/main/java/java/util/Vector.java b/luni/src/main/java/java/util/Vector.java index c236be0..1348bcc 100644 --- a/luni/src/main/java/java/util/Vector.java +++ b/luni/src/main/java/java/util/Vector.java @@ -92,7 +92,7 @@ public class Vector<E> extends AbstractList<E> implements List<E>, */ public Vector(int capacity, int capacityIncrement) { if (capacity < 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("capacity < 0: " + capacity); } elementData = newElementArray(capacity); elementCount = 0; diff --git a/luni/src/main/java/java/util/WeakHashMap.java b/luni/src/main/java/java/util/WeakHashMap.java index 6417679..2c07d28 100644 --- a/luni/src/main/java/java/util/WeakHashMap.java +++ b/luni/src/main/java/java/util/WeakHashMap.java @@ -198,15 +198,14 @@ public class WeakHashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> { * if the capacity is less than zero. */ public WeakHashMap(int capacity) { - if (capacity >= 0) { - elementCount = 0; - elementData = newEntryArray(capacity == 0 ? 1 : capacity); - loadFactor = 7500; // Default load factor of 0.75 - computeMaxSize(); - referenceQueue = new ReferenceQueue<K>(); - } else { - throw new IllegalArgumentException(); + if (capacity < 0) { + throw new IllegalArgumentException("capacity < 0: " + capacity); } + elementCount = 0; + elementData = newEntryArray(capacity == 0 ? 1 : capacity); + loadFactor = 7500; // Default load factor of 0.75 + computeMaxSize(); + referenceQueue = new ReferenceQueue<K>(); } /** @@ -222,15 +221,17 @@ public class WeakHashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> { * or equal to zero. */ public WeakHashMap(int capacity, float loadFactor) { - if (capacity >= 0 && loadFactor > 0) { - elementCount = 0; - elementData = newEntryArray(capacity == 0 ? 1 : capacity); - this.loadFactor = (int) (loadFactor * 10000); - computeMaxSize(); - referenceQueue = new ReferenceQueue<K>(); - } else { - throw new IllegalArgumentException(); + if (capacity < 0) { + throw new IllegalArgumentException("capacity < 0: " + capacity); + } + if (loadFactor <= 0) { + throw new IllegalArgumentException("loadFactor <= 0: " + loadFactor); } + elementCount = 0; + elementData = newEntryArray(capacity == 0 ? 1 : capacity); + this.loadFactor = (int) (loadFactor * 10000); + computeMaxSize(); + referenceQueue = new ReferenceQueue<K>(); } /** diff --git a/luni/src/main/java/java/util/regex/Matcher.java b/luni/src/main/java/java/util/regex/Matcher.java index cfd4432..7c12696 100644 --- a/luni/src/main/java/java/util/regex/Matcher.java +++ b/luni/src/main/java/java/util/regex/Matcher.java @@ -194,7 +194,7 @@ public final class Matcher implements MatchResult { */ private Matcher reset(CharSequence input, int start, int end) { if (input == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("input == null"); } if (start < 0 || end < 0 || start > input.length() || end > input.length() || start > end) { @@ -224,7 +224,7 @@ public final class Matcher implements MatchResult { */ public Matcher usePattern(Pattern pattern) { if (pattern == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("pattern == null"); } this.pattern = pattern; diff --git a/luni/src/main/java/java/util/zip/Deflater.java b/luni/src/main/java/java/util/zip/Deflater.java index 044b976..13f53c1 100644 --- a/luni/src/main/java/java/util/zip/Deflater.java +++ b/luni/src/main/java/java/util/zip/Deflater.java @@ -185,7 +185,7 @@ public class Deflater { */ public Deflater(int level, boolean noHeader) { if (level < DEFAULT_COMPRESSION || level > BEST_COMPRESSION) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad level: " + level); } compressLevel = level; streamHandle = createStream(compressLevel, strategy, noHeader); diff --git a/luni/src/main/java/java/util/zip/DeflaterInputStream.java b/luni/src/main/java/java/util/zip/DeflaterInputStream.java index 805ce17..d854fec 100644 --- a/luni/src/main/java/java/util/zip/DeflaterInputStream.java +++ b/luni/src/main/java/java/util/zip/DeflaterInputStream.java @@ -78,7 +78,7 @@ public class DeflaterInputStream extends FilterInputStream { throw new NullPointerException("deflater == null"); } if (bufferSize <= 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("bufferSize <= 0: " + bufferSize); } this.def = deflater; this.buf = new byte[bufferSize]; diff --git a/luni/src/main/java/java/util/zip/DeflaterOutputStream.java b/luni/src/main/java/java/util/zip/DeflaterOutputStream.java index d336e72..448f61c 100644 --- a/luni/src/main/java/java/util/zip/DeflaterOutputStream.java +++ b/luni/src/main/java/java/util/zip/DeflaterOutputStream.java @@ -86,11 +86,11 @@ public class DeflaterOutputStream extends FilterOutputStream { * @param def * is the specific {@code Deflater} that will be used to compress * data. - * @param bsize + * @param bufferSize * is the size to be used for the internal buffer. */ - public DeflaterOutputStream(OutputStream os, Deflater def, int bsize) { - this(os, def, bsize, false); + public DeflaterOutputStream(OutputStream os, Deflater def, int bufferSize) { + this(os, def, bufferSize, false); } /** @@ -113,19 +113,19 @@ public class DeflaterOutputStream extends FilterOutputStream { * @hide * @since 1.7 */ - public DeflaterOutputStream(OutputStream os, Deflater def, int bsize, boolean syncFlush) { + public DeflaterOutputStream(OutputStream os, Deflater def, int bufferSize, boolean syncFlush) { super(os); if (os == null) { throw new NullPointerException("os == null"); } else if (def == null) { throw new NullPointerException("def == null"); } - if (bsize <= 0) { - throw new IllegalArgumentException(); + if (bufferSize <= 0) { + throw new IllegalArgumentException("bufferSize <= 0: " + bufferSize); } this.def = def; this.syncFlush = syncFlush; - buf = new byte[bsize]; + buf = new byte[bufferSize]; } /** diff --git a/luni/src/main/java/java/util/zip/InflaterInputStream.java b/luni/src/main/java/java/util/zip/InflaterInputStream.java index 6081037..397637e 100644 --- a/luni/src/main/java/java/util/zip/InflaterInputStream.java +++ b/luni/src/main/java/java/util/zip/InflaterInputStream.java @@ -98,24 +98,24 @@ public class InflaterInputStream extends FilterInputStream { * the {@code InputStream} to read data from. * @param inflater * the specific {@code Inflater} for decompressing data. - * @param bsize + * @param bufferSize * the size to be used for the internal buffer. */ - public InflaterInputStream(InputStream is, Inflater inflater, int bsize) { + public InflaterInputStream(InputStream is, Inflater inflater, int bufferSize) { super(is); if (is == null) { throw new NullPointerException("is == null"); } else if (inflater == null) { throw new NullPointerException("inflater == null"); } - if (bsize <= 0) { - throw new IllegalArgumentException(); + if (bufferSize <= 0) { + throw new IllegalArgumentException("bufferSize <= 0: " + bufferSize); } this.inf = inflater; if (is instanceof ZipFile.RAFStream) { - nativeEndBufSize = bsize; + nativeEndBufSize = bufferSize; } else { - buf = new byte[bsize]; + buf = new byte[bufferSize]; } } diff --git a/luni/src/main/java/java/util/zip/InflaterOutputStream.java b/luni/src/main/java/java/util/zip/InflaterOutputStream.java index 9a699a8..ca8a950 100644 --- a/luni/src/main/java/java/util/zip/InflaterOutputStream.java +++ b/luni/src/main/java/java/util/zip/InflaterOutputStream.java @@ -76,7 +76,7 @@ public class InflaterOutputStream extends FilterOutputStream { throw new NullPointerException("inf == null"); } if (bufferSize <= 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("bufferSize <= 0: " + bufferSize); } this.inf = inf; this.buf = new byte[bufferSize]; diff --git a/luni/src/main/java/java/util/zip/ZipEntry.java b/luni/src/main/java/java/util/zip/ZipEntry.java index e2bfc8d..3e58727 100644 --- a/luni/src/main/java/java/util/zip/ZipEntry.java +++ b/luni/src/main/java/java/util/zip/ZipEntry.java @@ -183,11 +183,10 @@ public class ZipEntry implements ZipConstants, Cloneable { * the comment for this entry. */ public void setComment(String comment) { - if (comment == null || comment.length() <= 0xFFFF) { - this.comment = comment; - } else { - throw new IllegalArgumentException(); + if (comment != null && comment.length() > 0xffff) { + throw new IllegalArgumentException("Comment too long: " + comment.length()); } + this.comment = comment; } /** @@ -225,11 +224,10 @@ public class ZipEntry implements ZipConstants, Cloneable { * when the length of data is greater than 0xFFFF bytes. */ public void setExtra(byte[] data) { - if (data == null || data.length <= 0xFFFF) { - extra = data; - } else { - throw new IllegalArgumentException(); + if (data != null && data.length > 0xffff) { + throw new IllegalArgumentException("Extra data too long: " + data.length); } + extra = data; } /** diff --git a/luni/src/main/java/java/util/zip/ZipFile.java b/luni/src/main/java/java/util/zip/ZipFile.java index 816d1b8..83b1992 100644 --- a/luni/src/main/java/java/util/zip/ZipFile.java +++ b/luni/src/main/java/java/util/zip/ZipFile.java @@ -118,7 +118,7 @@ public class ZipFile implements ZipConstants { public ZipFile(File file, int mode) throws IOException { fileName = file.getPath(); if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE)) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad mode: " + mode); } if ((mode & OPEN_DELETE) != 0) { diff --git a/luni/src/main/java/java/util/zip/ZipOutputStream.java b/luni/src/main/java/java/util/zip/ZipOutputStream.java index 47db8f6..77a993b 100644 --- a/luni/src/main/java/java/util/zip/ZipOutputStream.java +++ b/luni/src/main/java/java/util/zip/ZipOutputStream.java @@ -367,7 +367,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant */ public void setLevel(int level) { if (level < Deflater.DEFAULT_COMPRESSION || level > Deflater.BEST_COMPRESSION) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad level: " + level); } compressLevel = level; } @@ -382,7 +382,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant */ public void setMethod(int method) { if (method != STORED && method != DEFLATED) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad method: " + method); } compressMethod = method; } diff --git a/luni/src/main/java/libcore/icu/NativeDecimalFormat.java b/luni/src/main/java/libcore/icu/NativeDecimalFormat.java index f6b5214..565da2e 100644 --- a/luni/src/main/java/libcore/icu/NativeDecimalFormat.java +++ b/luni/src/main/java/libcore/icu/NativeDecimalFormat.java @@ -280,8 +280,11 @@ public final class NativeDecimalFormat implements Cloneable { } public AttributedCharacterIterator formatToCharacterIterator(Object object) { + if (object == null) { + throw new NullPointerException("object == null"); + } if (!(object instanceof Number)) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("object not a Number: " + object.getClass()); } Number number = (Number) object; FieldPositionIterator fpIter = new FieldPositionIterator(); diff --git a/luni/src/main/java/libcore/net/http/HttpURLConnectionImpl.java b/luni/src/main/java/libcore/net/http/HttpURLConnectionImpl.java index 260a9ad..9507745 100644 --- a/luni/src/main/java/libcore/net/http/HttpURLConnectionImpl.java +++ b/luni/src/main/java/libcore/net/http/HttpURLConnectionImpl.java @@ -406,7 +406,7 @@ class HttpURLConnectionImpl extends HttpURLConnection { final boolean processAuthHeader(int responseCode, ResponseHeaders response, RawHeaders successorRequestHeaders) throws IOException { if (responseCode != HTTP_PROXY_AUTH && responseCode != HTTP_UNAUTHORIZED) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Bad response code: " + responseCode); } // keep asking for username/password until authorized diff --git a/luni/src/main/java/org/apache/harmony/security/asn1/ObjectIdentifier.java b/luni/src/main/java/org/apache/harmony/security/asn1/ObjectIdentifier.java index 24140e5..eb1e3e3 100644 --- a/luni/src/main/java/org/apache/harmony/security/asn1/ObjectIdentifier.java +++ b/luni/src/main/java/org/apache/harmony/security/asn1/ObjectIdentifier.java @@ -190,7 +190,7 @@ public final class ObjectIdentifier { if (! shouldThrow) { return null; } - throw new IllegalArgumentException(); + throw new IllegalArgumentException("str == null"); } int length = str.length(); diff --git a/luni/src/test/java/tests/api/java/util/SimpleTimeZoneTest.java b/luni/src/test/java/tests/api/java/util/SimpleTimeZoneTest.java index 618cbe4..eeb5b30 100644 --- a/luni/src/test/java/tests/api/java/util/SimpleTimeZoneTest.java +++ b/luni/src/test/java/tests/api/java/util/SimpleTimeZoneTest.java @@ -442,8 +442,18 @@ public class SimpleTimeZoneTest extends junit.framework.TestCase { st.setStartRule(0, 1, 1, 1); st.setEndRule(11, 1, 1, 1); st.setDSTSavings(1); - assertEquals("Daylight savings amount not set", 1, st.getDSTSavings()); - } + assertEquals(1, st.getDSTSavings()); + try { + st.setDSTSavings(0); + fail(); + } catch (IllegalArgumentException expected) { + } + try { + st.setDSTSavings(-1); + fail(); + } catch (IllegalArgumentException expected) { + } + } /** * java.util.SimpleTimeZone#setEndRule(int, int, int) diff --git a/xml/src/main/java/org/kxml2/io/KXmlParser.java b/xml/src/main/java/org/kxml2/io/KXmlParser.java index 2be8d36..80fd8ca 100644 --- a/xml/src/main/java/org/kxml2/io/KXmlParser.java +++ b/xml/src/main/java/org/kxml2/io/KXmlParser.java @@ -1612,7 +1612,7 @@ public class KXmlParser implements XmlPullParser, Closeable { boolean detectCharset = (charset == null); if (is == null) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("is == null"); } try { diff --git a/xml/src/main/java/org/kxml2/io/KXmlSerializer.java b/xml/src/main/java/org/kxml2/io/KXmlSerializer.java index d1965d6..8fa2756 100644 --- a/xml/src/main/java/org/kxml2/io/KXmlSerializer.java +++ b/xml/src/main/java/org/kxml2/io/KXmlSerializer.java @@ -327,7 +327,7 @@ public class KXmlSerializer implements XmlSerializer { public void setOutput(OutputStream os, String encoding) throws IOException { if (os == null) - throw new IllegalArgumentException(); + throw new IllegalArgumentException("os == null"); setOutput( encoding == null ? new OutputStreamWriter(os) |