8151832: Improve exception messages in exception thrown by new JDK 9 code
authorcoffeys
Thu, 22 Sep 2016 17:21:10 +0100
changeset 41121 91734a3ed04b
parent 41120 c730063ccd48
child 41122 c33012bac916
8151832: Improve exception messages in exception thrown by new JDK 9 code Reviewed-by: alanb
jdk/src/java.base/share/classes/java/lang/module/ModuleInfo.java
jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java
jdk/src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java
jdk/src/java.base/share/classes/jdk/internal/jimage/ImageHeader.java
jdk/src/java.base/share/classes/jdk/internal/jimage/ImageLocation.java
jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStream.java
jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStringsReader.java
jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java
jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java
jdk/src/java.base/share/classes/jdk/internal/misc/VM.java
jdk/src/java.desktop/share/classes/com/sun/beans/finder/ConstructorFinder.java
jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java
jdk/src/java.desktop/share/classes/javax/imageio/ImageWriter.java
--- a/jdk/src/java.base/share/classes/java/lang/module/ModuleInfo.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/module/ModuleInfo.java	Thu Sep 22 17:21:10 2016 +0100
@@ -664,7 +664,7 @@
             try {
                 bb.get(b, off, len);
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -681,7 +681,7 @@
                 int ch = bb.get();
                 return (ch != 0);
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -690,7 +690,7 @@
             try {
                 return bb.get();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -699,7 +699,7 @@
             try {
                 return ((int) bb.get()) & 0xff;
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -708,7 +708,7 @@
             try {
                 return bb.getShort();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -717,7 +717,7 @@
             try {
                 return ((int) bb.getShort()) & 0xffff;
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -726,7 +726,7 @@
             try {
                 return bb.getChar();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -735,7 +735,7 @@
             try {
                 return bb.getInt();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -744,7 +744,7 @@
             try {
                 return bb.getLong();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -753,7 +753,7 @@
             try {
                 return bb.getFloat();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
@@ -762,7 +762,7 @@
             try {
                 return bb.getDouble();
             } catch (BufferUnderflowException e) {
-                throw new EOFException();
+                throw new EOFException(e.getMessage());
             }
         }
 
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java	Thu Sep 22 17:21:10 2016 +0100
@@ -597,10 +597,10 @@
         private final Module module;
         ProxyBuilder(ClassLoader loader, List<Class<?>> interfaces) {
             if (!VM.isModuleSystemInited()) {
-                throw new InternalError("Proxy is not supported until module system is fully initialzed");
+                throw new InternalError("Proxy is not supported until module system is fully initialized");
             }
             if (interfaces.size() > 65535) {
-                throw new IllegalArgumentException("interface limit exceeded");
+                throw new IllegalArgumentException("interface limit exceeded: " + interfaces.size());
             }
 
             Set<Class<?>> refTypes = referencedTypes(loader, interfaces);
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java	Thu Sep 22 17:21:10 2016 +0100
@@ -186,7 +186,9 @@
 
         if (result.getMajorVersion() != ImageHeader.MAJOR_VERSION ||
             result.getMinorVersion() != ImageHeader.MINOR_VERSION) {
-            throw new IOException("The image file \"" + name + "\" is not the correct version");
+            throw new IOException("The image file \"" + name + "\" is not " +
+                "the correct version. Major: " + result.getMajorVersion() +
+                ". Minor: " + result.getMinorVersion());
         }
 
         return result;
@@ -318,11 +320,11 @@
 
     private ByteBuffer readBuffer(long offset, long size) {
         if (offset < 0 || Integer.MAX_VALUE <= offset) {
-            throw new IndexOutOfBoundsException("offset");
+            throw new IndexOutOfBoundsException("Bad offset: " + offset);
         }
 
         if (size < 0 || Integer.MAX_VALUE <= size) {
-            throw new IndexOutOfBoundsException("size");
+            throw new IndexOutOfBoundsException("Bad size: " + size);
         }
 
         if (MAP_ALL) {
@@ -382,11 +384,13 @@
         long uncompressedSize = loc.getUncompressedSize();
 
         if (compressedSize < 0 || Integer.MAX_VALUE < compressedSize) {
-            throw new IndexOutOfBoundsException("Compressed size");
+            throw new IndexOutOfBoundsException(
+                "Bad compressed size: " + compressedSize);
         }
 
         if (uncompressedSize < 0 || Integer.MAX_VALUE < uncompressedSize) {
-            throw new IndexOutOfBoundsException("Uncompressed size");
+            throw new IndexOutOfBoundsException(
+                "Bad uncompressed size: " + uncompressedSize);
         }
 
         if (compressedSize == 0) {
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageHeader.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageHeader.java	Thu Sep 22 17:21:10 2016 +0100
@@ -79,7 +79,8 @@
         Objects.requireNonNull(buffer);
 
         if (buffer.capacity() != HEADER_SLOTS) {
-            throw new InternalError("jimage header not the correct size");
+            throw new InternalError(
+                "jimage header not the correct size: " + buffer.capacity());
         }
 
         int magic = buffer.get(0);
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageLocation.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageLocation.java	Thu Sep 22 17:21:10 2016 +0100
@@ -81,7 +81,8 @@
                 }
 
                 if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) {
-                    throw new InternalError("Invalid jimage attribute kind");
+                    throw new InternalError(
+                        "Invalid jimage attribute kind: " + kind);
                 }
 
                 int length = attributeLength(data);
@@ -91,7 +92,7 @@
                     value <<= 8;
 
                     if (!bytes.hasRemaining()) {
-                        throw new InternalError("\"Missing jimage attribute datad");
+                        throw new InternalError("Missing jimage attribute data");
                     }
 
                     value |= bytes.get() & 0xFF;
@@ -134,7 +135,8 @@
 
     long getAttribute(int kind) {
         if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) {
-            throw new InternalError("Invalid jimage attribute kind");
+            throw new InternalError(
+                "Invalid jimage attribute kind: " + kind);
         }
 
         return attributes[kind];
@@ -142,7 +144,8 @@
 
     String getAttributeString(int kind) {
         if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) {
-            throw new InternalError("Invalid jimage attribute kind");
+            throw new InternalError(
+                "Invalid jimage attribute kind: " + kind);
         }
 
         return getStrings().get((int)attributes[kind]);
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStream.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStream.java	Thu Sep 22 17:21:10 2016 +0100
@@ -82,7 +82,7 @@
 
     public void ensure(int needs) {
         if (needs < 0) {
-            throw new IndexOutOfBoundsException("needs");
+            throw new IndexOutOfBoundsException("Bad value: " + needs);
         }
 
         if (needs > buffer.remaining()) {
@@ -106,7 +106,7 @@
 
     public void skip(int n) {
         if (n < 0) {
-            throw new IndexOutOfBoundsException("n");
+            throw new IndexOutOfBoundsException("skip value = " + n);
         }
 
         buffer.position(buffer.position() + n);
--- a/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStringsReader.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.base/share/classes/jdk/internal/jimage/ImageStringsReader.java	Thu Sep 22 17:21:10 2016 +0100
@@ -151,7 +151,7 @@
         try {
             charsFromMUTF8(chars, bytes, offset, count);
         } catch (UTFDataFormatException ex) {
-            throw new InternalError("Attempt to convert non modified UTF-8 byte sequence");
+            throw new InternalError("Attempt to convert non modified UTF-8 byte sequence", ex);
         }
 
         return new String(chars);
@@ -199,7 +199,8 @@
                     ch = buffer.get();
 
                     if ((ch & 0xC0) != 0x80) {
-                        throw new InternalError("Bad continuation in modified UTF-8 byte sequence");
+                        throw new InternalError("Bad continuation in " +
+                            "modified UTF-8 byte sequence: " + ch);
                     }
 
                     uch = ((uch & ~mask) << 6) | (ch & 0x3F);
@@ -208,7 +209,8 @@
             }
 
             if ((uch & 0xFFFF) != uch) {
-                throw new InternalError("UTF-32 char in modified UTF-8 byte sequence");
+                throw new InternalError("UTF-32 char in modified UTF-8 " +
+                    "byte sequence: " + uch);
             }
 
             chars[j++] = (char)uch;
--- a/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java	Thu Sep 22 17:21:10 2016 +0100
@@ -183,7 +183,7 @@
     public PathMatcher getPathMatcher(String syntaxAndInput) {
         int pos = syntaxAndInput.indexOf(':');
         if (pos <= 0 || pos == syntaxAndInput.length()) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException("pos is " + pos);
         }
         String syntax = syntaxAndInput.substring(0, pos);
         String input = syntaxAndInput.substring(pos + 1);
@@ -285,7 +285,8 @@
         for (OpenOption option : options) {
             Objects.requireNonNull(option);
             if (!(option instanceof StandardOpenOption)) {
-                throw new IllegalArgumentException();
+                throw new IllegalArgumentException(
+                    "option class: " + option.getClass());
             }
         }
         if (options.contains(StandardOpenOption.WRITE) ||
--- a/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java	Thu Sep 22 17:21:10 2016 +0100
@@ -122,7 +122,8 @@
     public final JrtPath getName(int index) {
         initOffsets();
         if (index < 0 || index >= offsets.length) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException("index: " +
+                index + ", offsets length: " + offsets.length);
         }
         int begin = offsets[index];
         int end;
@@ -139,7 +140,9 @@
         initOffsets();
         if (beginIndex < 0 || endIndex > offsets.length ||
             beginIndex >= endIndex) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException(
+                "beginIndex: " + beginIndex + ", endIndex: " + endIndex +
+                ", offsets length: " + offsets.length);
         }
         // starting/ending offsets
         int begin = offsets[beginIndex];
@@ -211,7 +214,8 @@
             return o;
         }
         if (jrtfs != o.jrtfs || isAbsolute() != o.isAbsolute()) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException(
+                "Incorrect filesystem or path: " + other);
         }
         final String tp = this.path;
         final String op = o.path;
@@ -366,7 +370,8 @@
     private JrtPath checkPath(Path path) {
         Objects.requireNonNull(path);
         if (!(path instanceof JrtPath))
-            throw new ProviderMismatchException();
+            throw new ProviderMismatchException("path class: " +
+                path.getClass());
         return (JrtPath) path;
     }
 
@@ -459,7 +464,7 @@
             }
             if (c == '\u0000') {
                 throw new InvalidPathException(path,
-                        "Path: nul character not allowed");
+                        "Path: NUL character not allowed");
             }
             to.append(c);
             prevC = c;
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/VM.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/VM.java	Thu Sep 22 17:21:10 2016 +0100
@@ -50,7 +50,7 @@
     public static void initLevel(int value) {
         synchronized (lock) {
             if (value <= initLevel || value > SYSTEM_BOOTED)
-                throw new InternalError();
+                throw new InternalError("Bad level: " + value);
             initLevel = value;
             lock.notifyAll();
         }
--- a/jdk/src/java.desktop/share/classes/com/sun/beans/finder/ConstructorFinder.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.desktop/share/classes/com/sun/beans/finder/ConstructorFinder.java	Thu Sep 22 17:21:10 2016 +0100
@@ -67,19 +67,22 @@
      */
     public static Constructor<?> findConstructor(Class<?> type, Class<?>...args) throws NoSuchMethodException {
         if (type.isPrimitive()) {
-            throw new NoSuchMethodException("Primitive wrapper does not contain constructors");
+            throw new NoSuchMethodException("Primitive wrapper does not contain constructors: "
+                + type.getName());
         }
         if (type.isInterface()) {
-            throw new NoSuchMethodException("Interface does not contain constructors");
+            throw new NoSuchMethodException("Interface does not contain constructors: "
+                + type.getName());
         }
         if (!FinderUtils.isExported(type)) {
-            throw new NoSuchMethodException("Class is not accessible");
+            throw new NoSuchMethodException("Class is not accessible: " + type.getName());
         }
         if (Modifier.isAbstract(type.getModifiers())) {
-            throw new NoSuchMethodException("Abstract class cannot be instantiated");
+            throw new NoSuchMethodException("Abstract class cannot be instantiated: "
+                + type.getName());
         }
         if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) {
-            throw new NoSuchMethodException("Class is not accessible");
+            throw new NoSuchMethodException("Class is not accessible: " + type.getName());
         }
         PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
         Signature signature = new Signature(type, args);
--- a/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java	Thu Sep 22 17:21:10 2016 +0100
@@ -2461,16 +2461,16 @@
             try {
                 bundle = ResourceBundle.getBundle(baseName, locale, this.getClass().getModule());
             } catch (MissingResourceException mre) {
-                throw new IllegalArgumentException("Bundle not found!");
+                throw new IllegalArgumentException("Bundle not found!", mre);
             }
 
             String warning = null;
             try {
                 warning = bundle.getString(keyword);
             } catch (ClassCastException cce) {
-                throw new IllegalArgumentException("Resource is not a String!");
+                throw new IllegalArgumentException("Resource is not a String!", cce);
             } catch (MissingResourceException mre) {
-                throw new IllegalArgumentException("Resource is missing!");
+                throw new IllegalArgumentException("Resource is missing!", mre);
             }
 
             listener.warningOccurred(this, warning);
--- a/jdk/src/java.desktop/share/classes/javax/imageio/ImageWriter.java	Thu Sep 22 07:28:40 2016 -0700
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/ImageWriter.java	Thu Sep 22 17:21:10 2016 +0100
@@ -1963,16 +1963,16 @@
             try {
                 bundle = ResourceBundle.getBundle(baseName, locale, this.getClass().getModule());
             } catch (MissingResourceException mre) {
-                throw new IllegalArgumentException("Bundle not found!");
+                throw new IllegalArgumentException("Bundle not found!", mre);
             }
 
             String warning = null;
             try {
                 warning = bundle.getString(keyword);
             } catch (ClassCastException cce) {
-                throw new IllegalArgumentException("Resource is not a String!");
+                throw new IllegalArgumentException("Resource is not a String!", cce);
             } catch (MissingResourceException mre) {
-                throw new IllegalArgumentException("Resource is missing!");
+                throw new IllegalArgumentException("Resource is missing!", mre);
             }
 
             listener.warningOccurred(this, imageIndex, warning);