This is an automated email from the ASF dual-hosted git repository. ebourg pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 9ede7c8232d24b93704dbfb76bcc4f6d72d20336 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 | 8 ++--- .../catalina/mbeans/MemoryUserDatabaseMBean.java | 36 ++++++---------------- .../catalina/mbeans/NamingResourcesMBean.java | 18 ++++------- java/org/apache/catalina/mbeans/UserMBean.java | 8 ++--- java/org/apache/coyote/http2/Stream.java | 3 +- java/org/apache/coyote/http2/StreamProcessor.java | 3 +- .../org/apache/jasper/runtime/PageContextImpl.java | 6 ++-- .../tomcat/util/scan/StandardJarScanner.java | 4 +-- 10 files changed, 30 insertions(+), 78 deletions(-) diff --git a/java/jakarta/security/auth/message/config/AuthConfigFactory.java b/java/jakarta/security/auth/message/config/AuthConfigFactory.java index a51c641..f08c125 100644 --- a/java/jakarta/security/auth/message/config/AuthConfigFactory.java +++ b/java/jakarta/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 9c5fea3..783772a 100644 --- a/java/org/apache/catalina/connector/Response.java +++ b/java/org/apache/catalina/connector/Response.java @@ -1596,10 +1596,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)) { @@ -1629,10 +1626,7 @@ public class Response implements HttpServletResponse { encodedURI = AccessController.doPrivileged( new PrivilegedEncodeUrl(urlEncoder, relativePath, pos)); } 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); @@ -1645,10 +1639,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 46a6fc8..134e50d 100644 --- a/java/org/apache/catalina/mbeans/GroupMBean.java +++ b/java/org/apache/catalina/mbeans/GroupMBean.java @@ -68,9 +68,7 @@ public class GroupMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), role); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.createError.role", role)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.createError.role", role), e); } } return results.toArray(new String[0]); @@ -92,9 +90,7 @@ public class GroupMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), user); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.createError.user", user)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.createError.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 c869914..b8fc248 100644 --- a/java/org/apache/catalina/mbeans/MemoryUserDatabaseMBean.java +++ b/java/org/apache/catalina/mbeans/MemoryUserDatabaseMBean.java @@ -136,9 +136,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { try { MBeanUtils.createMBean(group); } catch (Exception e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.createMBeanError.group", groupname)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.createMBeanError.group", groupname), e); } return findGroup(groupname); } @@ -157,9 +155,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { try { MBeanUtils.createMBean(role); } catch (Exception e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.createMBeanError.role", rolename)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.createMBeanError.role", rolename), e); } return findRole(rolename); } @@ -179,9 +175,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { try { MBeanUtils.createMBean(user); } catch (Exception e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.createMBeanError.user", username)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.createMBeanError.user", username), e); } return findUser(username); } @@ -204,9 +198,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managedGroup.getDomain(), group); return oname.toString(); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.createError.group", groupname)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.createError.group", groupname), e); } } @@ -228,9 +220,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managedRole.getDomain(), role); return oname.toString(); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.createError.role", rolename)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.createError.role", rolename), e); } } @@ -253,9 +243,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managedUser.getDomain(), user); return oname.toString(); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.createError.user", username)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.createError.user", username), e); } } @@ -275,9 +263,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { MBeanUtils.destroyMBean(group); database.removeGroup(group); } catch (Exception e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.destroyError.group", groupname)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.destroyError.group", groupname), e); } } @@ -297,9 +283,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { MBeanUtils.destroyMBean(role); database.removeRole(role); } catch (Exception e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.destroyError.role", rolename)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.destroyError.role", rolename), e); } } @@ -319,9 +303,7 @@ public class MemoryUserDatabaseMBean extends BaseModelMBean { MBeanUtils.destroyMBean(user); database.removeUser(user); } catch (Exception e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.destroyError.user", username)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.destroyError.user", username), e); } } } diff --git a/java/org/apache/catalina/mbeans/NamingResourcesMBean.java b/java/org/apache/catalina/mbeans/NamingResourcesMBean.java index 81386e3..efd840c 100644 --- a/java/org/apache/catalina/mbeans/NamingResourcesMBean.java +++ b/java/org/apache/catalina/mbeans/NamingResourcesMBean.java @@ -70,10 +70,8 @@ public class NamingResourcesMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), env); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException( - sm.getString("namingResourcesMBean.createObjectNameError.environment", env)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException( + sm.getString("namingResourcesMBean.createObjectNameError.environment", env), e); } } return results.toArray(new String[0]); @@ -93,10 +91,8 @@ public class NamingResourcesMBean extends BaseModelMBean { ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), contextResource); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException( - sm.getString("namingResourcesMBean.createObjectNameError.resource", contextResource)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException( + sm.getString("namingResourcesMBean.createObjectNameError.resource", contextResource), e); } } return results.toArray(new String[0]); @@ -118,10 +114,8 @@ public class NamingResourcesMBean extends BaseModelMBean { MBeanUtils.createObjectName(managed.getDomain(), resourceLink); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException( - sm.getString("namingResourcesMBean.createObjectNameError.resourceLink", resourceLink)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException( + sm.getString("namingResourcesMBean.createObjectNameError.resourceLink", 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 d552f0e..47f4fb8 100644 --- a/java/org/apache/catalina/mbeans/UserMBean.java +++ b/java/org/apache/catalina/mbeans/UserMBean.java @@ -74,9 +74,7 @@ public class UserMBean extends BaseModelMBean { MBeanUtils.createObjectName(managed.getDomain(), group); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.createError.group", group)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.createError.group", group), e); } } return results.toArray(new String[0]); @@ -99,9 +97,7 @@ public class UserMBean extends BaseModelMBean { MBeanUtils.createObjectName(managed.getDomain(), role); results.add(oname.toString()); } catch (MalformedObjectNameException e) { - IllegalArgumentException iae = new IllegalArgumentException(sm.getString("userMBean.createError.role", role)); - iae.initCause(e); - throw iae; + throw new IllegalArgumentException(sm.getString("userMBean.createError.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 778edfc..65bf087 100644 --- a/java/org/apache/coyote/http2/Stream.java +++ b/java/org/apache/coyote/http2/Stream.java @@ -662,8 +662,7 @@ 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 862ea35..45bce39 100644 --- a/java/org/apache/coyote/http2/StreamProcessor.java +++ b/java/org/apache/coyote/http2/StreamProcessor.java @@ -104,8 +104,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 f5510b2..1310f16 100644 --- a/java/org/apache/jasper/runtime/PageContextImpl.java +++ b/java/org/apache/jasper/runtime/PageContextImpl.java @@ -520,10 +520,8 @@ 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 cd939dd..9a2fb79 100644 --- a/java/org/apache/tomcat/util/scan/StandardJarScanner.java +++ b/java/org/apache/tomcat/util/scan/StandardJarScanner.java @@ -412,9 +412,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