7080020: Add conventional constructors to InternalError and VirtualMachineError
authordarcy
Mon, 22 Aug 2011 12:16:12 -0700
changeset 10355 a976ff46116b
parent 10354 5257798c26d0
child 10356 5c00183df0c8
7080020: Add conventional constructors to InternalError and VirtualMachineError Reviewed-by: darcy Contributed-by: nsebastian.sickelmann@gmx.de
jdk/src/share/classes/com/sun/servicetag/SunConnection.java
jdk/src/share/classes/java/lang/InternalError.java
jdk/src/share/classes/java/lang/VirtualMachineError.java
jdk/src/share/classes/java/util/prefs/Preferences.java
jdk/src/share/classes/sun/font/FontManagerFactory.java
jdk/src/share/classes/sun/misc/URLClassPath.java
jdk/src/share/classes/sun/reflect/MethodAccessorGenerator.java
jdk/src/share/classes/sun/security/x509/X500Name.java
jdk/src/share/classes/sun/tools/jconsole/ProxyClient.java
jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java
--- a/jdk/src/share/classes/com/sun/servicetag/SunConnection.java	Mon Aug 22 16:05:38 2011 +0100
+++ b/jdk/src/share/classes/com/sun/servicetag/SunConnection.java	Mon Aug 22 12:16:12 2011 -0700
@@ -101,10 +101,7 @@
             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 @@
         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 @@
             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 @@
             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();
--- a/jdk/src/share/classes/java/lang/InternalError.java	Mon Aug 22 16:05:38 2011 +0100
+++ b/jdk/src/share/classes/java/lang/InternalError.java	Mon Aug 22 12:16:12 2011 -0700
@@ -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 @@
  * @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 @@
      * Constructs an <code>InternalError</code> with the specified
      * detail message.
      *
-     * @param   s   the detail message.
+     * @param   message   the detail message.
+     */
+    public InternalError(String message) {
+        super(message);
+    }
+
+
+    /**
+     * Constructs an {@code InternalError} with the specified detail
+     * message and cause.  <p>Note that the detail message associated
+     * with {@code cause} is <i>not</i> 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 s) {
-        super(s);
+    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);
+    }
+
 }
--- a/jdk/src/share/classes/java/lang/VirtualMachineError.java	Mon Aug 22 16:05:38 2011 +0100
+++ b/jdk/src/share/classes/java/lang/VirtualMachineError.java	Mon Aug 22 12:16:12 2011 -0700
@@ -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 @@
  * @author  Frank Yellin
  * @since   JDK1.0
  */
-abstract public
-class VirtualMachineError extends Error {
+abstract public class VirtualMachineError extends Error {
     /**
      * Constructs a <code>VirtualMachineError</code> with no detail message.
      */
@@ -46,9 +45,43 @@
      * Constructs a <code>VirtualMachineError</code> 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.  <p>Note that the detail message
+     * associated with {@code cause} is <i>not</i> 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);
     }
 }
--- a/jdk/src/share/classes/java/util/prefs/Preferences.java	Mon Aug 22 16:05:38 2011 +0100
+++ b/jdk/src/share/classes/java/util/prefs/Preferences.java	Mon Aug 22 12:16:12 2011 -0700
@@ -256,11 +256,9 @@
                                       .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 @@
             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);
         }
     }
 
--- a/jdk/src/share/classes/sun/font/FontManagerFactory.java	Mon Aug 22 16:05:38 2011 +0100
+++ b/jdk/src/share/classes/sun/font/FontManagerFactory.java	Mon Aug 22 12:16:12 2011 -0700
@@ -78,20 +78,11 @@
                     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;
             }
--- a/jdk/src/share/classes/sun/misc/URLClassPath.java	Mon Aug 22 16:05:38 2011 +0100
+++ b/jdk/src/share/classes/sun/misc/URLClassPath.java	Mon Aug 22 12:16:12 2011 -0700
@@ -717,7 +717,7 @@
             try {
                 ensureOpen();
             } catch (IOException e) {
-                throw (InternalError) new InternalError().initCause(e);
+                throw new InternalError(e);
             }
             return index;
         }
@@ -812,7 +812,7 @@
             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 @@
                         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) {
--- a/jdk/src/share/classes/sun/reflect/MethodAccessorGenerator.java	Mon Aug 22 16:05:38 2011 +0100
+++ b/jdk/src/share/classes/sun/reflect/MethodAccessorGenerator.java	Mon Aug 22 12:16:12 2011 -0700
@@ -401,10 +401,8 @@
                                  0,
                                  bytes.length,
                                  declaringClass.getClassLoader()).newInstance();
-                        } catch (InstantiationException |
-                                 IllegalAccessException e) {
-                            throw (InternalError)
-                                new InternalError().initCause(e);
+                        } catch (InstantiationException | IllegalAccessException e) {
+                            throw new InternalError(e);
                         }
                     }
                 });
--- a/jdk/src/share/classes/sun/security/x509/X500Name.java	Mon Aug 22 16:05:38 2011 +0100
+++ b/jdk/src/share/classes/sun/security/x509/X500Name.java	Mon Aug 22 12:16:12 2011 -0700
@@ -1401,8 +1401,7 @@
             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);
         }
     }
 
--- a/jdk/src/share/classes/sun/tools/jconsole/ProxyClient.java	Mon Aug 22 16:05:38 2011 +0100
+++ b/jdk/src/share/classes/sun/tools/jconsole/ProxyClient.java	Mon Aug 22 12:16:12 2011 -0700
@@ -208,7 +208,7 @@
             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 @@
         } 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) {
--- a/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java	Mon Aug 22 16:05:38 2011 +0100
+++ b/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java	Mon Aug 22 12:16:12 2011 -0700
@@ -55,9 +55,7 @@
             try {
                 return new Iocp(null, ThreadPool.createDefault()).start();
             } catch (IOException ioe) {
-                InternalError e = new InternalError();
-                e.initCause(ioe);
-                throw e;
+                throw new InternalError(ioe);
             }
         }
     }