This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 9667d29 Code clean-up. Add braces for clarity. 9667d29 is described below commit 9667d291b3bcad0ce22d76911f5ca5e538030f68 Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon May 24 17:24:11 2021 +0100 Code clean-up. Add braces for clarity. --- java/jakarta/servlet/UnavailableException.java | 10 +- java/jakarta/servlet/jsp/tagext/TagInfo.java | 9 +- .../catalina/ant/jmx/JMXAccessorSetTask.java | 6 +- .../apache/catalina/ant/jmx/JMXAccessorTask.java | 47 ++++--- .../authenticator/NonLoginAuthenticator.java | 3 +- .../catalina/authenticator/SavedRequest.java | 5 +- .../authenticator/SpnegoAuthenticator.java | 40 ++++-- java/org/apache/catalina/connector/Response.java | 5 +- .../catalina/core/ApplicationDispatcher.java | 141 ++++++++++++--------- .../apache/catalina/filters/RemoteCIDRFilter.java | 3 +- 10 files changed, 162 insertions(+), 107 deletions(-) diff --git a/java/jakarta/servlet/UnavailableException.java b/java/jakarta/servlet/UnavailableException.java index c5af76d..25aa58b 100644 --- a/java/jakarta/servlet/UnavailableException.java +++ b/java/jakarta/servlet/UnavailableException.java @@ -80,10 +80,11 @@ public class UnavailableException extends ServletException { public UnavailableException(int seconds, Servlet servlet, String msg) { super(msg); this.servlet = servlet; - if (seconds <= 0) + if (seconds <= 0) { this.seconds = -1; - else + } else { this.seconds = seconds; + } permanent = false; } @@ -123,10 +124,11 @@ public class UnavailableException extends ServletException { public UnavailableException(String msg, int seconds) { super(msg); - if (seconds <= 0) + if (seconds <= 0) { this.seconds = -1; - else + } else { this.seconds = seconds; + } servlet = null; permanent = false; } diff --git a/java/jakarta/servlet/jsp/tagext/TagInfo.java b/java/jakarta/servlet/jsp/tagext/TagInfo.java index dcc234d..7ac0fc5 100644 --- a/java/jakarta/servlet/jsp/tagext/TagInfo.java +++ b/java/jakarta/servlet/jsp/tagext/TagInfo.java @@ -97,8 +97,9 @@ public class TagInfo { this.tagVariableInfo = null; this.dynamicAttributes = false; - if (tagExtraInfo != null) + if (tagExtraInfo != null) { tagExtraInfo.setTagInfo(this); + } } /** @@ -151,8 +152,9 @@ public class TagInfo { // Use defaults for unspecified values this.dynamicAttributes = false; - if (tagExtraInfo != null) + if (tagExtraInfo != null) { tagExtraInfo.setTagInfo(this); + } } /** @@ -207,8 +209,9 @@ public class TagInfo { this.tagVariableInfo = tvi; this.dynamicAttributes = dynamicAttributes; - if (tagExtraInfo != null) + if (tagExtraInfo != null) { tagExtraInfo.setTagInfo(this); + } } /** diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java b/java/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java index 74f2201..478b01c 100644 --- a/java/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java +++ b/java/org/apache/catalina/ant/jmx/JMXAccessorSetTask.java @@ -160,8 +160,9 @@ public class JMXAccessorSetTask extends JMXAccessorTask { String mType = getMBeanAttributeType(jmxServerConnection, name, attribute); realValue = convertStringToType(value, mType); - } else + } else { realValue = value; + } } jmxServerConnection.setAttribute(new ObjectName(name), new Attribute( attribute, realValue)); @@ -187,8 +188,9 @@ public class JMXAccessorSetTask extends JMXAccessorTask { MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname); MBeanAttributeInfo attrs[] = minfo.getAttributes(); for (int i = 0; mattrType == null && i < attrs.length; i++) { - if (attribute.equals(attrs[i].getName())) + if (attribute.equals(attrs[i].getName())) { mattrType = attrs[i].getType(); + } } return mattrType; } diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorTask.java b/java/org/apache/catalina/ant/jmx/JMXAccessorTask.java index d79e471..3ef604d 100644 --- a/java/org/apache/catalina/ant/jmx/JMXAccessorTask.java +++ b/java/org/apache/catalina/ant/jmx/JMXAccessorTask.java @@ -358,11 +358,11 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask { String host, String port, String username, String password) throws MalformedURLException, IOException { String urlForJMX; - if (url != null) + if (url != null) { urlForJMX = url; - else - urlForJMX = JMX_SERVICE_PREFIX + host + ":" + port - + JMX_SERVICE_SUFFIX; + } else { + urlForJMX = JMX_SERVICE_PREFIX + host + ":" + port + JMX_SERVICE_SUFFIX; + } Map<String, String[]> environment = null; if (username != null && password != null) { String[] credentials = new String[2]; @@ -513,24 +513,27 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask { * @return The converted object */ protected Object convertStringToType(String value, String valueType) { - if ("java.lang.String".equals(valueType)) + if ("java.lang.String".equals(valueType)) { return value; + } Object convertValue = value; if ("java.lang.Integer".equals(valueType) || "int".equals(valueType)) { try { convertValue = Integer.valueOf(value); } catch (NumberFormatException ex) { - if (isEcho()) + if (isEcho()) { handleErrorOutput("Unable to convert to integer:" + value); + } } } else if ("java.lang.Long".equals(valueType) || "long".equals(valueType)) { try { convertValue = Long.valueOf(value); } catch (NumberFormatException ex) { - if (isEcho()) + if (isEcho()) { handleErrorOutput("Unable to convert to long:" + value); + } } } else if ("java.lang.Boolean".equals(valueType) || "boolean".equals(valueType)) { @@ -540,32 +543,35 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask { try { convertValue = Float.valueOf(value); } catch (NumberFormatException ex) { - if (isEcho()) + if (isEcho()) { handleErrorOutput("Unable to convert to float:" + value); + } } } else if ("java.lang.Double".equals(valueType) || "double".equals(valueType)) { try { convertValue = Double.valueOf(value); } catch (NumberFormatException ex) { - if (isEcho()) + if (isEcho()) { handleErrorOutput("Unable to convert to double:" + value); + } } } else if ("javax.management.ObjectName".equals(valueType) || "name".equals(valueType)) { try { convertValue = new ObjectName(value); } catch (MalformedObjectNameException e) { - if (isEcho()) - handleErrorOutput("Unable to convert to ObjectName:" - + value); + if (isEcho()) { + handleErrorOutput("Unable to convert to ObjectName:" + value); + } } } else if ("java.net.InetAddress".equals(valueType)) { try { convertValue = InetAddress.getByName(value); } catch (UnknownHostException exc) { - if (isEcho()) + if (isEcho()) { handleErrorOutput("Unable to resolve host name:" + value); + } } } return convertValue; @@ -581,8 +587,9 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask { for (int i = 0; i < Array.getLength(result); i++) { handleOutput(name + "." + i + "=" + Array.get(result, i)); } - } else + } else { handleOutput(name + "=" + result); + } } } @@ -610,8 +617,9 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask { * @param result The result */ protected void createProperty(String propertyPrefix, Object result) { - if (propertyPrefix == null) + if (propertyPrefix == null) { propertyPrefix = ""; + } if (result instanceof CompositeDataSupport) { CompositeDataSupport data = (CompositeDataSupport) result; CompositeType compositeType = data.getCompositeType(); @@ -666,9 +674,9 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask { size++; } } - if (size > 0) - setProperty(propertyPrefix + ".Length", Integer - .toString(size)); + if (size > 0) { + setProperty(propertyPrefix + ".Length", Integer.toString(size)); + } } else { setProperty(propertyPrefix, result.toString()); } @@ -696,8 +704,9 @@ public class JMXAccessorTask extends BaseRedirectorHelperTask { */ public boolean setProperty(String property, Object value) { if (property != null) { - if (value == null) + if (value == null) { value = ""; + } if (isEcho()) { handleOutput(property + "=" + value.toString()); } diff --git a/java/org/apache/catalina/authenticator/NonLoginAuthenticator.java b/java/org/apache/catalina/authenticator/NonLoginAuthenticator.java index e49be71..319105e 100644 --- a/java/org/apache/catalina/authenticator/NonLoginAuthenticator.java +++ b/java/org/apache/catalina/authenticator/NonLoginAuthenticator.java @@ -93,8 +93,9 @@ public final class NonLoginAuthenticator extends AuthenticatorBase { // to say the user is now authenticated because access to // protected resources will only be allowed with a matching role. // i.e. SC_FORBIDDEN (403 status) will be generated later. - if (containerLog.isDebugEnabled()) + if (containerLog.isDebugEnabled()) { containerLog.debug("User authenticated without any roles"); + } return true; } diff --git a/java/org/apache/catalina/authenticator/SavedRequest.java b/java/org/apache/catalina/authenticator/SavedRequest.java index 8371578..7bb296e 100644 --- a/java/org/apache/catalina/authenticator/SavedRequest.java +++ b/java/org/apache/catalina/authenticator/SavedRequest.java @@ -82,10 +82,11 @@ public final class SavedRequest { public Iterator<String> getHeaderValues(String name) { List<String> values = headers.get(name); - if (values == null) + if (values == null) { return Collections.emptyIterator(); - else + } else { return values.iterator(); + } } diff --git a/java/org/apache/catalina/authenticator/SpnegoAuthenticator.java b/java/org/apache/catalina/authenticator/SpnegoAuthenticator.java index 16e0b36..8bb3710 100644 --- a/java/org/apache/catalina/authenticator/SpnegoAuthenticator.java +++ b/java/org/apache/catalina/authenticator/SpnegoAuthenticator.java @@ -383,16 +383,34 @@ public class SpnegoAuthenticator extends AuthenticatorBase { // Scan until we find the mech types list. If we find anything // unexpected, abort the fix process. - if (!tag(0x60)) return; - if (!length()) return; - if (!oid("1.3.6.1.5.5.2")) return; - if (!tag(0xa0)) return; - if (!length()) return; - if (!tag(0x30)) return; - if (!length()) return; - if (!tag(0xa0)) return; + if (!tag(0x60)) { + return; + } + if (!length()) { + return; + } + if (!oid("1.3.6.1.5.5.2")) { + return; + } + if (!tag(0xa0)) { + return; + } + if (!length()) { + return; + } + if (!tag(0x30)) { + return; + } + if (!length()) { + return; + } + if (!tag(0xa0)) { + return; + } lengthAsInt(); - if (!tag(0x30)) return; + if (!tag(0x30)) { + return; + } // Now at the start of the mechType list. // Read the mechTypes into an ordered set int mechTypesLen = lengthAsInt(); @@ -458,7 +476,9 @@ public class SpnegoAuthenticator extends AuthenticatorBase { private String oidAsString() { - if (!tag(0x06)) return null; + if (!tag(0x06)) { + return null; + } StringBuilder result = new StringBuilder(); int len = lengthAsInt(); // First byte is special case diff --git a/java/org/apache/catalina/connector/Response.java b/java/org/apache/catalina/connector/Response.java index d6c0e92..652b6b9 100644 --- a/java/org/apache/catalina/connector/Response.java +++ b/java/org/apache/catalina/connector/Response.java @@ -1033,8 +1033,9 @@ public class Response implements HttpServletResponse { char cc=name.charAt(0); if (cc=='C' || cc=='c') { - if (checkSpecialHeader(name, value)) - return; + if (checkSpecialHeader(name, value)) { + return; + } } getCoyoteResponse().addHeader(name, value, charset); diff --git a/java/org/apache/catalina/core/ApplicationDispatcher.java b/java/org/apache/catalina/core/ApplicationDispatcher.java index c83656b..7175449 100644 --- a/java/org/apache/catalina/core/ApplicationDispatcher.java +++ b/java/org/apache/catalina/core/ApplicationDispatcher.java @@ -286,8 +286,9 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher AccessController.doPrivileged(dp); } catch (PrivilegedActionException pe) { Exception e = pe.getException(); - if (e instanceof ServletException) + if (e instanceof ServletException) { throw (ServletException) e; + } throw (IOException) e; } } else { @@ -373,8 +374,9 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher } // This is not a real close in order to support error processing - if (wrapper.getLogger().isDebugEnabled() ) + if (wrapper.getLogger().isDebugEnabled() ) { wrapper.getLogger().debug(" Disabling the response for further output"); + } if (response instanceof ResponseFacade) { ((ResponseFacade) response).finish(); @@ -488,8 +490,9 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher } catch (PrivilegedActionException pe) { Exception e = pe.getException(); - if (e instanceof ServletException) + if (e instanceof ServletException) { throw (ServletException) e; + } throw (IOException) e; } } else { @@ -514,15 +517,13 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher // Handle an HTTP named dispatcher include if (name != null) { - ApplicationHttpRequest wrequest = - (ApplicationHttpRequest) wrapRequest(state); + ApplicationHttpRequest wrequest = (ApplicationHttpRequest) wrapRequest(state); wrequest.setAttribute(Globals.NAMED_DISPATCHER_ATTR, name); - if (servletPath != null) + if (servletPath != null) { wrequest.setServletPath(servletPath); - wrequest.setAttribute(Globals.DISPATCHER_TYPE_ATTR, - DispatcherType.INCLUDE); - wrequest.setAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR, - getCombinedPath()); + } + wrequest.setAttribute(Globals.DISPATCHER_TYPE_ATTR, DispatcherType.INCLUDE); + wrequest.setAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR, getCombinedPath()); invoke(state.outerRequest, state.outerResponse, state); } @@ -532,21 +533,20 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher ApplicationHttpRequest wrequest = (ApplicationHttpRequest) wrapRequest(state); String contextPath = context.getPath(); - if (requestURI != null) - wrequest.setAttribute(RequestDispatcher.INCLUDE_REQUEST_URI, - requestURI); - if (contextPath != null) - wrequest.setAttribute(RequestDispatcher.INCLUDE_CONTEXT_PATH, - contextPath); - if (servletPath != null) - wrequest.setAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH, - servletPath); - if (pathInfo != null) - wrequest.setAttribute(RequestDispatcher.INCLUDE_PATH_INFO, - pathInfo); + if (requestURI != null) { + wrequest.setAttribute(RequestDispatcher.INCLUDE_REQUEST_URI, requestURI); + } + if (contextPath != null) { + wrequest.setAttribute(RequestDispatcher.INCLUDE_CONTEXT_PATH, contextPath); + } + if (servletPath != null) { + wrequest.setAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH, servletPath); + } + if (pathInfo != null) { + wrequest.setAttribute(RequestDispatcher.INCLUDE_PATH_INFO, pathInfo); + } if (queryString != null) { - wrequest.setAttribute(RequestDispatcher.INCLUDE_QUERY_STRING, - queryString); + wrequest.setAttribute(RequestDispatcher.INCLUDE_QUERY_STRING, queryString); wrequest.setQueryParams(queryString); } if (mapping != null) { @@ -573,8 +573,9 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher } catch (PrivilegedActionException pe) { Exception e = pe.getException(); - if (e instanceof ServletException) + if (e instanceof ServletException) { throw (ServletException) e; + } throw (IOException) e; } } else { @@ -654,11 +655,11 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher sm.getString("applicationDispatcher.isUnavailable", wrapper.getName())); long available = wrapper.getAvailable(); - if ((available > 0L) && (available < Long.MAX_VALUE)) + if ((available > 0L) && (available < Long.MAX_VALUE)) { hresponse.setDateHeader("Retry-After", available); - hresponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, sm - .getString("applicationDispatcher.isUnavailable", wrapper - .getName())); + } + hresponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, + sm.getString("applicationDispatcher.isUnavailable", wrapper.getName())); unavailable = true; } @@ -750,13 +751,15 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher recycleRequestWrapper(state); // Rethrow an exception if one was thrown by the invoked servlet - if (ioException != null) + if (ioException != null) { throw ioException; - if (servletException != null) + } + if (servletException != null) { throw servletException; - if (runtimeException != null) + } + if (runtimeException != null) { throw runtimeException; - + } } @@ -765,8 +768,9 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher */ private void unwrapRequest(State state) { - if (state.wrapRequest == null) + if (state.wrapRequest == null) { return; + } if (state.outerRequest.isAsyncStarted()) { if (!state.outerRequest.getAsyncContext().hasOriginalRequestAndResponse()) { @@ -779,18 +783,19 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher while (current != null) { // If we run into the container request we are done - if ((current instanceof Request) - || (current instanceof RequestFacade)) + if ((current instanceof Request) || (current instanceof RequestFacade)) { break; + } // Remove the current request if it is our wrapper if (current == state.wrapRequest) { ServletRequest next = ((ServletRequestWrapper) current).getRequest(); - if (previous == null) + if (previous == null) { state.outerRequest = next; - else + } else { ((ServletRequestWrapper) previous).setRequest(next); + } break; } @@ -807,8 +812,9 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher */ private void unwrapResponse(State state) { - if (state.wrapResponse == null) + if (state.wrapResponse == null) { return; + } if (state.outerRequest.isAsyncStarted()) { if (!state.outerRequest.getAsyncContext().hasOriginalRequestAndResponse()) { @@ -821,18 +827,19 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher while (current != null) { // If we run into the container response we are done - if ((current instanceof Response) - || (current instanceof ResponseFacade)) + if ((current instanceof Response) || (current instanceof ResponseFacade)) { break; + } // Remove the current response if it is our wrapper if (current == state.wrapResponse) { ServletResponse next = ((ServletResponseWrapper) current).getResponse(); - if (previous == null) + if (previous == null) { state.outerResponse = next; - else + } else { ((ServletResponseWrapper) previous).setResponse(next); + } break; } @@ -855,14 +862,18 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher ServletRequest previous = null; ServletRequest current = state.outerRequest; while (current != null) { - if(state.hrequest == null && (current instanceof HttpServletRequest)) + if(state.hrequest == null && (current instanceof HttpServletRequest)) { state.hrequest = (HttpServletRequest)current; - if (!(current instanceof ServletRequestWrapper)) + } + if (!(current instanceof ServletRequestWrapper)) { break; - if (current instanceof ApplicationHttpRequest) + } + if (current instanceof ApplicationHttpRequest) { break; - if (current instanceof ApplicationRequest) + } + if (current instanceof ApplicationRequest) { break; + } previous = current; current = ((ServletRequestWrapper) current).getRequest(); } @@ -893,10 +904,11 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher } else { wrapper = new ApplicationRequest(current); } - if (previous == null) + if (previous == null) { state.outerRequest = wrapper; - else + } else { ((ServletRequestWrapper) previous).setRequest(wrapper); + } state.wrapRequest = wrapper; return wrapper; @@ -913,35 +925,38 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher ServletResponse previous = null; ServletResponse current = state.outerResponse; while (current != null) { - if(state.hresponse == null && (current instanceof HttpServletResponse)) { + if (state.hresponse == null && (current instanceof HttpServletResponse)) { state.hresponse = (HttpServletResponse)current; - if(!state.including) // Forward only needs hresponse + if (!state.including) { // Forward only needs hresponse return null; + } } - if (!(current instanceof ServletResponseWrapper)) + if (!(current instanceof ServletResponseWrapper)) { break; - if (current instanceof ApplicationHttpResponse) + } + if (current instanceof ApplicationHttpResponse) { break; - if (current instanceof ApplicationResponse) + } + if (current instanceof ApplicationResponse) { break; + } previous = current; current = ((ServletResponseWrapper) current).getResponse(); } // Instantiate a new wrapper at this point and insert it in the chain ServletResponse wrapper = null; - if ((current instanceof ApplicationHttpResponse) || - (current instanceof Response) || - (current instanceof HttpServletResponse)) - wrapper = - new ApplicationHttpResponse((HttpServletResponse) current, - state.including); - else + if ((current instanceof ApplicationHttpResponse) || (current instanceof Response) || + (current instanceof HttpServletResponse)) { + wrapper = new ApplicationHttpResponse((HttpServletResponse) current, state.including); + } else { wrapper = new ApplicationResponse(current, state.including); - if (previous == null) + } + if (previous == null) { state.outerResponse = wrapper; - else + } else { ((ServletResponseWrapper) previous).setResponse(wrapper); + } state.wrapResponse = wrapper; return wrapper; diff --git a/java/org/apache/catalina/filters/RemoteCIDRFilter.java b/java/org/apache/catalina/filters/RemoteCIDRFilter.java index 759da6d..a134ed1 100644 --- a/java/org/apache/catalina/filters/RemoteCIDRFilter.java +++ b/java/org/apache/catalina/filters/RemoteCIDRFilter.java @@ -113,8 +113,9 @@ public final class RemoteCIDRFilter extends FilterBase { public void setDeny(final String input) { final List<String> messages = fillFromInput(input, deny); - if (messages.isEmpty()) + if (messages.isEmpty()) { return; + } for (final String message : messages) { log.error(message); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org