提交 eea48c18 编写于 作者: D darcy

7080020: Add conventional constructors to InternalError and VirtualMachineError

Reviewed-by: darcy
Contributed-by: nsebastian.sickelmann@gmx.de
上级 6b43f370
...@@ -101,10 +101,7 @@ class SunConnection { ...@@ -101,10 +101,7 @@ class SunConnection {
return new URL(registerURL); return new URL(registerURL);
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
// should never reach here // should never reach here
InternalError x = throw new InternalError(ex.getMessage(), ex);
new InternalError(ex.getMessage());
x.initCause(ex);
throw x;
} }
} }
...@@ -171,9 +168,7 @@ class SunConnection { ...@@ -171,9 +168,7 @@ class SunConnection {
try { try {
BrowserSupport.browse(url.toURI()); BrowserSupport.browse(url.toURI());
} catch (URISyntaxException ex) { } catch (URISyntaxException ex) {
InternalError x = new InternalError("Error in registering: " + ex.getMessage()); throw new InternalError("Error in registering: " + ex.getMessage(), ex);
x.initCause(ex);
throw x;
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
if (Util.isVerbose()) { if (Util.isVerbose()) {
ex.printStackTrace(); ex.printStackTrace();
...@@ -232,9 +227,7 @@ class SunConnection { ...@@ -232,9 +227,7 @@ class SunConnection {
return (returnCode == HttpURLConnection.HTTP_OK); return (returnCode == HttpURLConnection.HTTP_OK);
} catch (MalformedURLException me) { } catch (MalformedURLException me) {
// should never reach here // should never reach here
InternalError x = new InternalError("Error in registering: " + me.getMessage()); throw new InternalError("Error in registering: " + me.getMessage(), me);
x.initCause(me);
throw x;
} catch (Exception ioe) { } catch (Exception ioe) {
// SocketTimeoutException, IOException or UnknownHostException // SocketTimeoutException, IOException or UnknownHostException
if (Util.isVerbose()) { if (Util.isVerbose()) {
...@@ -262,10 +255,9 @@ class SunConnection { ...@@ -262,10 +255,9 @@ class SunConnection {
BrowserSupport.browse(registerPage.toURI()); BrowserSupport.browse(registerPage.toURI());
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
// should never reach here // should never reach here
InternalError x = throw new InternalError(
new InternalError("Error in launching " + registerPage + ": " + ex.getMessage()); "Error in launching " + registerPage + ": " + ex.getMessage()
x.initCause(ex); , ex);
throw x;
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
if (Util.isVerbose()) { if (Util.isVerbose()) {
ex.printStackTrace(); ex.printStackTrace();
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,8 +32,7 @@ package java.lang; ...@@ -32,8 +32,7 @@ package java.lang;
* @author unascribed * @author unascribed
* @since JDK1.0 * @since JDK1.0
*/ */
public public class InternalError extends VirtualMachineError {
class InternalError extends VirtualMachineError {
private static final long serialVersionUID = -9062593416125562365L; private static final long serialVersionUID = -9062593416125562365L;
/** /**
...@@ -47,9 +46,45 @@ class InternalError extends VirtualMachineError { ...@@ -47,9 +46,45 @@ class InternalError extends VirtualMachineError {
* Constructs an <code>InternalError</code> with the specified * Constructs an <code>InternalError</code> with the specified
* detail message. * detail message.
* *
* @param s the detail message. * @param message the detail message.
*/ */
public InternalError(String s) { public InternalError(String message) {
super(s); 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 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);
}
} }
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided * particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code. * by Oracle in the LICENSE file that accompanied this code.
...@@ -33,8 +33,7 @@ package java.lang; ...@@ -33,8 +33,7 @@ package java.lang;
* @author Frank Yellin * @author Frank Yellin
* @since JDK1.0 * @since JDK1.0
*/ */
abstract public abstract public class VirtualMachineError extends Error {
class VirtualMachineError extends Error {
/** /**
* Constructs a <code>VirtualMachineError</code> with no detail message. * Constructs a <code>VirtualMachineError</code> with no detail message.
*/ */
...@@ -46,9 +45,43 @@ class VirtualMachineError extends Error { ...@@ -46,9 +45,43 @@ class VirtualMachineError extends Error {
* Constructs a <code>VirtualMachineError</code> with the specified * Constructs a <code>VirtualMachineError</code> with the specified
* detail message. * detail message.
* *
* @param s the detail message. * @param message the detail message.
*/ */
public VirtualMachineError(String s) { public VirtualMachineError(String message) {
super(s); 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);
} }
} }
...@@ -256,11 +256,9 @@ public abstract class Preferences { ...@@ -256,11 +256,9 @@ public abstract class Preferences {
.getContextClassLoader()) .getContextClassLoader())
.newInstance(); .newInstance();
} catch (Exception e) { } catch (Exception e) {
InternalError error = new InternalError( throw new InternalError(
"Can't instantiate Preferences factory " "Can't instantiate Preferences factory "
+ factoryName); + factoryName, e);
error.initCause(e);
throw error;
} }
} }
} }
...@@ -299,11 +297,9 @@ public abstract class Preferences { ...@@ -299,11 +297,9 @@ public abstract class Preferences {
return (PreferencesFactory) return (PreferencesFactory)
Class.forName(platformFactory, false, null).newInstance(); Class.forName(platformFactory, false, null).newInstance();
} catch (Exception e) { } catch (Exception e) {
InternalError error = new InternalError( throw new InternalError(
"Can't instantiate platform default Preferences factory " "Can't instantiate platform default Preferences factory "
+ platformFactory); + platformFactory, e);
error.initCause(e);
throw error;
} }
} }
......
...@@ -78,20 +78,11 @@ public final class FontManagerFactory { ...@@ -78,20 +78,11 @@ public final class FontManagerFactory {
ClassLoader cl = ClassLoader.getSystemClassLoader(); ClassLoader cl = ClassLoader.getSystemClassLoader();
Class fmClass = Class.forName(fmClassName, true, cl); Class fmClass = Class.forName(fmClassName, true, cl);
instance = (FontManager) fmClass.newInstance(); instance = (FontManager) fmClass.newInstance();
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException |
InternalError err = new InternalError(); InstantiationException |
err.initCause(ex); IllegalAccessException ex) {
throw err; 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; return null;
} }
......
...@@ -717,7 +717,7 @@ public class URLClassPath { ...@@ -717,7 +717,7 @@ public class URLClassPath {
try { try {
ensureOpen(); ensureOpen();
} catch (IOException e) { } catch (IOException e) {
throw (InternalError) new InternalError().initCause(e); throw new InternalError(e);
} }
return index; return index;
} }
...@@ -812,7 +812,7 @@ public class URLClassPath { ...@@ -812,7 +812,7 @@ public class URLClassPath {
try { try {
ensureOpen(); ensureOpen();
} catch (IOException e) { } catch (IOException e) {
throw (InternalError) new InternalError().initCause(e); throw new InternalError(e);
} }
final JarEntry entry = jar.getJarEntry(name); final JarEntry entry = jar.getJarEntry(name);
if (entry != null) if (entry != null)
...@@ -900,7 +900,7 @@ public class URLClassPath { ...@@ -900,7 +900,7 @@ public class URLClassPath {
try { try {
newLoader.ensureOpen(); newLoader.ensureOpen();
} catch (IOException e) { } catch (IOException e) {
throw (InternalError) new InternalError().initCause(e); throw new InternalError(e);
} }
final JarEntry entry = newLoader.jar.getJarEntry(name); final JarEntry entry = newLoader.jar.getJarEntry(name);
if (entry != null) { if (entry != null) {
......
...@@ -401,10 +401,8 @@ class MethodAccessorGenerator extends AccessorGenerator { ...@@ -401,10 +401,8 @@ class MethodAccessorGenerator extends AccessorGenerator {
0, 0,
bytes.length, bytes.length,
declaringClass.getClassLoader()).newInstance(); declaringClass.getClassLoader()).newInstance();
} catch (InstantiationException | } catch (InstantiationException | IllegalAccessException e) {
IllegalAccessException e) { throw new InternalError(e);
throw (InternalError)
new InternalError().initCause(e);
} }
} }
}); });
......
...@@ -1401,8 +1401,7 @@ public class X500Name implements GeneralNameInterface, Principal { ...@@ -1401,8 +1401,7 @@ public class X500Name implements GeneralNameInterface, Principal {
principalConstructor = constr; principalConstructor = constr;
principalField = (Field)result[1]; principalField = (Field)result[1];
} catch (Exception e) { } catch (Exception e) {
throw (InternalError)new InternalError("Could not obtain " throw new InternalError("Could not obtain X500Principal access", e);
+ "X500Principal access").initCause(e);
} }
} }
......
...@@ -208,7 +208,7 @@ public class ProxyClient implements JConsoleContext { ...@@ -208,7 +208,7 @@ public class ProxyClient implements JConsoleContext {
serverStubClass = Class.forName(rmiServerImplStubClassName).asSubclass(Remote.class); serverStubClass = Class.forName(rmiServerImplStubClassName).asSubclass(Remote.class);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// should never reach here // should never reach here
throw (InternalError) new InternalError(e.getMessage()).initCause(e); throw new InternalError(e.getMessage(), e);
} }
rmiServerImplStubClass = serverStubClass; rmiServerImplStubClass = serverStubClass;
} }
...@@ -395,18 +395,10 @@ public class ProxyClient implements JConsoleContext { ...@@ -395,18 +395,10 @@ public class ProxyClient implements JConsoleContext {
} catch (MalformedObjectNameException e) { } catch (MalformedObjectNameException e) {
// should not reach here // should not reach here
throw new InternalError(e.getMessage()); throw new InternalError(e.getMessage());
} catch (IntrospectionException e) { } catch (IntrospectionException |
InternalError ie = new InternalError(e.getMessage()); InstanceNotFoundException |
ie.initCause(e); ReflectionException e) {
throw ie; throw new InternalError(e.getMessage(), e);
} 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;
} }
if (hasPlatformMXBeans) { if (hasPlatformMXBeans) {
......
...@@ -55,9 +55,7 @@ public class WindowsAsynchronousFileChannelImpl ...@@ -55,9 +55,7 @@ public class WindowsAsynchronousFileChannelImpl
try { try {
return new Iocp(null, ThreadPool.createDefault()).start(); return new Iocp(null, ThreadPool.createDefault()).start();
} catch (IOException ioe) { } catch (IOException ioe) {
InternalError e = new InternalError(); throw new InternalError(ioe);
e.initCause(ioe);
throw e;
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册