Skip to content

Commit 1c45c8a

Browse files
turbanoffSerguei Spitsyn
authored andcommitted
8274757: Cleanup unnecessary calls to Throwable.initCause() in java.management module
Reviewed-by: dfuchs, sspitsyn
1 parent c06df25 commit 1c45c8a

File tree

10 files changed

+18
-50
lines changed

10 files changed

+18
-50
lines changed

src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnectionImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,8 +1648,7 @@ public ClassLoader run() throws Exception {
16481648
*/
16491649
private static IOException newIOException(String message,
16501650
Throwable cause) {
1651-
final IOException x = new IOException(message);
1652-
return EnvHelp.initCause(x,cause);
1651+
return new IOException(message, cause);
16531652
}
16541653

16551654
/**

src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnector.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public synchronized void connect(Map<String,?> environment)
367367
} catch (NamingException e) {
368368
final String msg = "Failed to retrieve RMIServer stub: " + e;
369369
if (tracing) logger.trace("connect",idstr + " " + msg);
370-
throw EnvHelp.initCause(new IOException(msg),e);
370+
throw new IOException(msg, e);
371371
}
372372
}
373373

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

src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnectorServer.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -420,8 +420,7 @@ public synchronized void start() throws IOException {
420420
try {
421421
mbsf = new MBeanServerFileAccessController(accessFile);
422422
} catch (IOException e) {
423-
throw EnvHelp.initCause(
424-
new IllegalArgumentException(e.getMessage()), e);
423+
throw new IllegalArgumentException(e.getMessage(), e);
425424
}
426425
// Set the MBeanServerForwarder
427426
//
@@ -434,9 +433,7 @@ public synchronized void start() throws IOException {
434433
defaultClassLoader = EnvHelp.resolveServerClassLoader(
435434
attributes, getMBeanServer());
436435
} catch (InstanceNotFoundException infc) {
437-
IllegalArgumentException x = new
438-
IllegalArgumentException("ClassLoader not found: "+infc);
439-
throw EnvHelp.initCause(x,infc);
436+
throw new IllegalArgumentException("ClassLoader not found: " + infc, infc);
440437
}
441438

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

838834

src/java.management/share/classes/com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import com.sun.jmx.mbeanserver.Util;
3939
import com.sun.jmx.remote.util.EnvHelp;
4040

41-
import java.io.ObjectInputStream;
4241
import java.lang.ref.WeakReference;
4342
import java.security.AccessControlContext;
4443
import java.security.AccessController;
@@ -80,7 +79,6 @@
8079
import javax.management.NotificationListener;
8180
import javax.management.ObjectInstance;
8281
import javax.management.ObjectName;
83-
import javax.management.OperationsException;
8482
import javax.management.QueryEval;
8583
import javax.management.QueryExp;
8684
import javax.management.ReflectionException;
@@ -208,8 +206,7 @@ public ObjectInstance createMBean(String className, ObjectName name,
208206
} catch (InstanceNotFoundException e) {
209207
/* Can only happen if loaderName doesn't exist, but we just
210208
passed null, so we shouldn't get this exception. */
211-
throw EnvHelp.initCause(
212-
new IllegalArgumentException("Unexpected exception: " + e), e);
209+
throw new IllegalArgumentException("Unexpected exception: " + e, e);
213210
}
214211
}
215212

src/java.management/share/classes/com/sun/jmx/remote/internal/ArrayNotificationBuffer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,9 @@ private void createListeners() {
610610
logger.debug("createListeners", "added creationListener");
611611
} catch (Exception e) {
612612
final String msg = "Can't add listener to MBean server delegate: ";
613-
RuntimeException re = new IllegalArgumentException(msg + e);
614-
EnvHelp.initCause(re, e);
615613
logger.fine("createListeners", msg + e);
616614
logger.debug("createListeners", e);
617-
throw re;
615+
throw new IllegalArgumentException(msg + e, e);
618616
}
619617

620618
/* Spec doesn't say whether Set returned by QueryNames can be modified

src/java.management/share/classes/com/sun/jmx/remote/internal/ClientNotifForwarder.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151

5252
import com.sun.jmx.remote.util.ClassLogger;
5353
import com.sun.jmx.remote.util.EnvHelp;
54-
import java.lang.reflect.UndeclaredThrowableException;
5554
import java.util.concurrent.RejectedExecutionException;
5655

5756

@@ -340,9 +339,7 @@ public synchronized void postReconnection(ClientListenerInfo[] listenerInfos)
340339
try {
341340
wait();
342341
} catch (InterruptedException ire) {
343-
IOException ioe = new IOException(ire.toString());
344-
EnvHelp.initCause(ioe, ire);
345-
throw ioe;
342+
throw new IOException(ire.toString(), ire);
346343
}
347344
}
348345

@@ -381,9 +378,7 @@ public synchronized void postReconnection(ClientListenerInfo[] listenerInfos)
381378
try {
382379
wait();
383380
} catch (InterruptedException ire) {
384-
IOException ioe = new IOException(ire.toString());
385-
EnvHelp.initCause(ioe, ire);
386-
throw ioe;
381+
throw new IOException(ire.toString(), ire);
387382
}
388383
}
389384

@@ -821,10 +816,7 @@ private synchronized void init(boolean reconnected) throws IOException {
821816
try {
822817
wait();
823818
} catch (InterruptedException ire) {
824-
IOException ioe = new IOException(ire.toString());
825-
EnvHelp.initCause(ioe, ire);
826-
827-
throw ioe;
819+
throw new IOException(ire.toString(), ire);
828820
}
829821
}
830822

@@ -901,10 +893,7 @@ private synchronized void beforeRemove() throws IOException {
901893
try {
902894
wait();
903895
} catch (InterruptedException ire) {
904-
IOException ioe = new IOException(ire.toString());
905-
EnvHelp.initCause(ioe, ire);
906-
907-
throw ioe;
896+
throw new IOException(ire.toString(), ire);
908897
}
909898
}
910899

src/java.management/share/classes/com/sun/jmx/remote/internal/ServerNotifForwarder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ public Boolean run() throws InstanceNotFoundException {
121121
name.getKeyPropertyList());
122122
} catch (MalformedObjectNameException mfoe) {
123123
// impossible, but...
124-
IOException ioe = new IOException(mfoe.getMessage());
125-
ioe.initCause(mfoe);
126-
throw ioe;
124+
throw new IOException(mfoe.getMessage(), mfoe);
127125
}
128126
}
129127

src/java.management/share/classes/com/sun/jmx/remote/security/JMXPluggableAuthenticator.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import javax.security.auth.login.LoginException;
4545
import javax.security.auth.spi.LoginModule;
4646
import com.sun.jmx.remote.util.ClassLogger;
47-
import com.sun.jmx.remote.util.EnvHelp;
4847

4948
/**
5049
* <p>This class represents a
@@ -228,9 +227,7 @@ private static void authenticationFailure(String method,
228227
se = (SecurityException) exception;
229228
} else {
230229
msg = "Authentication failed! " + exception.getMessage();
231-
final SecurityException e = new SecurityException(msg);
232-
EnvHelp.initCause(e, exception);
233-
se = e;
230+
se = new SecurityException(msg, exception);
234231
}
235232
logException(method, msg, se);
236233
throw se;

src/java.management/share/classes/javax/management/openmbean/OpenMBeanAttributeInfoSupport.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,8 +27,6 @@
2727
package javax.management.openmbean;
2828

2929

30-
// java import
31-
//
3230
import java.lang.reflect.Array;
3331
import java.lang.reflect.Constructor;
3432
import java.lang.reflect.Method;
@@ -44,7 +42,6 @@
4442
import javax.management.DescriptorRead;
4543
import javax.management.ImmutableDescriptor;
4644
import javax.management.MBeanAttributeInfo;
47-
import com.sun.jmx.remote.util.EnvHelp;
4845
import sun.reflect.misc.MethodUtil;
4946
import sun.reflect.misc.ReflectUtil;
5047

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

src/java.management/share/classes/javax/management/remote/JMXConnectorFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,7 @@ public boolean test(Provider<P> sp) {
619619
if (e instanceof IOException) {
620620
exception = (IOException) e;
621621
} else {
622-
exception = EnvHelp.initCause(
623-
new IOException(e.getMessage()), e);
622+
exception = new IOException(e.getMessage(), e);
624623
}
625624
}
626625
}

0 commit comments

Comments
 (0)