This is an automated email from the ASF dual-hosted git repository. remm 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 05a72ef525 Cleanups for EL and JSP 05a72ef525 is described below commit 05a72ef525e41835aaf5ce3d04122970f4aa8c21 Author: remm <r...@apache.org> AuthorDate: Thu Mar 20 22:10:45 2025 +0100 Cleanups for EL and JSP --- java/org/apache/el/MethodExpressionImpl.java | 2 +- java/org/apache/el/ValueExpressionLiteral.java | 2 + java/org/apache/el/lang/ELSupport.java | 64 ++++++++-------- java/org/apache/el/lang/ExpressionBuilder.java | 4 +- java/org/apache/el/lang/FunctionMapperImpl.java | 2 + java/org/apache/el/lang/VariableMapperImpl.java | 2 + java/org/apache/el/parser/AstValue.java | 12 +-- java/org/apache/el/parser/SimpleNode.java | 3 +- java/org/apache/el/stream/Stream.java | 9 +-- java/org/apache/el/util/ExceptionUtils.java | 6 +- java/org/apache/el/util/ReflectionUtil.java | 86 ++++++---------------- java/org/apache/jasper/Constants.java | 6 +- java/org/apache/jasper/EmbeddedServletOptions.java | 4 +- java/org/apache/jasper/JasperException.java | 3 + java/org/apache/jasper/JspCompilationContext.java | 4 +- java/org/apache/jasper/compiler/Collector.java | 6 +- java/org/apache/jasper/compiler/Compiler.java | 23 +++--- java/org/apache/jasper/compiler/ELNode.java | 2 +- .../apache/jasper/compiler/EncodingDetector.java | 10 +-- .../apache/jasper/compiler/ErrorDispatcher.java | 2 +- java/org/apache/jasper/compiler/Generator.java | 13 ++-- .../apache/jasper/compiler/JspDocumentParser.java | 10 ++- java/org/apache/jasper/compiler/JspReader.java | 4 +- .../apache/jasper/compiler/JspRuntimeContext.java | 6 +- java/org/apache/jasper/compiler/Mark.java | 5 +- java/org/apache/jasper/compiler/Node.java | 6 +- java/org/apache/jasper/compiler/PageDataImpl.java | 2 +- java/org/apache/jasper/compiler/PageInfo.java | 2 +- java/org/apache/jasper/compiler/Parser.java | 7 +- .../apache/jasper/compiler/ParserController.java | 4 +- java/org/apache/jasper/compiler/SmapInput.java | 21 +----- java/org/apache/jasper/compiler/SmapStratum.java | 2 +- .../jasper/compiler/StringInterpreterFactory.java | 2 +- .../apache/jasper/compiler/TagFileProcessor.java | 4 +- java/org/apache/jasper/compiler/TldCache.java | 2 +- java/org/apache/jasper/compiler/Validator.java | 7 +- .../compiler/tagplugin/TagPluginContext.java | 6 +- java/org/apache/jasper/el/JasperELResolver.java | 2 +- java/org/apache/jasper/el/JspELException.java | 3 + .../jasper/el/JspMethodNotFoundException.java | 3 + .../jasper/el/JspPropertyNotFoundException.java | 3 + .../jasper/el/JspPropertyNotWritableException.java | 3 + .../org/apache/jasper/runtime/BodyContentImpl.java | 6 +- java/org/apache/jasper/runtime/HttpJspBase.java | 2 + java/org/apache/jasper/runtime/JspWriterImpl.java | 6 +- .../apache/jasper/servlet/JasperInitializer.java | 2 +- .../apache/jasper/servlet/JspCServletContext.java | 6 +- java/org/apache/jasper/servlet/JspServlet.java | 6 +- .../apache/jasper/servlet/JspServletWrapper.java | 23 +++--- .../jasper/tagplugins/jstl/core/ForEach.java | 2 +- .../apache/jasper/tagplugins/jstl/core/Param.java | 2 +- .../apache/jasper/tagplugins/jstl/core/Set.java | 2 +- .../apache/jasper/tagplugins/jstl/core/When.java | 2 +- 53 files changed, 184 insertions(+), 244 deletions(-) diff --git a/java/org/apache/el/MethodExpressionImpl.java b/java/org/apache/el/MethodExpressionImpl.java index c9174d5796..4a0bac0aa7 100644 --- a/java/org/apache/el/MethodExpressionImpl.java +++ b/java/org/apache/el/MethodExpressionImpl.java @@ -53,7 +53,7 @@ import org.apache.el.util.ReflectionUtil; * This provides the <code>base</code> object on which the method appears. If the <code>base</code> object is null, a * <code>NullPointerException</code> must be thrown. At the last resolution, the final <code>property</code> is then * coerced to a <code>String</code>, which provides the name of the method to be found. A method matching the name and - * expected parameters provided at parse time is found and it is either queried or invoked (depending on the method + * expected parameters provided at parse time is found, and it is either queried or invoked (depending on the method * called on this <code>MethodExpression</code>). * </p> * <p> diff --git a/java/org/apache/el/ValueExpressionLiteral.java b/java/org/apache/el/ValueExpressionLiteral.java index ab6d0c18dc..426a6e4892 100644 --- a/java/org/apache/el/ValueExpressionLiteral.java +++ b/java/org/apache/el/ValueExpressionLiteral.java @@ -20,6 +20,7 @@ import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; +import java.io.Serial; import jakarta.el.ELContext; import jakarta.el.PropertyNotWritableException; @@ -31,6 +32,7 @@ import org.apache.el.util.ReflectionUtil; public final class ValueExpressionLiteral extends ValueExpression implements Externalizable { + @Serial private static final long serialVersionUID = 1L; private Object value; diff --git a/java/org/apache/el/lang/ELSupport.java b/java/org/apache/el/lang/ELSupport.java index 2c3ca445ee..e9a6ad4ac5 100644 --- a/java/org/apache/el/lang/ELSupport.java +++ b/java/org/apache/el/lang/ELSupport.java @@ -177,8 +177,8 @@ public class ELSupport { } /* - * Going to have to have some casts /raw types somewhere so doing it here keeps them all in one place. There might - * be a neater / better solution but I couldn't find it. + * Going to have some casts /raw types somewhere so doing it here keeps them all in one place. There might + * be a neater / better solution, but I couldn't find it. */ @SuppressWarnings("unchecked") public static Enum<?> coerceToEnum(final ELContext ctx, final Object obj, @@ -457,23 +457,22 @@ public class ELSupport { } } - if (obj == null) { - return ""; - } else if (obj instanceof String) { - return (String) obj; - } else if (obj instanceof Enum<?>) { - return ((Enum<?>) obj).name(); - } else { - try { - return obj.toString(); - } catch (ELException e) { - // Unlikely but you never know - throw e; - } catch (Throwable t) { - ExceptionUtils.handleThrowable(t); - throw new ELException(t); + return switch (obj) { + case null -> ""; + case String s -> s; + case Enum<?> anEnum -> anEnum.name(); + default -> { + try { + yield obj.toString(); + } catch (ELException e) { + // Unlikely but you never know + throw e; + } catch (Throwable t) { + ExceptionUtils.handleThrowable(t); + throw new ELException(t); + } } - } + }; } public static <T> T coerceToType(final ELContext ctx, final Object obj, final Class<T> type) @@ -533,8 +532,7 @@ public class ELSupport { if (obj == null) { return null; } - if (obj instanceof String) { - String str = (String) obj; + if (obj instanceof String str) { PropertyEditor editor = PropertyEditorManager.findEditor(type); if (editor == null) { if (str.isEmpty()) { @@ -693,19 +691,23 @@ public class ELSupport { */ private static boolean overridesObjectMethod(Method method) { // There are three methods that can be overridden - if ("equals".equals(method.getName())) { - if (method.getReturnType().equals(boolean.class)) { - if (method.getParameterCount() == 1) { - return method.getParameterTypes()[0].equals(Object.class); + switch (method.getName()) { + case "equals" -> { + if (method.getReturnType().equals(boolean.class)) { + if (method.getParameterCount() == 1) { + return method.getParameterTypes()[0].equals(Object.class); + } } } - } else if ("hashCode".equals(method.getName())) { - if (method.getReturnType().equals(int.class)) { - return method.getParameterCount() == 0; + case "hashCode" -> { + if (method.getReturnType().equals(int.class)) { + return method.getParameterCount() == 0; + } } - } else if ("toString".equals(method.getName())) { - if (method.getReturnType().equals(String.class)) { - return method.getParameterCount() == 0; + case "toString" -> { + if (method.getReturnType().equals(String.class)) { + return method.getParameterCount() == 0; + } } } @@ -714,6 +716,6 @@ public class ELSupport { private ELSupport() { - // Uility class - hide default constructor; + // Utility class - hide default constructor; } } diff --git a/java/org/apache/el/lang/ExpressionBuilder.java b/java/org/apache/el/lang/ExpressionBuilder.java index 4b462fe137..06a6c1ee77 100644 --- a/java/org/apache/el/lang/ExpressionBuilder.java +++ b/java/org/apache/el/lang/ExpressionBuilder.java @@ -166,9 +166,7 @@ public final class ExpressionBuilder implements NodeVisitor { @Override public void visit(Node node) throws ELException { - if (node instanceof AstFunction) { - - AstFunction funcNode = (AstFunction) node; + if (node instanceof AstFunction funcNode) { Method m = null; diff --git a/java/org/apache/el/lang/FunctionMapperImpl.java b/java/org/apache/el/lang/FunctionMapperImpl.java index ba35e56b4b..8fcb802c53 100644 --- a/java/org/apache/el/lang/FunctionMapperImpl.java +++ b/java/org/apache/el/lang/FunctionMapperImpl.java @@ -20,6 +20,7 @@ import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; +import java.io.Serial; import java.lang.reflect.Method; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -35,6 +36,7 @@ import org.apache.el.util.ReflectionUtil; */ public class FunctionMapperImpl extends FunctionMapper implements Externalizable { + @Serial private static final long serialVersionUID = 1L; protected ConcurrentMap<String,Function> functions = new ConcurrentHashMap<>(); diff --git a/java/org/apache/el/lang/VariableMapperImpl.java b/java/org/apache/el/lang/VariableMapperImpl.java index f20d1a8955..e22adb4408 100644 --- a/java/org/apache/el/lang/VariableMapperImpl.java +++ b/java/org/apache/el/lang/VariableMapperImpl.java @@ -20,6 +20,7 @@ import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; +import java.io.Serial; import java.util.HashMap; import java.util.Map; @@ -28,6 +29,7 @@ import jakarta.el.VariableMapper; public class VariableMapperImpl extends VariableMapper implements Externalizable { + @Serial private static final long serialVersionUID = 1L; private Map<String,ValueExpression> vars = new HashMap<>(); diff --git a/java/org/apache/el/parser/AstValue.java b/java/org/apache/el/parser/AstValue.java index 248591ec5b..936245a0ae 100644 --- a/java/org/apache/el/parser/AstValue.java +++ b/java/org/apache/el/parser/AstValue.java @@ -94,7 +94,8 @@ public final class AstValue extends SimpleNode { i += 2; if (property == null) { - throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.property", property)); + throw new PropertyNotFoundException( + MessageFactory.get("error.unreachable.property", this.children[i].getImage())); } } else if (i + 1 < propCount) { // Object with property not at end of expression @@ -110,11 +111,13 @@ public final class AstValue extends SimpleNode { i++; if (property == null) { - throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.property", property)); + throw new PropertyNotFoundException( + MessageFactory.get("error.unreachable.property", this.children[i].getImage())); } } if (base == null) { - throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.property", property)); + throw new PropertyNotFoundException( + MessageFactory.get("error.unreachable.property", this.children[i].getImage())); } } @@ -133,8 +136,7 @@ public final class AstValue extends SimpleNode { ELResolver resolver = ctx.getELResolver(); while (base != null && i < propCount) { suffix = this.children[i].getValue(ctx); - if (i + 1 < propCount && (this.children[i + 1] instanceof AstMethodParameters)) { - AstMethodParameters mps = (AstMethodParameters) this.children[i + 1]; + if (i + 1 < propCount && (this.children[i + 1] instanceof AstMethodParameters mps)) { if (base instanceof Optional && "orElseGet".equals(suffix) && mps.jjtGetNumChildren() == 1) { Node paramFoOptional = mps.jjtGetChild(0); if (!(paramFoOptional instanceof AstLambdaExpression || diff --git a/java/org/apache/el/parser/SimpleNode.java b/java/org/apache/el/parser/SimpleNode.java index 13415caba4..6799ad8562 100644 --- a/java/org/apache/el/parser/SimpleNode.java +++ b/java/org/apache/el/parser/SimpleNode.java @@ -176,10 +176,9 @@ public abstract class SimpleNode implements Node { if (this == obj) { return true; } - if (!(obj instanceof SimpleNode)) { + if (!(obj instanceof SimpleNode other)) { return false; } - SimpleNode other = (SimpleNode) obj; if (id != other.id) { return false; } diff --git a/java/org/apache/el/stream/Stream.java b/java/org/apache/el/stream/Stream.java index 3660802705..3b3f32e31a 100644 --- a/java/org/apache/el/stream/Stream.java +++ b/java/org/apache/el/stream/Stream.java @@ -460,14 +460,7 @@ public class Stream { } - private static class LambdaExpressionComparator implements Comparator<Object> { - - private final LambdaExpression le; - - LambdaExpressionComparator(LambdaExpression le) { - this.le = le; - } - + private record LambdaExpressionComparator(LambdaExpression le) implements Comparator<Object> { @Override public int compare(Object o1, Object o2) { return ELSupport.coerceToNumber(null, le.invoke(o1, o2), Integer.class).intValue(); diff --git a/java/org/apache/el/util/ExceptionUtils.java b/java/org/apache/el/util/ExceptionUtils.java index f8e7dafb10..85c7786a3c 100644 --- a/java/org/apache/el/util/ExceptionUtils.java +++ b/java/org/apache/el/util/ExceptionUtils.java @@ -17,7 +17,7 @@ package org.apache.el.util; /** - * Utilities for handling Throwables and Exceptions. + * Utilities for handling Throwable and Exceptions. */ /* * Copied from o.a.t.u.ExceptionUtils @@ -42,8 +42,8 @@ public class ExceptionUtils { /** - * NO-OP method provided to enable simple pre-loading of this class. Since the class is used extensively in error - * handling, it is prudent to pre-load it to avoid any failure to load this class masking the true problem during + * NO-OP method provided to enable simple preloading of this class. Since the class is used extensively in error + * handling, it is prudent to preload it to avoid any failure to load this class masking the true problem during * error handling. */ public static void preload() { diff --git a/java/org/apache/el/util/ReflectionUtil.java b/java/org/apache/el/util/ReflectionUtil.java index 423798cf29..ae3095a115 100644 --- a/java/org/apache/el/util/ReflectionUtil.java +++ b/java/org/apache/el/util/ReflectionUtil.java @@ -290,7 +290,7 @@ public class ReflectionUtil { } } if (multiple) { - if (bestMatch.getExactCount() == paramCount - 1) { + if (bestMatch.exactCount() == paramCount - 1) { // Only one parameter is not an exact match - try using the // super class match = resolveAmbiguousMethod(candidates.keySet(), paramTypes); @@ -425,8 +425,7 @@ public class ReflectionUtil { * This class duplicates code in jakarta.el.Util. When making changes keep the code in sync. */ private static boolean isCoercibleFrom(EvaluationContext ctx, Object src, Class<?> target) { - // TODO: This isn't pretty but it works. Significant refactoring would - // be required to avoid the exception. + // TODO: This isn't pretty but it works. Significant refactoring would be required to avoid the exception. try { ELSupport.coerceToType(ctx, src, target); } catch (ELException e) { @@ -495,68 +494,29 @@ public class ReflectionUtil { /* * This class duplicates code in jakarta.el.Util. When making changes keep the code in sync. */ - private static class MatchResult implements Comparable<MatchResult> { - - private final boolean varArgs; - private final int exactCount; - private final int assignableCount; - private final int coercibleCount; - private final int varArgsCount; - private final boolean bridge; - - MatchResult(boolean varArgs, int exactCount, int assignableCount, int coercibleCount, int varArgsCount, - boolean bridge) { - this.varArgs = varArgs; - this.exactCount = exactCount; - this.assignableCount = assignableCount; - this.coercibleCount = coercibleCount; - this.varArgsCount = varArgsCount; - this.bridge = bridge; - } - - public boolean isVarArgs() { - return varArgs; - } - - public int getExactCount() { - return exactCount; - } - - public int getAssignableCount() { - return assignableCount; - } - - public int getCoercible() { - return coercibleCount; - } - - public int getVarArgsCount() { - return varArgsCount; - } - - public boolean isBridge() { - return bridge; - } + private record MatchResult(boolean varArgs, int exactCount, int assignableCount, + int coercibleCount, int varArgsCount, + boolean bridge) implements Comparable<MatchResult> { @Override public int compareTo(MatchResult o) { // Non-varArgs always beats varArgs - int cmp = Boolean.compare(o.isVarArgs(), this.isVarArgs()); + int cmp = Boolean.compare(o.varArgs(), this.varArgs()); if (cmp == 0) { - cmp = Integer.compare(this.getExactCount(), o.getExactCount()); + cmp = Integer.compare(this.exactCount(), o.exactCount()); if (cmp == 0) { - cmp = Integer.compare(this.getAssignableCount(), o.getAssignableCount()); + cmp = Integer.compare(this.assignableCount(), o.assignableCount()); if (cmp == 0) { - cmp = Integer.compare(this.getCoercible(), o.getCoercible()); + cmp = Integer.compare(this.coercibleCount(), o.coercibleCount()); if (cmp == 0) { // Fewer var args matches are better - cmp = Integer.compare(o.getVarArgsCount(), this.getVarArgsCount()); + cmp = Integer.compare(o.varArgsCount(), this.varArgsCount()); if (cmp == 0) { // The nature of bridge methods is such that it actually // doesn't matter which one we pick as long as we pick // one. That said, pick the 'right' one (the non-bridge // one) anyway. - cmp = Boolean.compare(o.isBridge(), this.isBridge()); + cmp = Boolean.compare(o.bridge(), this.bridge()); } } } @@ -568,24 +528,24 @@ public class ReflectionUtil { @Override public boolean equals(Object o) { return o == this || (null != o && this.getClass().equals(o.getClass()) && - ((MatchResult) o).getExactCount() == this.getExactCount() && - ((MatchResult) o).getAssignableCount() == this.getAssignableCount() && - ((MatchResult) o).getCoercible() == this.getCoercible() && - ((MatchResult) o).getVarArgsCount() == this.getVarArgsCount() && - ((MatchResult) o).isVarArgs() == this.isVarArgs() && - ((MatchResult) o).isBridge() == this.isBridge()); + ((MatchResult) o).exactCount() == this.exactCount() && + ((MatchResult) o).assignableCount() == this.assignableCount() && + ((MatchResult) o).coercibleCount() == this.coercibleCount() && + ((MatchResult) o).varArgsCount() == this.varArgsCount() && + ((MatchResult) o).varArgs() == this.varArgs() && + ((MatchResult) o).bridge() == this.bridge()); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + assignableCount; - result = prime * result + (bridge ? 1231 : 1237); - result = prime * result + coercibleCount; - result = prime * result + exactCount; - result = prime * result + (varArgs ? 1231 : 1237); - result = prime * result + varArgsCount; + result = prime * result + assignableCount(); + result = prime * result + (bridge() ? 1231 : 1237); + result = prime * result + coercibleCount(); + result = prime * result + exactCount(); + result = prime * result + (varArgs() ? 1231 : 1237); + result = prime * result + varArgsCount(); return result; } } diff --git a/java/org/apache/jasper/Constants.java b/java/org/apache/jasper/Constants.java index 9cf3b4fc38..b1ddf0bb02 100644 --- a/java/org/apache/jasper/Constants.java +++ b/java/org/apache/jasper/Constants.java @@ -16,8 +16,6 @@ */ package org.apache.jasper; -import java.util.Arrays; -import java.util.Collections; import java.util.List; /** @@ -35,10 +33,8 @@ public class Constants { /** * These classes/packages are automatically imported by the generated code. */ - private static final String[] PRIVATE_STANDARD_IMPORTS = - { "jakarta.servlet.*", "jakarta.servlet.http.*", "jakarta.servlet.jsp.*" }; public static final List<String> STANDARD_IMPORTS = - Collections.unmodifiableList(Arrays.asList(PRIVATE_STANDARD_IMPORTS)); + List.of("jakarta.servlet.*", "jakarta.servlet.http.*", "jakarta.servlet.jsp.*"); /** * Default size of the JSP buffer. diff --git a/java/org/apache/jasper/EmbeddedServletOptions.java b/java/org/apache/jasper/EmbeddedServletOptions.java index 81156548fd..36697c7347 100644 --- a/java/org/apache/jasper/EmbeddedServletOptions.java +++ b/java/org/apache/jasper/EmbeddedServletOptions.java @@ -876,11 +876,11 @@ public final class EmbeddedServletOptions implements Options { } } - // Setup the global Tag Libraries location cache for this + // Set up the global Tag Libraries location cache for this // web-application. tldCache = TldCache.getInstance(context); - // Setup the jsp config info for this web app. + // Set up the jsp config info for this web app. jspConfig = new JspConfig(context); // Create a Tag plugin instance diff --git a/java/org/apache/jasper/JasperException.java b/java/org/apache/jasper/JasperException.java index b65bb2979a..13b18ade5e 100644 --- a/java/org/apache/jasper/JasperException.java +++ b/java/org/apache/jasper/JasperException.java @@ -16,6 +16,8 @@ */ package org.apache.jasper; +import java.io.Serial; + /** * Base class for all exceptions generated by the JSP engine. Makes it convenient to catch just this at the top-level. * @@ -23,6 +25,7 @@ package org.apache.jasper; */ public class JasperException extends jakarta.servlet.ServletException { + @Serial private static final long serialVersionUID = 1L; public JasperException(String reason) { diff --git a/java/org/apache/jasper/JspCompilationContext.java b/java/org/apache/jasper/JspCompilationContext.java index 63741bb59b..dc9f1a2104 100644 --- a/java/org/apache/jasper/JspCompilationContext.java +++ b/java/org/apache/jasper/JspCompilationContext.java @@ -43,7 +43,7 @@ import org.apache.tomcat.Jar; import org.apache.tomcat.util.descriptor.tld.TldResourcePath; /** - * A place holder for various things that are used through out the JSP engine. This is a per-request/per-context data + * A placeholder for various things that are used throughout the JSP engine. This is a per-request/per-context data * structure. Some of the instance variables are set at different points. Most of the path-related stuff is here - * mangling names, versions, dirs, loading resources and dealing with uris. * @@ -187,7 +187,7 @@ public class JspCompilationContext { /** * The output directory to generate code into. The output directory is make up of the scratch directory, which is - * provide in Options, plus the directory derived from the package name. + * provided in Options, plus the directory derived from the package name. * * @return the output directory in which the generated sources are placed */ diff --git a/java/org/apache/jasper/compiler/Collector.java b/java/org/apache/jasper/compiler/Collector.java index e3d4a7063a..df7e3c3417 100644 --- a/java/org/apache/jasper/compiler/Collector.java +++ b/java/org/apache/jasper/compiler/Collector.java @@ -107,8 +107,7 @@ class Collector { hasScriptingVars = false; // Scan attribute list for expressions - if (n instanceof Node.CustomTag) { - Node.CustomTag ct = (Node.CustomTag) n; + if (n instanceof Node.CustomTag ct) { Node.JspAttribute[] attrs = ct.getJspAttributes(); for (int i = 0; attrs != null && i < attrs.length; i++) { if (attrs[i].isExpression()) { @@ -120,8 +119,7 @@ class Collector { visitBody(n); - if ((n instanceof Node.CustomTag) && !hasScriptingVars) { - Node.CustomTag ct = (Node.CustomTag) n; + if ((n instanceof Node.CustomTag ct) && !hasScriptingVars) { hasScriptingVars = ct.getVariableInfos().length > 0 || ct.getTagVariableInfos().length > 0; } diff --git a/java/org/apache/jasper/compiler/Compiler.java b/java/org/apache/jasper/compiler/Compiler.java index 905fab96e1..94eab9d081 100644 --- a/java/org/apache/jasper/compiler/Compiler.java +++ b/java/org/apache/jasper/compiler/Compiler.java @@ -108,9 +108,10 @@ public abstract class Compiler { */ protected Map<String,SmapStratum> generateJava() throws Exception { - long t1, t2, t3, t4; - - t1 = t2 = t3 = t4 = 0; + long t1 = 0; + long t2 = 0; + long t3 = 0; + long t4; if (log.isDebugEnabled()) { t1 = System.currentTimeMillis(); @@ -244,9 +245,9 @@ public abstract class Compiler { Generator.generate(writer, this, pageNodes); } - // The writer is only used during the compile, dereference + // The writer is only used during compile, dereference // it in the JspCompilationContext when done to allow it - // to be GC'd and save memory. + // to be GCed and save memory. ctxt.setWriter(null); if (log.isTraceEnabled()) { @@ -276,7 +277,7 @@ public abstract class Compiler { ctxt.getRuntimeContext().getSmaps().putAll(smaps); } - // If any proto type .java and .class files was generated, + // If any prototype .java and .class files was generated, // the prototype .java may have been replaced by the current // compilation (if the tag file is self referencing), but the // .class file need to be removed, to make sure that javac would @@ -288,7 +289,7 @@ public abstract class Compiler { private ServletWriter setupContextWriter(String javaFileName) throws FileNotFoundException, JasperException { ServletWriter writer; - // Setup the ServletWriter + // Set up the ServletWriter String javaEncoding = ctxt.getOptions().getJavaEncoding(); OutputStreamWriter osw = null; @@ -332,7 +333,7 @@ public abstract class Compiler { } /** - * Compile the jsp file from the current engine context. As an side- effect, tag files that are referenced by this + * Compile the jsp file from the current engine context. As a side effect, tag files that are referenced by this * page are also compiled. * * @param compileClass If true, generate both .java and .class file If false, generate only .java file @@ -346,7 +347,7 @@ public abstract class Compiler { } /** - * Compile the jsp file from the current engine context. As an side- effect, tag files that are referenced by this + * Compile the jsp file from the current engine context. As a side effect, tag files that are referenced by this * page are also compiled. * * @param compileClass If true, generate both .java and .class file If false, generate only .java file @@ -389,7 +390,7 @@ public abstract class Compiler { } // Make sure these object which are only used during the // generation and compilation of the JSP page get - // dereferenced so that they can be GC'd and reduce the + // dereferenced so that they can be GCed and reduce the // memory footprint. tfp = null; errDispatcher = null; @@ -416,7 +417,7 @@ public abstract class Compiler { /** * Determine if a compilation is necessary by checking the time stamp of the JSP page with that of the corresponding * .class or .java file. If the page has dependencies, the check is also extended to its dependents, and so on. This - * method can by overridden by a subclasses of Compiler. + * method can be overridden by a subclasses of Compiler. * * @param checkClass If true, check against .class file, if false, check against .java file. * diff --git a/java/org/apache/jasper/compiler/ELNode.java b/java/org/apache/jasper/compiler/ELNode.java index a1568d484b..6730a59b5e 100644 --- a/java/org/apache/jasper/compiler/ELNode.java +++ b/java/org/apache/jasper/compiler/ELNode.java @@ -31,7 +31,7 @@ import org.apache.jasper.JasperException; * @author Kin-man Chung */ -abstract class ELNode { +public abstract class ELNode { public abstract void accept(Visitor v) throws JasperException; diff --git a/java/org/apache/jasper/compiler/EncodingDetector.java b/java/org/apache/jasper/compiler/EncodingDetector.java index aff864dca9..d65d1a4c68 100644 --- a/java/org/apache/jasper/compiler/EncodingDetector.java +++ b/java/org/apache/jasper/compiler/EncodingDetector.java @@ -201,14 +201,6 @@ class EncodingDetector { } - private static class BomResult { - - public final String encoding; - public final int skip; - - BomResult(String encoding, int skip) { - this.encoding = encoding; - this.skip = skip; - } + private record BomResult(String encoding, int skip) { } } diff --git a/java/org/apache/jasper/compiler/ErrorDispatcher.java b/java/org/apache/jasper/compiler/ErrorDispatcher.java index 436ae5354a..16ec6b76dd 100644 --- a/java/org/apache/jasper/compiler/ErrorDispatcher.java +++ b/java/org/apache/jasper/compiler/ErrorDispatcher.java @@ -250,7 +250,7 @@ public class ErrorDispatcher { file = where.getFile(); } } else { - // Get the context-relative resource path, so as to not disclose any local file system details + // Get the context-relative resource path, to avoid disclosing any local file system details file = where.getFile(); } line = where.getLineNumber(); diff --git a/java/org/apache/jasper/compiler/Generator.java b/java/org/apache/jasper/compiler/Generator.java index e708247824..c31d5d4980 100644 --- a/java/org/apache/jasper/compiler/Generator.java +++ b/java/org/apache/jasper/compiler/Generator.java @@ -2385,8 +2385,7 @@ class Generator { List<Object> vec = n.getScriptingVars(scope); if (vec != null) { for (Object elem : vec) { - if (elem instanceof VariableInfo) { - VariableInfo varInfo = (VariableInfo) elem; + if (elem instanceof VariableInfo varInfo) { out.printin(varInfo.getClassName()); out.print(" "); out.print(varInfo.getVarName()); @@ -2425,7 +2424,7 @@ class Generator { // JspFragment, because a fragment is always scriptless. // Thus, there is no need to save/ restore/ sync them. // Note, that JspContextWrapper.syncFoo() methods will take - // care of saving/ restoring/ sync'ing of JspContext attributes. + // care of saving/ restoring/ syncing of JspContext attributes. return; } @@ -2497,7 +2496,7 @@ class Generator { // JspFragment, because a fragment is always scriptless. // Thus, there is no need to save/ restore/ sync them. // Note, that JspContextWrapper.syncFoo() methods will take - // care of saving/ restoring/ sync'ing of JspContext attributes. + // care of saving/ restoring/ syncing of JspContext attributes. return; } @@ -2563,7 +2562,7 @@ class Generator { // JspFragment, because a fragment is always scriptless. // Thus, there is no need to save/ restore/ sync them. // Note, that JspContextWrapper.syncFoo() methods will take - // care of saving/ restoring/ sync'ing of JspContext attributes. + // care of saving/ restoring/ syncing of JspContext attributes. return; } @@ -2957,7 +2956,7 @@ class Generator { fragmentHelperClass.closeFragment(fragment, methodNesting); // XXX - Need to change pageContext to jspContext if // we're not in a place where pageContext is defined (e.g. - // in a fragment or in a tag file. + // in a fragment or in a tag file). out.print("new " + fragmentHelperClass.getClassName() + "( " + fragment.getId() + ", _jspx_page_context, " + tagHandlerVar + ", " + pushBodyCountVar + ")"); } @@ -3701,7 +3700,7 @@ class Generator { /* * For a CustomTag, the codes that are generated at the beginning of the tag may not be in the same buffer as * those for the body of the tag. Two fields are used here to keep this straight. For codes that do not - * corresponds to any JSP lines, they should be null. + * correspond to any JSP lines, they should be null. */ private final Node node; diff --git a/java/org/apache/jasper/compiler/JspDocumentParser.java b/java/org/apache/jasper/compiler/JspDocumentParser.java index 5b6eb84da4..11c464abfa 100644 --- a/java/org/apache/jasper/compiler/JspDocumentParser.java +++ b/java/org/apache/jasper/compiler/JspDocumentParser.java @@ -19,6 +19,7 @@ package org.apache.jasper.compiler; import java.io.CharArrayWriter; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.Serial; import java.util.Collection; import javax.xml.parsers.SAXParser; @@ -361,7 +362,7 @@ class JspDocumentParser extends DefaultHandler2 implements TagConstants { * * The SAX does not call this method with all of the template text, but may invoke this method with chunks of it. * This is a problem when we try to determine if the text contains only whitespaces, or when we are looking for an - * EL expression string. Therefore it is necessary to buffer and concatenate the chunks and process the concatenated + * EL expression string. Therefore, it is necessary to buffer and concatenate the chunks and process the concatenated * text later (at beginTag and endTag) * * @param buf The characters @@ -532,12 +533,12 @@ class JspDocumentParser extends DefaultHandler2 implements TagConstants { continue; } // Ignore any whitespace (including spaces, carriage returns, - // line feeds, and tabs, that appear at the beginning and at + // line feeds, and tabs) that appear at the beginning and at // the end of the body of the <jsp:attribute> action, if the // action's 'trim' attribute is set to TRUE (default). // In addition, any textual nodes in the <jsp:attribute> that - // have only white space are dropped from the document, with - // the exception of leading and trailing white-space-only + // have only white space are dropped from the document, + // except for leading and trailing white-space-only // textual nodes in a <jsp:attribute> whose 'trim' attribute // is set to FALSE, which must be kept verbatim. if (i == 0) { @@ -1064,6 +1065,7 @@ class JspDocumentParser extends DefaultHandler2 implements TagConstants { */ private static class EnableDTDValidationException extends SAXParseException { + @Serial private static final long serialVersionUID = 1L; EnableDTDValidationException(String message, Locator loc) { diff --git a/java/org/apache/jasper/compiler/JspReader.java b/java/org/apache/jasper/compiler/JspReader.java index 95e20ad5c5..c5ad96aab0 100644 --- a/java/org/apache/jasper/compiler/JspReader.java +++ b/java/org/apache/jasper/compiler/JspReader.java @@ -30,7 +30,7 @@ import org.apache.tomcat.Jar; /** * JspReader is an input buffer for the JSP parser. It should allow unlimited lookahead and pushback. It also has a - * bunch of parsing utility methods for understanding htmlesque thingies. + * bunch of parsing utility methods for understanding html style content. * * @author Anil K. Vijendran * @author Anselm Baird-Smith @@ -599,7 +599,7 @@ class JspReader { /** * Parse utils - Is current character a token delimiter ? Delimiters are currently defined to be =, >, <, ", - * and ' or any any space character as defined by <code>isSpace</code>. + * and ' or any space character as defined by <code>isSpace</code>. * * @return A boolean. */ diff --git a/java/org/apache/jasper/compiler/JspRuntimeContext.java b/java/org/apache/jasper/compiler/JspRuntimeContext.java index 49808b5bc4..d659c0ad83 100644 --- a/java/org/apache/jasper/compiler/JspRuntimeContext.java +++ b/java/org/apache/jasper/compiler/JspRuntimeContext.java @@ -300,7 +300,7 @@ public final class JspRuntimeContext { /** - * Method used by background thread to check the JSP dependencies registered with this class for JSP's. + * Method used by background thread to check the JSP dependencies registered with this class for JSPs. */ public void checkCompile() { @@ -349,7 +349,7 @@ public final class JspRuntimeContext { try { if (jsw.isTagFile()) { // Although this is a public method, all other paths to this - // method use this sync and it is required to prevent race + // method use this sync, and it is required to prevent race // conditions during the reload. synchronized (this) { jsw.loadTagFile(); @@ -449,7 +449,7 @@ public final class JspRuntimeContext { /** - * Method used by background thread to check if any JSP's should be unloaded. + * Method used by background thread to check if any JSPs should be unloaded. */ public void checkUnload() { diff --git a/java/org/apache/jasper/compiler/Mark.java b/java/org/apache/jasper/compiler/Mark.java index a53cd7bb03..3b4fb67982 100644 --- a/java/org/apache/jasper/compiler/Mark.java +++ b/java/org/apache/jasper/compiler/Mark.java @@ -26,7 +26,7 @@ import org.apache.jasper.JspCompilationContext; * * @author Anil K. Vijendran */ -final class Mark { +public final class Mark { // position within current stream int cursor, line, col; @@ -125,8 +125,7 @@ final class Mark { @Override public boolean equals(Object other) { - if (other instanceof Mark) { - Mark m = (Mark) other; + if (other instanceof Mark m) { return this.cursor == m.cursor && this.line == m.line && this.col == m.col; } return false; diff --git a/java/org/apache/jasper/compiler/Node.java b/java/org/apache/jasper/compiler/Node.java index 90af48e7f2..abfb7d27ef 100644 --- a/java/org/apache/jasper/compiler/Node.java +++ b/java/org/apache/jasper/compiler/Node.java @@ -49,7 +49,7 @@ import org.xml.sax.Attributes; * @author Mark Roth */ -abstract class Node implements TagConstants { +public abstract class Node implements TagConstants { private static final VariableInfo[] ZERO_VARIABLE_INFO = {}; @@ -346,7 +346,7 @@ abstract class Node implements TagConstants { } /** - * Selects and invokes a method in the visitor class based on the node type. This is abstract and should be overrode + * Selects and invokes a method in the visitor class based on the node type. This is abstract and should be overridden * by the extending classes. * * @param v The visitor class @@ -2191,7 +2191,7 @@ abstract class Node implements TagConstants { /** * This method provides a place to put actions that are common to all nodes. Override this in the child visitor - * class if need to. + * class if needed. * * @param n The node to visit */ diff --git a/java/org/apache/jasper/compiler/PageDataImpl.java b/java/org/apache/jasper/compiler/PageDataImpl.java index 8327b72f23..853e2420da 100644 --- a/java/org/apache/jasper/compiler/PageDataImpl.java +++ b/java/org/apache/jasper/compiler/PageDataImpl.java @@ -77,7 +77,7 @@ class PageDataImpl extends PageData implements TagConstants { } /* - * First-pass Visitor for JspRoot nodes (representing jsp:root elements) and TablibDirective nodes, ignoring any + * First-pass Visitor for JspRoot nodes (representing jsp:root elements) and TaglibDirective nodes, ignoring any * other nodes. * * The purpose of this Visitor is to collect the attributes of the top-level jsp:root and those of the jsp:root diff --git a/java/org/apache/jasper/compiler/PageInfo.java b/java/org/apache/jasper/compiler/PageInfo.java index 9dceee1f0a..f84102f557 100644 --- a/java/org/apache/jasper/compiler/PageInfo.java +++ b/java/org/apache/jasper/compiler/PageInfo.java @@ -39,7 +39,7 @@ import org.apache.jasper.JspCompilationContext; * @author Kin-man Chung */ -class PageInfo { +public class PageInfo { private final List<String> imports; private final Map<String,Long> dependants; diff --git a/java/org/apache/jasper/compiler/Parser.java b/java/org/apache/jasper/compiler/Parser.java index 5c0b5a5aa9..435bd333a0 100644 --- a/java/org/apache/jasper/compiler/Parser.java +++ b/java/org/apache/jasper/compiler/Parser.java @@ -562,7 +562,7 @@ class Parser implements TagConstants { } /* - * Parses a attribute directive with the following syntax: AttributeDirective ::= ( S Attribute)* + * Parses an attribute directive with the following syntax: AttributeDirective ::= ( S Attribute)* */ private void parseAttributeDirective(Node parent) throws JasperException { Attributes attrs = parseAttributes(); @@ -955,8 +955,7 @@ class Parser implements TagConstants { boolean result = false; if (reader.matchesOptionalSpacesFollowedBy("<jsp:attribute")) { - // May be an EmptyBody, depending on whether - // There's a "<jsp:body" before the ETag + // It may be an EmptyBody, depending on whether there's a "<jsp:body" before the ETag // First, parse <jsp:attribute> elements: parseNamedAttributes(parent); @@ -1121,7 +1120,7 @@ class Parser implements TagConstants { // 'CustomActionJSPContent', or 'CustomActionScriptlessContent'. // depending on body-content in TLD. - // Looking for a body, it still can be empty; but if there is a + // Looking for a body, it still can be empty; but if there is // a tag body, its syntax would be dependent on the type of // body content declared in the TLD. String bc; diff --git a/java/org/apache/jasper/compiler/ParserController.java b/java/org/apache/jasper/compiler/ParserController.java index 6fefdbcfdc..5f90f621b5 100644 --- a/java/org/apache/jasper/compiler/ParserController.java +++ b/java/org/apache/jasper/compiler/ParserController.java @@ -40,7 +40,7 @@ import org.xml.sax.Attributes; * @author Pierre Delisle * @author Jan Luehe */ -class ParserController implements TagConstants { +public class ParserController implements TagConstants { private static final String CHARSET = "charset="; private static final String TAGS_IN_JAR_LOCATION = "/META-INF/tags/"; @@ -197,7 +197,7 @@ class ParserController implements TagConstants { /* * An included file is being parsed that was included from the standard location for tag files in JAR but * tries to escape that location to either somewhere in the JAR not under the standard location or outside - * of the JAR. Neither of these are permitted. + * the JAR. Neither of these are permitted. */ err.jspError("jsp.error.invalid.includeInTagFileJar", inFileName, jar.getJarFileURL().toString()); } diff --git a/java/org/apache/jasper/compiler/SmapInput.java b/java/org/apache/jasper/compiler/SmapInput.java index 858c0522ce..32bac1bdb1 100644 --- a/java/org/apache/jasper/compiler/SmapInput.java +++ b/java/org/apache/jasper/compiler/SmapInput.java @@ -16,24 +16,5 @@ */ package org.apache.jasper.compiler; -public class SmapInput { - - private final String fileName; - private final int lineNumber; - - - public SmapInput(String fileName, int lineNumber) { - this.fileName = fileName; - this.lineNumber = lineNumber; - } - - - public String getFileName() { - return fileName; - } - - - public int getLineNumber() { - return lineNumber; - } +public record SmapInput(String fileName, int lineNumber) { } diff --git a/java/org/apache/jasper/compiler/SmapStratum.java b/java/org/apache/jasper/compiler/SmapStratum.java index 8eab419f9e..6adcf1d1c3 100644 --- a/java/org/apache/jasper/compiler/SmapStratum.java +++ b/java/org/apache/jasper/compiler/SmapStratum.java @@ -30,7 +30,7 @@ public class SmapStratum { /** * Represents a single LineSection in an SMAP, associated with a particular stratum. */ - static class LineInfo { + public static class LineInfo { private int inputStartLine = -1; private int outputStartLine = -1; private int lineFileID = 0; diff --git a/java/org/apache/jasper/compiler/StringInterpreterFactory.java b/java/org/apache/jasper/compiler/StringInterpreterFactory.java index 22d7dea62e..45c637dab6 100644 --- a/java/org/apache/jasper/compiler/StringInterpreterFactory.java +++ b/java/org/apache/jasper/compiler/StringInterpreterFactory.java @@ -153,7 +153,7 @@ public class StringInterpreterFactory { /** - * Intended to be used by sub-classes that don't need/want to re-implement the logic in + * Intended to be used by subclasses that don't need/want to re-implement the logic in * {@link #convertString(Class, String, String, Class, boolean)}. * * @param c unused diff --git a/java/org/apache/jasper/compiler/TagFileProcessor.java b/java/org/apache/jasper/compiler/TagFileProcessor.java index 92d08c8656..146a059653 100644 --- a/java/org/apache/jasper/compiler/TagFileProcessor.java +++ b/java/org/apache/jasper/compiler/TagFileProcessor.java @@ -46,7 +46,7 @@ import org.apache.tomcat.util.descriptor.tld.TldResourcePath; * @author Kin-man Chung */ -class TagFileProcessor { +public class TagFileProcessor { private List<Compiler> tempVector; @@ -625,7 +625,7 @@ class TagFileProcessor { /** * Removed the java and class files for the tag prototype generated from the current compilation. * - * @param classFileName If non-null, remove only the class file with with this name. + * @param classFileName If non-null, remove only the class file with this name. */ public void removeProtoTypeFiles(String classFileName) { for (Compiler c : tempVector) { diff --git a/java/org/apache/jasper/compiler/TldCache.java b/java/org/apache/jasper/compiler/TldCache.java index f2106493f8..c1f8014c2e 100644 --- a/java/org/apache/jasper/compiler/TldCache.java +++ b/java/org/apache/jasper/compiler/TldCache.java @@ -35,7 +35,7 @@ import org.xml.sax.SAXException; /** * This class caches parsed instances of TLD files to remove the need for the same TLD to be parsed for each JSP that - * references it. It does not protect against multiple threads processing the same, new TLD but it does ensure that each + * references it. It does not protect against multiple threads processing the same new TLD, but it does ensure that each * all threads will use the same TLD object after parsing. */ public class TldCache { diff --git a/java/org/apache/jasper/compiler/Validator.java b/java/org/apache/jasper/compiler/Validator.java index e1fc3acdc3..96725d4a45 100644 --- a/java/org/apache/jasper/compiler/Validator.java +++ b/java/org/apache/jasper/compiler/Validator.java @@ -1120,10 +1120,10 @@ class Validator { /** * Preprocess attributes that can be expressions. Expression delimiters are stripped. * <p> - * If value is null, checks if there are any NamedAttribute subelements in the tree node, and if so, constructs + * If value is null, checks if there are any NamedAttribute sub elements in the tree node, and if so, constructs * a JspAttribute out of a child NamedAttribute node. * - * @param el EL expression, if already parsed by the caller (so that we can skip re-parsing it) + * @param el EL expression, if already parsed by the caller (so that we can skip reparsing it) */ private Node.JspAttribute getJspAttribute(TagAttributeInfo tai, String qName, String uri, String localName, String value, Node n, ELNode.Nodes el, boolean dynamic) throws JasperException { @@ -1610,10 +1610,9 @@ class Validator { for (Object o : compiler.getPageInfo().getTaglibs()) { - if (!(o instanceof TagLibraryInfoImpl)) { + if (!(o instanceof TagLibraryInfoImpl tli)) { continue; } - TagLibraryInfoImpl tli = (TagLibraryInfoImpl) o; ValidationMessage[] errors = tli.validate(xmlView); if ((errors != null) && (errors.length != 0)) { diff --git a/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java b/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java index 7f6ad2c098..38d9383a57 100644 --- a/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java +++ b/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java @@ -81,7 +81,7 @@ public interface TagPluginContext { String getConstantAttribute(String attribute); /** - * Generate codes to evaluate value of a attribute in the custom tag The codes is a Java expression. NOTE: Currently + * Generate codes to evaluate value of an attribute in the custom tag The codes is a Java expression. NOTE: Currently * cannot handle attributes that are fragments. * * @param attribute The specified attribute @@ -101,10 +101,10 @@ public interface TagPluginContext { /** * Get the PluginContext for the parent of this custom tag. NOTE: The operations available for PluginContext so - * obtained is limited to getPluginAttribute and setPluginAttribute, and queries (e.g. isScriptless(). There should + * obtained is limited to getPluginAttribute and setPluginAttribute, and queries (e.g. isScriptless()). There should * be no calls to generate*(). * - * @return The pluginContext for the parent node. null if the parent is not a custom tag, or if the pluginContext if + * @return The pluginContext for the parent node. null if the parent is not a custom tag, or if the pluginContext is * not available (because useTagPlugin is false, e.g). */ TagPluginContext getParentContext(); diff --git a/java/org/apache/jasper/el/JasperELResolver.java b/java/org/apache/jasper/el/JasperELResolver.java index d4bb44d7a6..644a002341 100644 --- a/java/org/apache/jasper/el/JasperELResolver.java +++ b/java/org/apache/jasper/el/JasperELResolver.java @@ -107,7 +107,7 @@ public class JasperELResolver extends CompositeELResolver { // call implicit and app resolvers int index = 1 /* implicit */ + appResolversSize; for (int i = 0; i < index; i++) { - result = resolvers[i].getValue(context, base, property); + result = resolvers[i].getValue(context, null, property); if (context.isPropertyResolved()) { return result; } diff --git a/java/org/apache/jasper/el/JspELException.java b/java/org/apache/jasper/el/JspELException.java index a881dd33bb..e1e6468c8d 100644 --- a/java/org/apache/jasper/el/JspELException.java +++ b/java/org/apache/jasper/el/JspELException.java @@ -16,10 +16,13 @@ */ package org.apache.jasper.el; +import java.io.Serial; + import jakarta.el.ELException; public class JspELException extends ELException { + @Serial private static final long serialVersionUID = 1L; public JspELException(String mark, ELException e) { diff --git a/java/org/apache/jasper/el/JspMethodNotFoundException.java b/java/org/apache/jasper/el/JspMethodNotFoundException.java index 2827b19807..6034da3740 100644 --- a/java/org/apache/jasper/el/JspMethodNotFoundException.java +++ b/java/org/apache/jasper/el/JspMethodNotFoundException.java @@ -16,10 +16,13 @@ */ package org.apache.jasper.el; +import java.io.Serial; + import jakarta.el.MethodNotFoundException; public class JspMethodNotFoundException extends MethodNotFoundException { + @Serial private static final long serialVersionUID = 1L; public JspMethodNotFoundException(String mark, MethodNotFoundException e) { diff --git a/java/org/apache/jasper/el/JspPropertyNotFoundException.java b/java/org/apache/jasper/el/JspPropertyNotFoundException.java index 8842906033..cf3b5a87f2 100644 --- a/java/org/apache/jasper/el/JspPropertyNotFoundException.java +++ b/java/org/apache/jasper/el/JspPropertyNotFoundException.java @@ -16,10 +16,13 @@ */ package org.apache.jasper.el; +import java.io.Serial; + import jakarta.el.PropertyNotFoundException; public final class JspPropertyNotFoundException extends PropertyNotFoundException { + @Serial private static final long serialVersionUID = 1L; public JspPropertyNotFoundException(String mark, PropertyNotFoundException e) { diff --git a/java/org/apache/jasper/el/JspPropertyNotWritableException.java b/java/org/apache/jasper/el/JspPropertyNotWritableException.java index 43654bb931..4e975cf0de 100644 --- a/java/org/apache/jasper/el/JspPropertyNotWritableException.java +++ b/java/org/apache/jasper/el/JspPropertyNotWritableException.java @@ -16,10 +16,13 @@ */ package org.apache.jasper.el; +import java.io.Serial; + import jakarta.el.PropertyNotWritableException; public class JspPropertyNotWritableException extends PropertyNotWritableException { + @Serial private static final long serialVersionUID = 1L; public JspPropertyNotWritableException(String mark, PropertyNotWritableException e) { diff --git a/java/org/apache/jasper/runtime/BodyContentImpl.java b/java/org/apache/jasper/runtime/BodyContentImpl.java index 4a3cd0960f..8ff21e212b 100644 --- a/java/org/apache/jasper/runtime/BodyContentImpl.java +++ b/java/org/apache/jasper/runtime/BodyContentImpl.java @@ -27,8 +27,8 @@ import jakarta.servlet.jsp.tagext.BodyContent; import org.apache.jasper.compiler.Localizer; /** - * Write text to a character-output stream, buffering characters so as to provide for the efficient writing of single - * characters, arrays, and strings. Provide support for discarding for the output that has been buffered. + * Write text to a character-output stream, buffering characters to provide efficient writing of single + * characters, arrays, and strings. Provide support for discarding the output that has been buffered. * * @author Rajiv Mordani * @author Jan Luehe @@ -341,7 +341,7 @@ public class BodyContentImpl extends BodyContent { public void writeOut(Writer out) throws IOException { if (writer == null) { out.write(cb, 0, nextChar); - // Flush not called as the writer passed could be a BodyContent and + // Flush not called as the writer passed could be a BodyContent, and // it doesn't allow to flush. } } diff --git a/java/org/apache/jasper/runtime/HttpJspBase.java b/java/org/apache/jasper/runtime/HttpJspBase.java index 331c5dacf3..3b810d8367 100644 --- a/java/org/apache/jasper/runtime/HttpJspBase.java +++ b/java/org/apache/jasper/runtime/HttpJspBase.java @@ -17,6 +17,7 @@ package org.apache.jasper.runtime; import java.io.IOException; +import java.io.Serial; import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletException; @@ -35,6 +36,7 @@ import org.apache.jasper.compiler.Localizer; */ public abstract class HttpJspBase extends HttpServlet implements HttpJspPage { + @Serial private static final long serialVersionUID = 1L; protected HttpJspBase() { diff --git a/java/org/apache/jasper/runtime/JspWriterImpl.java b/java/org/apache/jasper/runtime/JspWriterImpl.java index f69ab08a03..f43da63928 100644 --- a/java/org/apache/jasper/runtime/JspWriterImpl.java +++ b/java/org/apache/jasper/runtime/JspWriterImpl.java @@ -27,8 +27,8 @@ import org.apache.jasper.Constants; import org.apache.jasper.compiler.Localizer; /** - * Write text to a character-output stream, buffering characters so as to provide for the efficient writing of single - * characters, arrays, and strings. Provide support for discarding for the output that has been buffered. This needs + * Write text to a character-output stream, buffering characters to provide efficient writing of single + * characters, arrays, and strings. Provide support for discarding the output that has been buffered. This needs * revisiting when the buffering problems in the JSP spec are fixed -akv * * @author Anil K. Vijendran @@ -202,7 +202,7 @@ public class JspWriterImpl extends JspWriter { } /** - * Our own little min method, to avoid loading java.lang.Math if we've run out of file descriptors and we're trying + * Our own little min method, to avoid loading java.lang.Math if we've run out of file descriptors, and we're trying * to print a stack trace. */ private static int min(int a, int b) { diff --git a/java/org/apache/jasper/servlet/JasperInitializer.java b/java/org/apache/jasper/servlet/JasperInitializer.java index 9d41424d8e..c813721467 100644 --- a/java/org/apache/jasper/servlet/JasperInitializer.java +++ b/java/org/apache/jasper/servlet/JasperInitializer.java @@ -59,7 +59,7 @@ public class JasperInitializer implements ServletContainerInitializer { log.debug(Localizer.getMessage(MSG + ".onStartup", context.getServletContextName())); } - // Setup a simple default Instance Manager + // Set up a simple default Instance Manager if (context.getAttribute(InstanceManager.class.getName()) == null) { context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager()); } diff --git a/java/org/apache/jasper/servlet/JspCServletContext.java b/java/org/apache/jasper/servlet/JspCServletContext.java index f87a933f16..ec3abc6d27 100644 --- a/java/org/apache/jasper/servlet/JspCServletContext.java +++ b/java/org/apache/jasper/servlet/JspCServletContext.java @@ -187,11 +187,7 @@ public class JspCServletContext implements ServletContext { List<URL> resourceJars = new ArrayList<>(); // Build list of potential resource JARs. Use same ordering as ContextConfig Set<WebXml> resourceFragments = new LinkedHashSet<>(orderedFragments); - for (WebXml fragment : fragments) { - if (!resourceFragments.contains(fragment)) { - resourceFragments.add(fragment); - } - } + resourceFragments.addAll(fragments); for (WebXml resourceFragment : resourceFragments) { try (Jar jar = JarFactory.newInstance(resourceFragment.getURL())) { diff --git a/java/org/apache/jasper/servlet/JspServlet.java b/java/org/apache/jasper/servlet/JspServlet.java index 1c1d376198..d4dad0274d 100644 --- a/java/org/apache/jasper/servlet/JspServlet.java +++ b/java/org/apache/jasper/servlet/JspServlet.java @@ -18,6 +18,7 @@ package org.apache.jasper.servlet; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.Serial; import java.lang.reflect.Constructor; import java.net.MalformedURLException; @@ -40,8 +41,8 @@ import org.apache.tomcat.PeriodicEventListener; import org.apache.tomcat.util.security.Escape; /** - * The JSP engine (a.k.a Jasper). The servlet container is responsible for providing a URLClassLoader for the web - * application context Jasper is being used in. Jasper will try get the Tomcat ServletContext attribute for its + * The Jasper JSP engine. The servlet container is responsible for providing a URLClassLoader for the web + * application context Jasper is being used in. Jasper will try to get the Tomcat ServletContext attribute for its * ServletContext class loader, if that fails, it uses the parent class loader. In either case, it must be a * URLClassLoader. * @@ -53,6 +54,7 @@ import org.apache.tomcat.util.security.Escape; */ public class JspServlet extends HttpServlet implements PeriodicEventListener { + @Serial private static final long serialVersionUID = 1L; // Logger diff --git a/java/org/apache/jasper/servlet/JspServletWrapper.java b/java/org/apache/jasper/servlet/JspServletWrapper.java index 2b98fe6a8f..cecbba20b7 100644 --- a/java/org/apache/jasper/servlet/JspServletWrapper.java +++ b/java/org/apache/jasper/servlet/JspServletWrapper.java @@ -49,8 +49,8 @@ import org.apache.tomcat.InstanceManager; import org.apache.tomcat.Jar; /** - * The JSP engine (a.k.a Jasper). The servlet container is responsible for providing a URLClassLoader for the web - * application context Jasper is being used in. Jasper will try get the Tomcat ServletContext attribute for its + * The Jasper JSP engine. The servlet container is responsible for providing a URLClassLoader for the web + * application context Jasper is being used in. Jasper will try to get the Tomcat ServletContext attribute for its * ServletContext class loader, if that fails, it uses the parent class loader. In either case, it must be a * URLClassLoader. * @@ -81,8 +81,8 @@ public class JspServletWrapper { private final ServletConfig config; private final Options options; /* - * The servlet / tag file needs a compilation check on first access. Use a separate flag (rather then theServlet == - * null / tagHandlerClass == null as it avoids the potentially expensive isOutDated() calls in ctxt.compile() if + * The servlet / tag file needs a compilation check on first access. Use a separate flag (rather than theServlet == + * null / tagHandlerClass == null) as it avoids the potentially expensive isOutDated() calls in ctxt.compile() if * there are multiple concurrent requests for the servlet / tag before the class has been loaded. */ private volatile boolean mustCompile = true; @@ -273,7 +273,7 @@ public class JspServletWrapper { /** * Compile and load a prototype for the Tag file. This is needed when compiling tag files with circular - * dependencies. A prototype (skeleton) with no dependencies on other other tag files is generated and compiled. + * dependencies. A prototype (skeleton) with no dependencies on other tag files is generated and compiled. * * @return the loaded class * @@ -513,8 +513,7 @@ public class JspServletWrapper { * Attempts to construct a JasperException that contains helpful information about what went wrong. Uses the JSP * compiler system to translate the line number in the generated servlet that originated the exception to a line * number in the JSP. Then constructs an exception containing that information, and a snippet of the JSP to help - * debugging. Please see https://bz.apache.org/bugzilla/show_bug.cgi?id=37062 and http://www.tfenne.com/jasper/ for - * more details. + * debugging. Please see <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=37062">BZ 37062</a> for more details. * </p> * * @param ex the exception that was the cause of the problem. @@ -549,7 +548,7 @@ public class JspServletWrapper { if (smap == null) { // If we couldn't find a frame in the stack trace corresponding - // to the generated servlet class or we don't have a copy of the + // to the generated servlet class, or we don't have a copy of the // smap to hand, we can't really add anything return new JasperException(ex); } @@ -560,16 +559,16 @@ public class JspServletWrapper { // If the line number is less than one we couldn't find out // where in the JSP things went wrong - if (source.getLineNumber() < 1) { + if (source.lineNumber() < 1) { throw new JasperException(ex); } JavacErrorDetail detail = new JavacErrorDetail(jspFrame.getMethodName(), javaLineNumber, - source.getFileName(), source.getLineNumber(), null, ctxt); + source.fileName(), source.lineNumber(), null, ctxt); if (options.getDisplaySourceFragment()) { return new JasperException( - Localizer.getMessage("jsp.exception", detail.getJspFileName(), "" + source.getLineNumber()) + + Localizer.getMessage("jsp.exception", detail.getJspFileName(), "" + source.lineNumber()) + System.lineSeparator() + System.lineSeparator() + detail.getJspExtract() + System.lineSeparator() + System.lineSeparator() + "Stacktrace:", ex); @@ -577,7 +576,7 @@ public class JspServletWrapper { } return new JasperException( - Localizer.getMessage("jsp.exception", detail.getJspFileName(), "" + source.getLineNumber()), ex); + Localizer.getMessage("jsp.exception", detail.getJspFileName(), "" + source.lineNumber()), ex); } catch (Exception je) { // If anything goes wrong, just revert to the original behaviour if (ex instanceof JasperException) { diff --git a/java/org/apache/jasper/tagplugins/jstl/core/ForEach.java b/java/org/apache/jasper/tagplugins/jstl/core/ForEach.java index b3d318f034..7a6634153d 100644 --- a/java/org/apache/jasper/tagplugins/jstl/core/ForEach.java +++ b/java/org/apache/jasper/tagplugins/jstl/core/ForEach.java @@ -71,7 +71,7 @@ public final class ForEach implements TagPlugin { } /** - * Generate codes for Collections The pseudo code is: + * Generate codes for Collections The pseudocode is: */ private void doCollection(TagPluginContext ctxt) { diff --git a/java/org/apache/jasper/tagplugins/jstl/core/Param.java b/java/org/apache/jasper/tagplugins/jstl/core/Param.java index d182cf118c..e9028b7c21 100644 --- a/java/org/apache/jasper/tagplugins/jstl/core/Param.java +++ b/java/org/apache/jasper/tagplugins/jstl/core/Param.java @@ -33,7 +33,7 @@ public class Param implements TagPlugin { String encName = ctxt.getTemporaryVariableName(); String index = ctxt.getTemporaryVariableName(); - // if the param tag has no parents, throw a exception + // if the param tag has no parents, throw an exception TagPluginContext parent = ctxt.getParentContext(); if (parent == null) { ctxt.generateJavaSource( diff --git a/java/org/apache/jasper/tagplugins/jstl/core/Set.java b/java/org/apache/jasper/tagplugins/jstl/core/Set.java index 1d02507fb4..501402a531 100644 --- a/java/org/apache/jasper/tagplugins/jstl/core/Set.java +++ b/java/org/apache/jasper/tagplugins/jstl/core/Set.java @@ -63,7 +63,7 @@ public class Set implements TagPlugin { // get the iScope according to the strScope iScope = Util.getScope(strScope); - String jspCtxt = null; + String jspCtxt; if (ctxt.isTagFile()) { jspCtxt = "this.getJspContext()"; } else { diff --git a/java/org/apache/jasper/tagplugins/jstl/core/When.java b/java/org/apache/jasper/tagplugins/jstl/core/When.java index b6568003e7..5bc75db74a 100644 --- a/java/org/apache/jasper/tagplugins/jstl/core/When.java +++ b/java/org/apache/jasper/tagplugins/jstl/core/When.java @@ -42,7 +42,7 @@ public final class When implements TagPlugin { ctxt.generateBody(); // We don't generate the closing "}" for the "if" here because there - // may be whitespaces in between <c:when>'s. Instead we delay + // may be whitespaces in between <c:when>'s. Instead, we delay // generating it until the next <c:when> or <c:otherwise> or // <c:choose> } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org