Skip to content
Permalink
Browse files
8274757: Cleanup unnecessary calls to Throwable.initCause() in java.m…
…anagement module

Reviewed-by: dfuchs, sspitsyn
  • Loading branch information
turbanoff authored and Serguei Spitsyn committed Nov 16, 2021
1 parent c06df25 commit 1c45c8a08287e2d8d7574eaa773850b7f0b33207
@@ -1648,8 +1648,7 @@ public ClassLoader run() throws Exception {
*/
private static IOException newIOException(String message,
Throwable cause) {
final IOException x = new IOException(message);
return EnvHelp.initCause(x,cause);
return new IOException(message, cause);
}

/**
@@ -367,7 +367,7 @@ public synchronized void connect(Map<String,?> environment)
} catch (NamingException e) {
final String msg = "Failed to retrieve RMIServer stub: " + e;
if (tracing) logger.trace("connect",idstr + " " + msg);
throw EnvHelp.initCause(new IOException(msg),e);
throw new IOException(msg, e);
}
}

@@ -543,9 +543,7 @@ private synchronized void close(boolean intern) throws IOException {
throw (IOException) closeException;
if (closeException instanceof RuntimeException)
throw (RuntimeException) closeException;
final IOException x =
new IOException("Failed to close: " + closeException);
throw EnvHelp.initCause(x,closeException);
throw new IOException("Failed to close: " + closeException, closeException);
}
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, 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
@@ -420,8 +420,7 @@ public synchronized void start() throws IOException {
try {
mbsf = new MBeanServerFileAccessController(accessFile);
} catch (IOException e) {
throw EnvHelp.initCause(
new IllegalArgumentException(e.getMessage()), e);
throw new IllegalArgumentException(e.getMessage(), e);
}
// Set the MBeanServerForwarder
//
@@ -434,9 +433,7 @@ public synchronized void start() throws IOException {
defaultClassLoader = EnvHelp.resolveServerClassLoader(
attributes, getMBeanServer());
} catch (InstanceNotFoundException infc) {
IllegalArgumentException x = new
IllegalArgumentException("ClassLoader not found: "+infc);
throw EnvHelp.initCause(x,infc);
throw new IllegalArgumentException("ClassLoader not found: " + infc, infc);
}

if (tracing) logger.trace("start", "setting RMIServer object");
@@ -831,8 +828,7 @@ private static String byteArrayToBase64(byte[] a) {
*/
private static IOException newIOException(String message,
Throwable cause) {
final IOException x = new IOException(message);
return EnvHelp.initCause(x,cause);
return new IOException(message, cause);
}


@@ -38,7 +38,6 @@
import com.sun.jmx.mbeanserver.Util;
import com.sun.jmx.remote.util.EnvHelp;

import java.io.ObjectInputStream;
import java.lang.ref.WeakReference;
import java.security.AccessControlContext;
import java.security.AccessController;
@@ -80,7 +79,6 @@
import javax.management.NotificationListener;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.OperationsException;
import javax.management.QueryEval;
import javax.management.QueryExp;
import javax.management.ReflectionException;
@@ -208,8 +206,7 @@ public ObjectInstance createMBean(String className, ObjectName name,
} catch (InstanceNotFoundException e) {
/* Can only happen if loaderName doesn't exist, but we just
passed null, so we shouldn't get this exception. */
throw EnvHelp.initCause(
new IllegalArgumentException("Unexpected exception: " + e), e);
throw new IllegalArgumentException("Unexpected exception: " + e, e);
}
}

@@ -610,11 +610,9 @@ private void createListeners() {
logger.debug("createListeners", "added creationListener");
} catch (Exception e) {
final String msg = "Can't add listener to MBean server delegate: ";
RuntimeException re = new IllegalArgumentException(msg + e);
EnvHelp.initCause(re, e);
logger.fine("createListeners", msg + e);
logger.debug("createListeners", e);
throw re;
throw new IllegalArgumentException(msg + e, e);
}

/* Spec doesn't say whether Set returned by QueryNames can be modified
@@ -51,7 +51,6 @@

import com.sun.jmx.remote.util.ClassLogger;
import com.sun.jmx.remote.util.EnvHelp;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.concurrent.RejectedExecutionException;


@@ -340,9 +339,7 @@ public synchronized void postReconnection(ClientListenerInfo[] listenerInfos)
try {
wait();
} catch (InterruptedException ire) {
IOException ioe = new IOException(ire.toString());
EnvHelp.initCause(ioe, ire);
throw ioe;
throw new IOException(ire.toString(), ire);
}
}

@@ -381,9 +378,7 @@ public synchronized void postReconnection(ClientListenerInfo[] listenerInfos)
try {
wait();
} catch (InterruptedException ire) {
IOException ioe = new IOException(ire.toString());
EnvHelp.initCause(ioe, ire);
throw ioe;
throw new IOException(ire.toString(), ire);
}
}

@@ -821,10 +816,7 @@ private synchronized void init(boolean reconnected) throws IOException {
try {
wait();
} catch (InterruptedException ire) {
IOException ioe = new IOException(ire.toString());
EnvHelp.initCause(ioe, ire);

throw ioe;
throw new IOException(ire.toString(), ire);
}
}

@@ -901,10 +893,7 @@ private synchronized void beforeRemove() throws IOException {
try {
wait();
} catch (InterruptedException ire) {
IOException ioe = new IOException(ire.toString());
EnvHelp.initCause(ioe, ire);

throw ioe;
throw new IOException(ire.toString(), ire);
}
}

@@ -121,9 +121,7 @@ public Boolean run() throws InstanceNotFoundException {
name.getKeyPropertyList());
} catch (MalformedObjectNameException mfoe) {
// impossible, but...
IOException ioe = new IOException(mfoe.getMessage());
ioe.initCause(mfoe);
throw ioe;
throw new IOException(mfoe.getMessage(), mfoe);
}
}

@@ -44,7 +44,6 @@
import javax.security.auth.login.LoginException;
import javax.security.auth.spi.LoginModule;
import com.sun.jmx.remote.util.ClassLogger;
import com.sun.jmx.remote.util.EnvHelp;

/**
* <p>This class represents a
@@ -228,9 +227,7 @@ private static void authenticationFailure(String method,
se = (SecurityException) exception;
} else {
msg = "Authentication failed! " + exception.getMessage();
final SecurityException e = new SecurityException(msg);
EnvHelp.initCause(e, exception);
se = e;
se = new SecurityException(msg, exception);
}
logException(method, msg, se);
throw se;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, 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
@@ -27,8 +27,6 @@
package javax.management.openmbean;


// java import
//
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
@@ -44,7 +42,6 @@
import javax.management.DescriptorRead;
import javax.management.ImmutableDescriptor;
import javax.management.MBeanAttributeInfo;
import com.sun.jmx.remote.util.EnvHelp;
import sun.reflect.misc.MethodUtil;
import sun.reflect.misc.ReflectUtil;

@@ -626,7 +623,7 @@ static <T> T valueFrom(Descriptor d, String name, OpenType<T> openType) {
final String msg =
"Cannot convert descriptor field " + name + " to " +
openType.getTypeName();
throw EnvHelp.initCause(new IllegalArgumentException(msg), e);
throw new IllegalArgumentException(msg, e);
}
}

@@ -619,8 +619,7 @@ public boolean test(Provider<P> sp) {
if (e instanceof IOException) {
exception = (IOException) e;
} else {
exception = EnvHelp.initCause(
new IOException(e.getMessage()), e);
exception = new IOException(e.getMessage(), e);
}
}
}

1 comment on commit 1c45c8a

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 1c45c8a Nov 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.