diff --git a/src/share/classes/com/sun/servicetag/SunConnection.java b/src/share/classes/com/sun/servicetag/SunConnection.java index a28fbf9ed9b2227499336f0b41afcd1810ad1bf6..91ea977c54b7682fdc60c50f3693ce80a63ab677 100644 --- a/src/share/classes/com/sun/servicetag/SunConnection.java +++ b/src/share/classes/com/sun/servicetag/SunConnection.java @@ -101,10 +101,7 @@ class SunConnection { return new URL(registerURL); } catch (MalformedURLException ex) { // should never reach here - InternalError x = - new InternalError(ex.getMessage()); - x.initCause(ex); - throw x; + throw new InternalError(ex.getMessage(), ex); } } @@ -171,9 +168,7 @@ class SunConnection { try { BrowserSupport.browse(url.toURI()); } catch (URISyntaxException ex) { - InternalError x = new InternalError("Error in registering: " + ex.getMessage()); - x.initCause(ex); - throw x; + throw new InternalError("Error in registering: " + ex.getMessage(), ex); } catch (IllegalArgumentException ex) { if (Util.isVerbose()) { ex.printStackTrace(); @@ -232,9 +227,7 @@ class SunConnection { return (returnCode == HttpURLConnection.HTTP_OK); } catch (MalformedURLException me) { // should never reach here - InternalError x = new InternalError("Error in registering: " + me.getMessage()); - x.initCause(me); - throw x; + throw new InternalError("Error in registering: " + me.getMessage(), me); } catch (Exception ioe) { // SocketTimeoutException, IOException or UnknownHostException if (Util.isVerbose()) { @@ -262,10 +255,9 @@ class SunConnection { BrowserSupport.browse(registerPage.toURI()); } catch (FileNotFoundException ex) { // should never reach here - InternalError x = - new InternalError("Error in launching " + registerPage + ": " + ex.getMessage()); - x.initCause(ex); - throw x; + throw new InternalError( + "Error in launching " + registerPage + ": " + ex.getMessage() + , ex); } catch (IllegalArgumentException ex) { if (Util.isVerbose()) { ex.printStackTrace(); diff --git a/src/share/classes/java/lang/InternalError.java b/src/share/classes/java/lang/InternalError.java index f49e9c24724647880f93fc74e186f33f5020be65..8d33821ff3ccf349cd337abf6f9df2aea556d437 100644 --- a/src/share/classes/java/lang/InternalError.java +++ b/src/share/classes/java/lang/InternalError.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,8 +32,7 @@ package java.lang; * @author unascribed * @since JDK1.0 */ -public -class InternalError extends VirtualMachineError { +public class InternalError extends VirtualMachineError { private static final long serialVersionUID = -9062593416125562365L; /** @@ -47,9 +46,45 @@ class InternalError extends VirtualMachineError { * Constructs an InternalError with the specified * detail message. * - * @param s the detail message. + * @param message the detail message. */ - public InternalError(String s) { - super(s); + public InternalError(String message) { + super(message); } + + + /** + * Constructs an {@code InternalError} with the specified detail + * message and cause.

Note that the detail message associated + * with {@code cause} is not automatically incorporated in + * this error's detail message. + * + * @param message the detail message (which is saved for later retrieval + * by the {@link #getMessage()} method). + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A {@code null} value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + * @since 1.8 + */ + public InternalError(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructs an {@code InternalError} with the specified cause + * and a detail message of {@code (cause==null ? null : + * cause.toString())} (which typically contains the class and + * detail message of {@code cause}). + * + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A {@code null} value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + * @since 1.8 + */ + public InternalError(Throwable cause) { + super(cause); + } + } diff --git a/src/share/classes/java/lang/VirtualMachineError.java b/src/share/classes/java/lang/VirtualMachineError.java index 2843147bff2d7506a4e1d89c0235113efa3c5fb4..8bbe1c01392bfe01c6d5efa0d68952b4801fd898 100644 --- a/src/share/classes/java/lang/VirtualMachineError.java +++ b/src/share/classes/java/lang/VirtualMachineError.java @@ -1,9 +1,9 @@ /* - * Copyright (c) 1995, 1997, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as + * under the terms of the GNU General Public License version 2 only, asP * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. @@ -33,8 +33,7 @@ package java.lang; * @author Frank Yellin * @since JDK1.0 */ -abstract public -class VirtualMachineError extends Error { +abstract public class VirtualMachineError extends Error { /** * Constructs a VirtualMachineError with no detail message. */ @@ -46,9 +45,43 @@ class VirtualMachineError extends Error { * Constructs a VirtualMachineError with the specified * detail message. * - * @param s the detail message. + * @param message the detail message. */ - public VirtualMachineError(String s) { - super(s); + public VirtualMachineError(String message) { + super(message); + } + + /** + * Constructs a {@code VirtualMachineError} with the specified + * detail message and cause.

Note that the detail message + * associated with {@code cause} is not automatically + * incorporated in this error's detail message. + * + * @param message the detail message (which is saved for later retrieval + * by the {@link #getMessage()} method). + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A {@code null} value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + * @since 1.8 + */ + public VirtualMachineError(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructs an a {@code VirtualMachineError} with the specified + * cause and a detail message of {@code (cause==null ? null : + * cause.toString())} (which typically contains the class and + * detail message of {@code cause}). + * + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A {@code null} value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + * @since 1.8 + */ + public VirtualMachineError(Throwable cause) { + super(cause); } } diff --git a/src/share/classes/java/util/prefs/Preferences.java b/src/share/classes/java/util/prefs/Preferences.java index 94461838926d52a86159417b75682267da26c522..fe20a74b6f0384c9a8f7cc3497429a474ec7e725 100644 --- a/src/share/classes/java/util/prefs/Preferences.java +++ b/src/share/classes/java/util/prefs/Preferences.java @@ -256,11 +256,9 @@ public abstract class Preferences { .getContextClassLoader()) .newInstance(); } catch (Exception e) { - InternalError error = new InternalError( + throw new InternalError( "Can't instantiate Preferences factory " - + factoryName); - error.initCause(e); - throw error; + + factoryName, e); } } } @@ -299,11 +297,9 @@ public abstract class Preferences { return (PreferencesFactory) Class.forName(platformFactory, false, null).newInstance(); } catch (Exception e) { - InternalError error = new InternalError( + throw new InternalError( "Can't instantiate platform default Preferences factory " - + platformFactory); - error.initCause(e); - throw error; + + platformFactory, e); } } diff --git a/src/share/classes/sun/font/FontManagerFactory.java b/src/share/classes/sun/font/FontManagerFactory.java index b9f4a6f129889a40681b0cbe52beb36a01dca890..20618e286cb413e5442a0379033307bf5501d846 100644 --- a/src/share/classes/sun/font/FontManagerFactory.java +++ b/src/share/classes/sun/font/FontManagerFactory.java @@ -78,20 +78,11 @@ public final class FontManagerFactory { ClassLoader cl = ClassLoader.getSystemClassLoader(); Class fmClass = Class.forName(fmClassName, true, cl); instance = (FontManager) fmClass.newInstance(); - } catch (ClassNotFoundException ex) { - InternalError err = new InternalError(); - err.initCause(ex); - throw err; + } catch (ClassNotFoundException | + InstantiationException | + IllegalAccessException ex) { + throw new InternalError(ex); - } catch (InstantiationException ex) { - InternalError err = new InternalError(); - err.initCause(ex); - throw err; - - } catch (IllegalAccessException ex) { - InternalError err = new InternalError(); - err.initCause(ex); - throw err; } return null; } diff --git a/src/share/classes/sun/misc/URLClassPath.java b/src/share/classes/sun/misc/URLClassPath.java index 5db540d60020573158cb450ef892a8f872c5afa9..cee982369c40512ee6f061816a518cb57fd7a46c 100644 --- a/src/share/classes/sun/misc/URLClassPath.java +++ b/src/share/classes/sun/misc/URLClassPath.java @@ -717,7 +717,7 @@ public class URLClassPath { try { ensureOpen(); } catch (IOException e) { - throw (InternalError) new InternalError().initCause(e); + throw new InternalError(e); } return index; } @@ -812,7 +812,7 @@ public class URLClassPath { try { ensureOpen(); } catch (IOException e) { - throw (InternalError) new InternalError().initCause(e); + throw new InternalError(e); } final JarEntry entry = jar.getJarEntry(name); if (entry != null) @@ -900,7 +900,7 @@ public class URLClassPath { try { newLoader.ensureOpen(); } catch (IOException e) { - throw (InternalError) new InternalError().initCause(e); + throw new InternalError(e); } final JarEntry entry = newLoader.jar.getJarEntry(name); if (entry != null) { diff --git a/src/share/classes/sun/reflect/MethodAccessorGenerator.java b/src/share/classes/sun/reflect/MethodAccessorGenerator.java index 551beb027161011e592d2167fb366c99e3bca0cb..a489f52dde0ccd1e1cb2fe519a568bf94f01a90a 100644 --- a/src/share/classes/sun/reflect/MethodAccessorGenerator.java +++ b/src/share/classes/sun/reflect/MethodAccessorGenerator.java @@ -401,10 +401,8 @@ class MethodAccessorGenerator extends AccessorGenerator { 0, bytes.length, declaringClass.getClassLoader()).newInstance(); - } catch (InstantiationException | - IllegalAccessException e) { - throw (InternalError) - new InternalError().initCause(e); + } catch (InstantiationException | IllegalAccessException e) { + throw new InternalError(e); } } }); diff --git a/src/share/classes/sun/security/x509/X500Name.java b/src/share/classes/sun/security/x509/X500Name.java index ce4c69c695688e2e00081d7935a6ff400f30118b..551ec609267c5eb778f2174fe248519144180471 100644 --- a/src/share/classes/sun/security/x509/X500Name.java +++ b/src/share/classes/sun/security/x509/X500Name.java @@ -1401,8 +1401,7 @@ public class X500Name implements GeneralNameInterface, Principal { principalConstructor = constr; principalField = (Field)result[1]; } catch (Exception e) { - throw (InternalError)new InternalError("Could not obtain " - + "X500Principal access").initCause(e); + throw new InternalError("Could not obtain X500Principal access", e); } } diff --git a/src/share/classes/sun/tools/jconsole/ProxyClient.java b/src/share/classes/sun/tools/jconsole/ProxyClient.java index 10780035b0f680ab2ef21f7f0618d62c7cb0a0fe..6e129fd5569fe7c3890ad874b4ebf38c0a103c0b 100644 --- a/src/share/classes/sun/tools/jconsole/ProxyClient.java +++ b/src/share/classes/sun/tools/jconsole/ProxyClient.java @@ -208,7 +208,7 @@ public class ProxyClient implements JConsoleContext { serverStubClass = Class.forName(rmiServerImplStubClassName).asSubclass(Remote.class); } catch (ClassNotFoundException e) { // should never reach here - throw (InternalError) new InternalError(e.getMessage()).initCause(e); + throw new InternalError(e.getMessage(), e); } rmiServerImplStubClass = serverStubClass; } @@ -395,18 +395,10 @@ public class ProxyClient implements JConsoleContext { } catch (MalformedObjectNameException e) { // should not reach here throw new InternalError(e.getMessage()); - } catch (IntrospectionException e) { - InternalError ie = new InternalError(e.getMessage()); - ie.initCause(e); - throw ie; - } catch (InstanceNotFoundException e) { - InternalError ie = new InternalError(e.getMessage()); - ie.initCause(e); - throw ie; - } catch (ReflectionException e) { - InternalError ie = new InternalError(e.getMessage()); - ie.initCause(e); - throw ie; + } catch (IntrospectionException | + InstanceNotFoundException | + ReflectionException e) { + throw new InternalError(e.getMessage(), e); } if (hasPlatformMXBeans) { diff --git a/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java b/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java index 126342a2f651eaa07da499770222a4f874441230..b85271e686e13cec469d09b3b474e341670014b5 100644 --- a/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java +++ b/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java @@ -55,9 +55,7 @@ public class WindowsAsynchronousFileChannelImpl try { return new Iocp(null, ThreadPool.createDefault()).start(); } catch (IOException ioe) { - InternalError e = new InternalError(); - e.initCause(ioe); - throw e; + throw new InternalError(ioe); } } }