This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 9b773c025172253bde78c675a2f3327a0201ba2c Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Jul 8 10:58:45 2019 +0100 Clean-up. Whitespace. Braces. Use service. Use ReflectiveOperationException. Use interfaces rather than concrete types. Improves alignment with 9.0.x. --- .../apache/catalina/core/ApplicationContext.java | 113 +++++++++------------ 1 file changed, 46 insertions(+), 67 deletions(-) diff --git a/java/org/apache/catalina/core/ApplicationContext.java b/java/org/apache/catalina/core/ApplicationContext.java index 9d9f306..250061a 100644 --- a/java/org/apache/catalina/core/ApplicationContext.java +++ b/java/org/apache/catalina/core/ApplicationContext.java @@ -182,8 +182,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S /** * The string manager for this package. */ - private static final StringManager sm = - StringManager.getManager(Constants.Package); + private static final StringManager sm = StringManager.getManager(Constants.Package); /** @@ -264,7 +263,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S pathMB.setString(uri); MappingData mappingData = new MappingData(); - ((Engine) host.getParent()).getService().getMapper().map(hostMB, pathMB, null, mappingData); + service.getMapper().map(hostMB, pathMB, null, mappingData); child = mappingData.context; } } catch (Throwable t) { @@ -596,8 +595,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S return null; } if (!path.startsWith("/")) { - throw new IllegalArgumentException - (sm.getString("applicationContext.resourcePaths.iae", path)); + throw new IllegalArgumentException (sm.getString("applicationContext.resourcePaths.iae", path)); } WebResourceRoot resources = context.getResources(); @@ -678,26 +676,23 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S // Notify interested application event listeners Object listeners[] = context.getApplicationEventListeners(); - if ((listeners == null) || (listeners.length == 0)) + if ((listeners == null) || (listeners.length == 0)) { return; - ServletContextAttributeEvent event = - new ServletContextAttributeEvent(context.getServletContext(), - name, value); + } + ServletContextAttributeEvent event = new ServletContextAttributeEvent( + context.getServletContext(), name, value); for (int i = 0; i < listeners.length; i++) { - if (!(listeners[i] instanceof ServletContextAttributeListener)) + if (!(listeners[i] instanceof ServletContextAttributeListener)) { continue; - ServletContextAttributeListener listener = - (ServletContextAttributeListener) listeners[i]; + } + ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners[i]; try { - context.fireContainerEvent("beforeContextAttributeRemoved", - listener); + context.fireContainerEvent("beforeContextAttributeRemoved", listener); listener.attributeRemoved(event); - context.fireContainerEvent("afterContextAttributeRemoved", - listener); + context.fireContainerEvent("afterContextAttributeRemoved", listener); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); - context.fireContainerEvent("afterContextAttributeRemoved", - listener); + context.fireContainerEvent("afterContextAttributeRemoved", listener); // FIXME - should we do anything besides log these? log(sm.getString("applicationContext.attributeEvent"), t); } @@ -709,8 +704,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S public void setAttribute(String name, Object value) { // Name cannot be null if (name == null) { - throw new NullPointerException - (sm.getString("applicationContext.setAttribute.namenull")); + throw new NullPointerException(sm.getString("applicationContext.setAttribute.namenull")); } // Null value is the same as removeAttribute() @@ -721,53 +715,47 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S // Add or replace the specified attribute // Check for read only attribute - if (readOnlyAttributes.containsKey(name)) + if (readOnlyAttributes.containsKey(name)) { return; + } Object oldValue = attributes.put(name, value); boolean replaced = oldValue != null; // Notify interested application event listeners Object listeners[] = context.getApplicationEventListeners(); - if ((listeners == null) || (listeners.length == 0)) + if ((listeners == null) || (listeners.length == 0)) { return; + } ServletContextAttributeEvent event = null; - if (replaced) - event = - new ServletContextAttributeEvent(context.getServletContext(), - name, oldValue); - else - event = - new ServletContextAttributeEvent(context.getServletContext(), - name, value); + if (replaced) { + event = new ServletContextAttributeEvent(context.getServletContext(), name, oldValue); + } else { + event = new ServletContextAttributeEvent(context.getServletContext(), name, value); + } for (int i = 0; i < listeners.length; i++) { - if (!(listeners[i] instanceof ServletContextAttributeListener)) + if (!(listeners[i] instanceof ServletContextAttributeListener)) { continue; - ServletContextAttributeListener listener = - (ServletContextAttributeListener) listeners[i]; + } + ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners[i]; try { if (replaced) { - context.fireContainerEvent - ("beforeContextAttributeReplaced", listener); + context.fireContainerEvent("beforeContextAttributeReplaced", listener); listener.attributeReplaced(event); - context.fireContainerEvent("afterContextAttributeReplaced", - listener); + context.fireContainerEvent("afterContextAttributeReplaced", listener); } else { - context.fireContainerEvent("beforeContextAttributeAdded", - listener); + context.fireContainerEvent("beforeContextAttributeAdded", listener); listener.attributeAdded(event); - context.fireContainerEvent("afterContextAttributeAdded", - listener); + context.fireContainerEvent("afterContextAttributeAdded", listener); } } catch (Throwable t) { ExceptionUtils.handleThrowable(t); - if (replaced) - context.fireContainerEvent("afterContextAttributeReplaced", - listener); - else - context.fireContainerEvent("afterContextAttributeAdded", - listener); + if (replaced) { + context.fireContainerEvent("afterContextAttributeReplaced", listener); + } else { + context.fireContainerEvent("afterContextAttributeAdded", listener); + } // FIXME - should we do anything besides log these? log(sm.getString("applicationContext.attributeEvent"), t); } @@ -844,8 +832,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S } catch (InvocationTargetException e) { ExceptionUtils.handleThrowable(e.getCause()); throw new ServletException(e); - } catch (IllegalAccessException | NamingException | InstantiationException | - ClassNotFoundException | NoSuchMethodException e) { + } catch (ReflectiveOperationException | NamingException e) { throw new ServletException(e); } } @@ -981,8 +968,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S @Override - public <T extends Servlet> T createServlet(Class<T> c) - throws ServletException { + public <T extends Servlet> T createServlet(Class<T> c) throws ServletException { try { @SuppressWarnings("unchecked") T servlet = (T) context.getInstanceManager().newInstance(c.getName()); @@ -991,8 +977,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S } catch (InvocationTargetException e) { ExceptionUtils.handleThrowable(e.getCause()); throw new ServletException(e); - } catch (IllegalAccessException | NamingException | InstantiationException | - ClassNotFoundException | NoSuchMethodException e) { + } catch (ReflectiveOperationException | NamingException e) { throw new ServletException(e); } } @@ -1027,8 +1012,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S // SSL not enabled by default as it can only used on its own // Context > Host > Engine > Service - Service s = ((Engine) context.getParent().getParent()).getService(); - Connector[] connectors = s.findConnectors(); + Connector[] connectors = service.findConnectors(); // Need at least one SSL enabled connector to use the SSL session ID. for (Connector connector : connectors) { if (Boolean.TRUE.equals(connector.getAttribute("SSLEnabled"))) { @@ -1089,8 +1073,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S public boolean setInitParameter(String name, String value) { // Name cannot be null if (name == null) { - throw new NullPointerException - (sm.getString("applicationContext.setAttribute.namenull")); + throw new NullPointerException(sm.getString("applicationContext.setAttribute.namenull")); } if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException( @@ -1137,8 +1120,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.cnfe", className), e); - } catch (IllegalAccessException | NamingException | InstantiationException | - ClassNotFoundException | NoSuchMethodException e) { + } catch (ReflectiveOperationException| NamingException e) { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.cnfe", className), e); @@ -1165,9 +1147,8 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S match = true; } - if (t instanceof HttpSessionListener - || (t instanceof ServletContextListener && - newServletContextListenerAllowed)) { + if (t instanceof HttpSessionListener || + (t instanceof ServletContextListener && newServletContextListenerAllowed)) { // Add listener directly to the list of instances rather than to // the list of class names. context.addApplicationLifecycleListener(t); @@ -1193,8 +1174,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S throws ServletException { try { @SuppressWarnings("unchecked") - T listener = - (T) context.getInstanceManager().newInstance(c); + T listener = (T) context.getInstanceManager().newInstance(c); if (listener instanceof ServletContextListener || listener instanceof ServletContextAttributeListener || listener instanceof ServletRequestListener || @@ -1210,8 +1190,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S } catch (InvocationTargetException e) { ExceptionUtils.handleThrowable(e.getCause()); throw new ServletException(e); - } catch (IllegalAccessException | NamingException | InstantiationException | - NoSuchMethodException e) { + } catch (ReflectiveOperationException | NamingException e) { throw new ServletException(e); } } @@ -1387,7 +1366,7 @@ public class ApplicationContext implements org.apache.catalina.servlet4preview.S protected void clearAttributes() { // Create list of attributes to be removed - ArrayList<String> list = new ArrayList<>(); + List<String> list = new ArrayList<>(); for (String s : attributes.keySet()) { list.add(s); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org