This is an automated email from the ASF dual-hosted git repository. ebourg pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 85eb58ebe5501742725dc470d339ffc402668280 Author: Emmanuel Bourg <ebo...@apache.org> AuthorDate: Fri Dec 4 01:03:07 2020 +0100 No longer use Throwable.initCause() when possible --- .../auth/message/config/AuthConfigFactory.java | 7 ++-- java/org/apache/catalina/connector/Response.java | 15 ++------ java/org/apache/catalina/mbeans/GroupMBean.java | 10 +---- .../catalina/mbeans/MemoryUserDatabaseMBean.java | 45 +++++----------------- .../catalina/mbeans/NamingResourcesMBean.java | 15 ++------ java/org/apache/catalina/mbeans/UserMBean.java | 10 +---- java/org/apache/coyote/http2/Stream.java | 3 +- java/org/apache/coyote/http2/StreamProcessor.java | 3 +- .../org/apache/jasper/runtime/PageContextImpl.java | 5 +-- .../tomcat/util/scan/StandardJarScanner.java | 4 +- 10 files changed, 26 insertions(+), 91 deletions(-) diff --git a/java/javax/security/auth/message/config/AuthConfigFactory.java b/java/javax/security/auth/message/config/AuthConfigFactory.java index d98b2f2..72a49b4 100644 --- a/java/javax/security/auth/message/config/AuthConfigFactory.java +++ b/java/javax/security/auth/message/config/AuthConfigFactory.java @@ -79,11 +79,10 @@ public abstract class AuthConfigFactory { } catch (PrivilegedActionException e) { Exception inner = e.getException(); if (inner instanceof InstantiationException) { - throw (SecurityException) new SecurityException("AuthConfigFactory error:" + - inner.getCause().getMessage()).initCause(inner.getCause()); + throw new SecurityException("AuthConfigFactory error:" + + inner.getCause().getMessage(), inner.getCause()); } else { - throw (SecurityException) new SecurityException( - "AuthConfigFactory error: " + inner).initCause(inner); + throw new SecurityException("AuthConfigFactory error: " + inner, inner); } } } diff --git a/java/org/apache/catalina/connector/Response.java b/java/org/apache/catalina/connector/Response.java index 4cac2a9..d22cfea 100644 --- a/java/org/apache/catalina/connector/Response.java +++ b/java/org/apache/catalina/connector/Response.java @@ -1627,10 +1627,7 @@ public class Response implements HttpServletResponse { redirectURLCC.append(location, 0, location.length()); return redirectURLCC.toString(); } catch (IOException e) { - IllegalArgumentException iae = - new IllegalArgumentException(location); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(location, e); } } else if (leadingSlash || !UriUtil.hasScheme(location)) { @@ -1667,10 +1664,7 @@ public class Response implements HttpServletResponse { } }); } catch (PrivilegedActionException pae){ - IllegalArgumentException iae = - new IllegalArgumentException(location); - iae.initCause(pae.getException()); - throw iae; + throw new IllegalArgumentException(location, pae.getException()); } } else { encodedURI = urlEncoder.encodeURL(relativePath, 0, pos); @@ -1683,10 +1677,7 @@ public class Response implements HttpServletResponse { normalize(redirectURLCC); } catch (IOException e) { - IllegalArgumentException iae = - new IllegalArgumentException(location); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(location, e); } return redirectURLCC.toString(); diff --git a/java/org/apache/catalina/mbeans/GroupMBean.java b/java/org/apache/catalina/mbeans/GroupMBean.java index 43bf48d..a60aa37 100644 --- a/java/org/apache/catalina/mbeans/GroupMBean.java +++ b/java/org/apache/catalina/mbeans/GroupMBean.java @@ -64,10 +64,7 @@ public class GroupMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), role); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Cannot create object name for role " + role); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Cannot create object name for role " + role, e); } } return results.toArray(new String[0]); @@ -89,10 +86,7 @@ public class GroupMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), user); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Cannot create object name for user " + user); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Cannot create object name for user " + user, e); } } return results.toArray(new String[0]); diff --git a/java/org/apache/catalina/mbeans/MemoryUserDatabaseMBean.java b/java/org/apache/catalina/mbeans/MemoryUserDatabaseMBean.java index 8f85f8f..34be739 100644 --- a/java/org/apache/catalina/mbeans/MemoryUserDatabaseMBean.java +++ b/java/org/apache/catalina/mbeans/MemoryUserDatabaseMBean.java @@ -132,10 +132,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { try { MBeanUtils.createMBean(group); } catch (Exception e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Exception creating group [" + groupname + "] MBean"); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Exception creating group [" + groupname + "] MBean", e); } return findGroup(groupname); } @@ -154,10 +151,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { try { MBeanUtils.createMBean(role); } catch (Exception e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Exception creating role [" + rolename + "] MBean"); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Exception creating role [" + rolename + "] MBean", e); } return findRole(rolename); } @@ -177,10 +171,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { try { MBeanUtils.createMBean(user); } catch (Exception e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Exception creating user [" + username + "] MBean"); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Exception creating user [" + username + "] MBean", e); } return findUser(username); } @@ -203,10 +194,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managedGroup.getDomain(), group); return oname.toString(); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Cannot create object name for group [" + groupname + "]"); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Cannot create object name for group [" + groupname + "]", e); } } @@ -228,10 +216,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managedRole.getDomain(), role); return oname.toString(); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Cannot create object name for role [" + rolename + "]"); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Cannot create object name for role [" + rolename + "]", e); } } @@ -254,10 +239,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managedUser.getDomain(), user); return oname.toString(); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Cannot create object name for user [" + username + "]"); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Cannot create object name for user [" + username + "]", e); } } @@ -277,10 +259,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { MBeanUtils.destroyMBean(group); database.removeGroup(group); } catch (Exception e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Exception destroying group [" + groupname + "] MBean"); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Exception destroying group [" + groupname + "] MBean", e); } } @@ -300,10 +279,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { MBeanUtils.destroyMBean(role); database.removeRole(role); } catch (Exception e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Exception destroying role [" + rolename + "] MBean"); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Exception destroying role [" + rolename + "] MBean", e); } } @@ -323,10 +299,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { MBeanUtils.destroyMBean(user); database.removeUser(user); } catch (Exception e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Exception destroying user [" + username + "] MBean"); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Exception destroying user [" + username + "] MBean", e); } } } diff --git a/java/org/apache/catalina/mbeans/NamingResourcesMBean.java b/java/org/apache/catalina/mbeans/NamingResourcesMBean.java index 79b4022..afffbf1 100644 --- a/java/org/apache/catalina/mbeans/NamingResourcesMBean.java +++ b/java/org/apache/catalina/mbeans/NamingResourcesMBean.java @@ -67,10 +67,7 @@ public class NamingResourcesMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), env); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException ( - "Cannot create object name for environment " + env); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException ("Cannot create object name for environment " + env, e); } } return results.toArray(new String[0]); @@ -90,10 +87,7 @@ public class NamingResourcesMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), contextResource); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Cannot create object name for resource " + contextResource); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Cannot create object name for resource " + contextResource, e); } } return results.toArray(new String[0]); @@ -115,10 +109,7 @@ public class NamingResourcesMBean extends BaseModelMBean { MBeanUtils.createObjectName(managed.getDomain(), resourceLink); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "Cannot create object name for resource " + resourceLink); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Cannot create object name for resource " + resourceLink, e); } } return results.toArray(new String[0]); diff --git a/java/org/apache/catalina/mbeans/UserMBean.java b/java/org/apache/catalina/mbeans/UserMBean.java index 8093813..2d85ee1 100644 --- a/java/org/apache/catalina/mbeans/UserMBean.java +++ b/java/org/apache/catalina/mbeans/UserMBean.java @@ -71,10 +71,7 @@ public class UserMBean extends BaseModelMBean { MBeanUtils.createObjectName(managed.getDomain(), group); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException - ("Cannot create object name for group " + group); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Cannot create object name for group " + group, e); } } return results.toArray(new String[0]); @@ -97,10 +94,7 @@ public class UserMBean extends BaseModelMBean { MBeanUtils.createObjectName(managed.getDomain(), role); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException - ("Cannot create object name for role " + role); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException("Cannot create object name for role " + role, e); } } return results.toArray(new String[0]); diff --git a/java/org/apache/coyote/http2/Stream.java b/java/org/apache/coyote/http2/Stream.java index 28ab46f..d7dad0e 100644 --- a/java/org/apache/coyote/http2/Stream.java +++ b/java/org/apache/coyote/http2/Stream.java @@ -628,8 +628,7 @@ public class Stream extends AbstractNonZeroStream implements HeaderEmitter { handler.sendStreamReset(se); } catch (IOException ioe) { ConnectionException ce = new ConnectionException( - sm.getString("stream.reset.fail"), Http2Error.PROTOCOL_ERROR); - ce.initCause(ioe); + sm.getString("stream.reset.fail"), Http2Error.PROTOCOL_ERROR, ioe); handler.closeConnection(ce); } } else { diff --git a/java/org/apache/coyote/http2/StreamProcessor.java b/java/org/apache/coyote/http2/StreamProcessor.java index c8fc304..ce4871b 100644 --- a/java/org/apache/coyote/http2/StreamProcessor.java +++ b/java/org/apache/coyote/http2/StreamProcessor.java @@ -101,8 +101,7 @@ class StreamProcessor extends AbstractProcessor { if (log.isDebugEnabled()) { log.debug(msg, e); } - ConnectionException ce = new ConnectionException(msg, Http2Error.INTERNAL_ERROR); - ce.initCause(e); + ConnectionException ce = new ConnectionException(msg, Http2Error.INTERNAL_ERROR, e); stream.close(ce); state = SocketState.CLOSED; } finally { diff --git a/java/org/apache/jasper/runtime/PageContextImpl.java b/java/org/apache/jasper/runtime/PageContextImpl.java index 3080546..677217a 100644 --- a/java/org/apache/jasper/runtime/PageContextImpl.java +++ b/java/org/apache/jasper/runtime/PageContextImpl.java @@ -721,10 +721,7 @@ public class PageContextImpl extends PageContext { out.clear(); baseOut.clear(); } catch (IOException ex) { - IllegalStateException ise = new IllegalStateException(Localizer - .getMessage("jsp.error.attempt_to_clear_flushed_buffer")); - ise.initCause(ex); - throw ise; + throw new IllegalStateException(Localizer.getMessage("jsp.error.attempt_to_clear_flushed_buffer"), ex); } // Make sure that the response object is not the wrapper for include diff --git a/java/org/apache/tomcat/util/scan/StandardJarScanner.java b/java/org/apache/tomcat/util/scan/StandardJarScanner.java index 402870d..dc668e5 100644 --- a/java/org/apache/tomcat/util/scan/StandardJarScanner.java +++ b/java/org/apache/tomcat/util/scan/StandardJarScanner.java @@ -414,9 +414,7 @@ public class StandardJarScanner implements JarScanner { } catch (Throwable t) { ExceptionUtils.handleThrowable(t); // Wrap the exception and re-throw - IOException ioe = new IOException(); - ioe.initCause(t); - throw ioe; + throw new IOException(t); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org