8284673: Collapse identical catch branches in java.management

Reviewed-by: cjplummer, dholmes
This commit is contained in:
Andrey Turbanov 2022-04-13 17:47:35 +00:00
parent c7755b815d
commit 249d54f93d
10 changed files with 57 additions and 170 deletions

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, 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
@ -735,9 +735,7 @@ public class DefaultMBeanServerInterceptor implements MBeanServerInterceptor {
try {
instance.setAttribute(attribute);
} catch (AttributeNotFoundException e) {
throw e;
} catch (InvalidAttributeValueException e) {
} catch (AttributeNotFoundException | InvalidAttributeValueException e) {
throw e;
} catch (Throwable t) {
rethrowMaybeMBeanException(t);
@ -821,11 +819,7 @@ public class DefaultMBeanServerInterceptor implements MBeanServerInterceptor {
throws ReflectionException {
try {
throw t;
} catch (ReflectionException e) {
throw e;
} catch (RuntimeOperationsException e) {
throw e;
} catch (RuntimeErrorException e) {
} catch (ReflectionException | RuntimeOperationsException | RuntimeErrorException e) {
throw e;
} catch (RuntimeException e) {
throw new RuntimeMBeanException(e, e.toString());
@ -1356,9 +1350,7 @@ public class DefaultMBeanServerInterceptor implements MBeanServerInterceptor {
final MBeanInfo mbi;
try {
mbi = moi.getMBeanInfo();
} catch (RuntimeMBeanException e) {
throw e;
} catch (RuntimeErrorException e) {
} catch (RuntimeMBeanException | RuntimeErrorException e) {
throw e;
} catch (RuntimeException e) {
throw new RuntimeMBeanException(e,

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, 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
@ -243,13 +243,7 @@ public class MBeanInstantiator {
throw new ReflectionException(new
NoSuchMethodException("No constructor"),
"No such constructor");
} catch (InstantiationException e) {
throw new ReflectionException(e,
"Exception thrown trying to invoke the MBean's empty constructor");
} catch (IllegalAccessException e) {
throw new ReflectionException(e,
"Exception thrown trying to invoke the MBean's empty constructor");
} catch (IllegalArgumentException e) {
} catch (InstantiationException | IllegalArgumentException | IllegalAccessException e) {
throw new ReflectionException(e,
"Exception thrown trying to invoke the MBean's empty constructor");
}
@ -308,11 +302,7 @@ public class MBeanInstantiator {
NoSuchMethodException("No such constructor found"),
"No such constructor" );
}
catch (InstantiationException e) {
throw new ReflectionException(e,
"Exception thrown trying to invoke the MBean's constructor");
}
catch (IllegalAccessException e) {
catch (InstantiationException | IllegalAccessException e) {
throw new ReflectionException(e,
"Exception thrown trying to invoke the MBean's constructor");
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2022, 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
@ -167,12 +167,8 @@ final class MBeanServerDelegateImpl
else
throw new AttributeNotFoundException("null");
} catch (AttributeNotFoundException x) {
} catch (AttributeNotFoundException | JMRuntimeException | SecurityException x) {
throw x;
} catch (JMRuntimeException j) {
throw j;
} catch (SecurityException s) {
throw s;
} catch (Exception x) {
throw new MBeanException(x,"Failed to get " + attribute);
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2022, 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
@ -133,11 +133,8 @@ public final class JMXPluggableAuthenticator implements JMXAuthenticator {
}
}
} catch (LoginException le) {
authenticationFailure("authenticate", le);
} catch (SecurityException se) {
authenticationFailure("authenticate", se);
} catch (LoginException | SecurityException e) {
authenticationFailure("authenticate", e);
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, 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
@ -1175,9 +1175,7 @@ public class ObjectName implements Comparable<ObjectName>, QueryExp {
try {
construct(cn);
} catch (NullPointerException e) {
throw new InvalidObjectException(e.toString());
} catch (MalformedObjectNameException e) {
} catch (NullPointerException | MalformedObjectNameException e) {
throw new InvalidObjectException(e.toString());
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, 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
@ -1224,13 +1224,7 @@ public class MLet extends java.net.URLClassLoader
Object serObject = ois.readObject();
ois.close();
return serObject;
} catch (IOException e) {
if (MLET_LOGGER.isLoggable(Level.DEBUG)) {
MLET_LOGGER.log(Level.DEBUG,
"Exception while deserializing " + filename, e);
}
throw e;
} catch (ClassNotFoundException e) {
} catch (IOException | ClassNotFoundException e) {
if (MLET_LOGGER.isLoggable(Level.DEBUG)) {
MLET_LOGGER.log(Level.DEBUG,
"Exception while deserializing " + filename, e);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, 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
@ -1176,9 +1176,7 @@ public class RequiredModelMBean
try {
ReflectUtil.checkPackageAccess(method.getDeclaringClass());
return MethodUtil.invoke(method, targetObject, opArgs);
} catch (InvocationTargetException e) {
caughtException[0] = e;
} catch (IllegalAccessException e) {
} catch (InvocationTargetException | IllegalAccessException e) {
caughtException[0] = e;
}
return null;
@ -1192,10 +1190,6 @@ public class RequiredModelMBean
}
}
return rslt;
} catch (RuntimeErrorException ree) {
throw new RuntimeOperationsException(ree,
"RuntimeException occurred in RequiredModelMBean "+
"while trying to invoke operation " + opName);
} catch (RuntimeException re) {
throw new RuntimeOperationsException(re,
"RuntimeException occurred in RequiredModelMBean "+
@ -1649,10 +1643,8 @@ public class RequiredModelMBean
"attribute value through a RequiredModelMBean");
}
} catch (MBeanException mbe) {
throw mbe;
} catch (AttributeNotFoundException t) {
throw t;
} catch (MBeanException | AttributeNotFoundException e) {
throw e;
} catch (Exception e) {
if (tracing) {
MODELMBEAN_LOGGER.log(Level.TRACE,
@ -2246,9 +2238,7 @@ public class RequiredModelMBean
try {
if (info == null) return false;
else return (info.getNotification(notifName)!=null);
} catch (MBeanException x) {
return false;
} catch (RuntimeOperationsException r) {
} catch (MBeanException | RuntimeOperationsException x) {
return false;
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, 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
@ -1204,45 +1204,15 @@ public abstract class Monitor
MONITOR_LOGGER.log(Level.TRACE, msg);
MONITOR_LOGGER.log(Level.TRACE, anf_ex::toString);
}
} catch (MBeanException mb_ex) {
} catch (MBeanException | ReflectionException| IOException | RuntimeException e) {
if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
return;
else {
notifType = RUNTIME_ERROR;
setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
msg = mb_ex.getMessage() == null ? "" : mb_ex.getMessage();
msg = e.getMessage() == null ? "" : e.getMessage();
MONITOR_LOGGER.log(Level.TRACE, msg);
MONITOR_LOGGER.log(Level.TRACE, mb_ex::toString);
}
} catch (ReflectionException ref_ex) {
if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED)) {
return;
} else {
notifType = RUNTIME_ERROR;
setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
msg = ref_ex.getMessage() == null ? "" : ref_ex.getMessage();
MONITOR_LOGGER.log(Level.TRACE, msg);
MONITOR_LOGGER.log(Level.TRACE, ref_ex::toString);
}
} catch (IOException io_ex) {
if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
return;
else {
notifType = RUNTIME_ERROR;
setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
msg = io_ex.getMessage() == null ? "" : io_ex.getMessage();
MONITOR_LOGGER.log(Level.TRACE, msg);
MONITOR_LOGGER.log(Level.TRACE, io_ex::toString);
}
} catch (RuntimeException rt_ex) {
if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
return;
else {
notifType = RUNTIME_ERROR;
setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
msg = rt_ex.getMessage() == null ? "" : rt_ex.getMessage();
MONITOR_LOGGER.log(Level.TRACE, msg);
MONITOR_LOGGER.log(Level.TRACE, rt_ex::toString);
MONITOR_LOGGER.log(Level.TRACE, e::toString);
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, 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
@ -31,7 +31,6 @@ import static com.sun.jmx.mbeanserver.Util.cast;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -666,10 +665,8 @@ public class RelationService extends NotificationBroadcasterSupport
} catch (MBeanException exc1) {
throw new RuntimeException(
(exc1.getTargetException()).getMessage());
} catch (ReflectionException exc2) {
} catch (ReflectionException | AttributeNotFoundException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (AttributeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
}
if (relId == null) {
@ -690,10 +687,8 @@ public class RelationService extends NotificationBroadcasterSupport
} catch (MBeanException exc1) {
throw new RuntimeException(
(exc1.getTargetException()).getMessage());
} catch (ReflectionException exc2) {
} catch (ReflectionException | AttributeNotFoundException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (AttributeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
}
boolean badRelServFlag = false;
@ -719,10 +714,8 @@ public class RelationService extends NotificationBroadcasterSupport
} catch (MBeanException exc1) {
throw new RuntimeException(
(exc1.getTargetException()).getMessage());
}catch (ReflectionException exc2) {
}catch (ReflectionException | AttributeNotFoundException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (AttributeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
}
if (relTypeName == null) {
String excMsg = "No relation type provided.";
@ -1534,10 +1527,8 @@ public class RelationService extends NotificationBroadcasterSupport
handleReferenceUnregistration(currRelId,
unregMBeanName,
localRoleNameList);
} catch (RelationNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (RoleNotFoundException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (RelationNotFoundException | RoleNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
}
}
@ -1846,12 +1837,10 @@ public class RelationService extends NotificationBroadcasterSupport
result = invokeResult;
else
result = new ArrayList<ObjectName>(invokeResult);
} catch (InstanceNotFoundException exc1) {
} catch (InstanceNotFoundException | ReflectionException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
} catch (MBeanException exc2) {
Exception wrappedExc = exc2.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
throw ((RoleNotFoundException)wrappedExc);
} else {
@ -1926,13 +1915,11 @@ public class RelationService extends NotificationBroadcasterSupport
"getRoles",
params,
signature));
} catch (InstanceNotFoundException exc1) {
} catch (InstanceNotFoundException | ReflectionException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
} catch (MBeanException exc2) {
throw new
RuntimeException((exc3.getTargetException()).getMessage());
RuntimeException((exc2.getTargetException()).getMessage());
}
}
@ -2043,12 +2030,10 @@ public class RelationService extends NotificationBroadcasterSupport
"getRoleCardinality",
params,
signature));
} catch (InstanceNotFoundException exc1) {
} catch (InstanceNotFoundException | ReflectionException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
} catch (MBeanException exc2) {
Exception wrappedExc = exc2.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
throw ((RoleNotFoundException)wrappedExc);
} else {
@ -2148,10 +2133,9 @@ public class RelationService extends NotificationBroadcasterSupport
myMBeanServer.setAttribute(((ObjectName)relObj),
new Attribute("Role", role));
} catch (InstanceNotFoundException exc1) {
} catch (InstanceNotFoundException | ReflectionException |
AttributeNotFoundException | InvalidAttributeValueException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (MBeanException exc2) {
Exception wrappedExc = exc2.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
@ -2162,10 +2146,6 @@ public class RelationService extends NotificationBroadcasterSupport
throw new RuntimeException(wrappedExc.getMessage());
}
} catch (AttributeNotFoundException exc4) {
throw new RuntimeException(exc4.getMessage());
} catch (InvalidAttributeValueException exc5) {
throw new RuntimeException(exc5.getMessage());
}
}
@ -2244,10 +2224,8 @@ public class RelationService extends NotificationBroadcasterSupport
"setRoles",
params,
signature));
} catch (InstanceNotFoundException exc1) {
} catch (InstanceNotFoundException | ReflectionException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (MBeanException exc2) {
throw new
RuntimeException((exc2.getTargetException()).getMessage());
@ -3287,12 +3265,9 @@ public class RelationService extends NotificationBroadcasterSupport
try {
relationObj.setRoleInt(role, true, this, false);
} catch (RoleNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (RelationNotFoundException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (RelationTypeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (RoleNotFoundException | RelationTypeNotFoundException |
RelationNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
@ -3317,10 +3292,9 @@ public class RelationService extends NotificationBroadcasterSupport
myMBeanServer.setAttribute(relationObjName,
new Attribute("Role", role));
} catch (InstanceNotFoundException exc1) {
} catch (InstanceNotFoundException | InvalidAttributeValueException |
AttributeNotFoundException | ReflectionException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (MBeanException exc2) {
Exception wrappedExc = exc2.getTargetException();
if (wrappedExc instanceof InvalidRoleValueException) {
@ -3328,10 +3302,6 @@ public class RelationService extends NotificationBroadcasterSupport
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
} catch (AttributeNotFoundException exc4) {
throw new RuntimeException(exc4.getMessage());
} catch (InvalidAttributeValueException exc5) {
throw new RuntimeException(exc5.getMessage());
}
}
}
@ -3620,10 +3590,8 @@ public class RelationService extends NotificationBroadcasterSupport
try {
currRoleInfo = getRoleInfo(currRelTypeName,
currRoleName);
} catch (RelationTypeNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (RoleInfoNotFoundException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (RelationTypeNotFoundException | RoleInfoNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
// Checks with expected minimum number of elements
@ -3669,10 +3637,8 @@ public class RelationService extends NotificationBroadcasterSupport
currRoleName,
true,
this);
} catch (RelationTypeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (InvalidRoleValueException exc4) {
throw new RuntimeException(exc4.getMessage());
} catch (RelationTypeNotFoundException | InvalidRoleValueException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
@ -3692,10 +3658,8 @@ public class RelationService extends NotificationBroadcasterSupport
"handleMBeanUnregistration",
params,
signature);
} catch (InstanceNotFoundException exc1) {
} catch (InstanceNotFoundException | ReflectionException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (MBeanException exc2) {
Exception wrappedExc = exc2.getTargetException();
throw new RuntimeException(wrappedExc.getMessage());

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, 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
@ -30,7 +30,6 @@ package javax.management.relation;
import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.List;
@ -1147,14 +1146,11 @@ public class RelationSupport
throw new RuntimeException(wrappedExc.getMessage());
}
} catch (ReflectionException exc3) {
} catch (ReflectionException | RelationTypeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (RelationTypeNotFoundException exc4) {
throw new RuntimeException(exc4.getMessage());
} catch (InstanceNotFoundException exc5) {
throw new RelationServiceNotRegisteredException(exc5.getMessage());
} catch (InstanceNotFoundException exc4) {
throw new RelationServiceNotRegisteredException(exc4.getMessage());
}
Object result = null;