mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-04 21:20:17 +00:00
8151832: Improve exception messages in exception thrown by new JDK 9 code
Reviewed-by: alanb
This commit is contained in:
parent
139e60e8e3
commit
48490309d8
@ -664,7 +664,7 @@ final class ModuleInfo {
|
||||
try {
|
||||
bb.get(b, off, len);
|
||||
} catch (BufferUnderflowException e) {
|
||||
throw new EOFException();
|
||||
throw new EOFException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -681,7 +681,7 @@ final class ModuleInfo {
|
||||
int ch = bb.get();
|
||||
return (ch != 0);
|
||||
} catch (BufferUnderflowException e) {
|
||||
throw new EOFException();
|
||||
throw new EOFException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -690,7 +690,7 @@ final class ModuleInfo {
|
||||
try {
|
||||
return bb.get();
|
||||
} catch (BufferUnderflowException e) {
|
||||
throw new EOFException();
|
||||
throw new EOFException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -699,7 +699,7 @@ final class ModuleInfo {
|
||||
try {
|
||||
return ((int) bb.get()) & 0xff;
|
||||
} catch (BufferUnderflowException e) {
|
||||
throw new EOFException();
|
||||
throw new EOFException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -708,7 +708,7 @@ final class ModuleInfo {
|
||||
try {
|
||||
return bb.getShort();
|
||||
} catch (BufferUnderflowException e) {
|
||||
throw new EOFException();
|
||||
throw new EOFException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -717,7 +717,7 @@ final class ModuleInfo {
|
||||
try {
|
||||
return ((int) bb.getShort()) & 0xffff;
|
||||
} catch (BufferUnderflowException e) {
|
||||
throw new EOFException();
|
||||
throw new EOFException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -726,7 +726,7 @@ final class ModuleInfo {
|
||||
try {
|
||||
return bb.getChar();
|
||||
} catch (BufferUnderflowException e) {
|
||||
throw new EOFException();
|
||||
throw new EOFException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -735,7 +735,7 @@ final class ModuleInfo {
|
||||
try {
|
||||
return bb.getInt();
|
||||
} catch (BufferUnderflowException e) {
|
||||
throw new EOFException();
|
||||
throw new EOFException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -744,7 +744,7 @@ final class ModuleInfo {
|
||||
try {
|
||||
return bb.getLong();
|
||||
} catch (BufferUnderflowException e) {
|
||||
throw new EOFException();
|
||||
throw new EOFException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -753,7 +753,7 @@ final class ModuleInfo {
|
||||
try {
|
||||
return bb.getFloat();
|
||||
} catch (BufferUnderflowException e) {
|
||||
throw new EOFException();
|
||||
throw new EOFException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -762,7 +762,7 @@ final class ModuleInfo {
|
||||
try {
|
||||
return bb.getDouble();
|
||||
} catch (BufferUnderflowException e) {
|
||||
throw new EOFException();
|
||||
throw new EOFException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -597,10 +597,10 @@ public class Proxy implements java.io.Serializable {
|
||||
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);
|
||||
|
||||
@ -186,7 +186,9 @@ public class BasicImageReader implements AutoCloseable {
|
||||
|
||||
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 @@ public class BasicImageReader implements AutoCloseable {
|
||||
|
||||
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 @@ public class BasicImageReader implements AutoCloseable {
|
||||
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) {
|
||||
|
||||
@ -79,7 +79,8 @@ public final class ImageHeader {
|
||||
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);
|
||||
|
||||
@ -81,7 +81,8 @@ public class ImageLocation {
|
||||
}
|
||||
|
||||
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 @@ public class ImageLocation {
|
||||
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 @@ public class ImageLocation {
|
||||
|
||||
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 @@ public class ImageLocation {
|
||||
|
||||
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]);
|
||||
|
||||
@ -82,7 +82,7 @@ public class ImageStream {
|
||||
|
||||
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 class ImageStream {
|
||||
|
||||
public void skip(int n) {
|
||||
if (n < 0) {
|
||||
throw new IndexOutOfBoundsException("n");
|
||||
throw new IndexOutOfBoundsException("skip value = " + n);
|
||||
}
|
||||
|
||||
buffer.position(buffer.position() + n);
|
||||
|
||||
@ -151,7 +151,7 @@ public class ImageStringsReader implements ImageStrings {
|
||||
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 @@ public class ImageStringsReader implements ImageStrings {
|
||||
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 @@ public class ImageStringsReader implements ImageStrings {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@ -183,7 +183,7 @@ class JrtFileSystem extends FileSystem {
|
||||
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 @@ class JrtFileSystem extends FileSystem {
|
||||
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) ||
|
||||
|
||||
@ -122,7 +122,8 @@ final class JrtPath implements Path {
|
||||
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 @@ final class JrtPath implements Path {
|
||||
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 @@ final class JrtPath implements Path {
|
||||
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 @@ final class JrtPath implements Path {
|
||||
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 @@ final class JrtPath implements Path {
|
||||
}
|
||||
if (c == '\u0000') {
|
||||
throw new InvalidPathException(path,
|
||||
"Path: nul character not allowed");
|
||||
"Path: NUL character not allowed");
|
||||
}
|
||||
to.append(c);
|
||||
prevC = c;
|
||||
|
||||
@ -50,7 +50,7 @@ public class VM {
|
||||
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();
|
||||
}
|
||||
|
||||
@ -67,19 +67,22 @@ public final class ConstructorFinder extends AbstractFinder<Constructor<?>> {
|
||||
*/
|
||||
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);
|
||||
|
||||
@ -2461,16 +2461,16 @@ public abstract class ImageReader {
|
||||
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);
|
||||
|
||||
@ -1963,16 +1963,16 @@ public abstract class ImageWriter implements ImageTranscoder {
|
||||
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user