This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 49d68a0259 Fix various minor Jasper issues from code review
49d68a0259 is described below
commit 49d68a0259273831c5e9e810d0952214bbdcc943
Author: remm <[email protected]>
AuthorDate: Mon Jun 1 09:11:32 2026 +0200
Fix various minor Jasper issues from code review
---
java/org/apache/jasper/compiler/ELParser.java | 6 ++
java/org/apache/jasper/compiler/JDTCompiler.java | 3 +-
java/org/apache/jasper/compiler/JavaCompiler.java | 101 +++++++++++----------
java/org/apache/jasper/compiler/Node.java | 2 +-
java/org/apache/jasper/compiler/PageInfo.java | 4 +-
java/org/apache/jasper/compiler/SmapStratum.java | 3 +-
java/org/apache/jasper/compiler/SmapUtil.java | 49 ++++++----
.../apache/jasper/compiler/TagFileProcessor.java | 7 +-
.../jasper/resources/LocalStrings.properties | 1 +
9 files changed, 102 insertions(+), 74 deletions(-)
diff --git a/java/org/apache/jasper/compiler/ELParser.java
b/java/org/apache/jasper/compiler/ELParser.java
index 4aab6fcd3e..e3f6023487 100644
--- a/java/org/apache/jasper/compiler/ELParser.java
+++ b/java/org/apache/jasper/compiler/ELParser.java
@@ -355,6 +355,7 @@ public class ELParser {
private Token parseQuotedChars(char quote) {
StringBuilder buf = new StringBuilder();
buf.append(quote);
+ boolean foundQuote = false;
while (hasNextChar()) {
char ch = nextChar();
if (ch == '\\') {
@@ -366,12 +367,17 @@ public class ELParser {
Localizer.getMessage("org.apache.jasper.compiler.ELParser.invalidQuoting",
expression));
}
} else if (ch == quote) {
+ foundQuote = true;
buf.append(ch);
break;
} else {
buf.append(ch);
}
}
+ if (!foundQuote) {
+ throw new IllegalArgumentException(
+
Localizer.getMessage("org.apache.jasper.compiler.ELParser.missingQuote",
expression));
+ }
return new QuotedString(getAndResetWhiteSpace(), buf.toString());
}
diff --git a/java/org/apache/jasper/compiler/JDTCompiler.java
b/java/org/apache/jasper/compiler/JDTCompiler.java
index 6fa8fa0350..f5d5485729 100644
--- a/java/org/apache/jasper/compiler/JDTCompiler.java
+++ b/java/org/apache/jasper/compiler/JDTCompiler.java
@@ -106,7 +106,7 @@ public class JDTCompiler extends
org.apache.jasper.compiler.Compiler {
@Override
public char[] getContents() {
- char[] result = null;
+ char[] result;
try (FileInputStream is = new FileInputStream(sourceFile);
InputStreamReader isr = new InputStreamReader(is,
ctxt.getOptions().getJavaEncoding());
Reader reader = new BufferedReader(isr)) {
@@ -120,6 +120,7 @@ public class JDTCompiler extends
org.apache.jasper.compiler.Compiler {
buf.getChars(0, result.length, result, 0);
} catch (IOException ioe) {
log.error(Localizer.getMessage("jsp.error.compilation.source", sourceFile),
ioe);
+ result = new char[0];
}
return result;
}
diff --git a/java/org/apache/jasper/compiler/JavaCompiler.java
b/java/org/apache/jasper/compiler/JavaCompiler.java
index 67394cea0c..c5d23a57bf 100644
--- a/java/org/apache/jasper/compiler/JavaCompiler.java
+++ b/java/org/apache/jasper/compiler/JavaCompiler.java
@@ -49,7 +49,7 @@ public class JavaCompiler extends Compiler {
private final Log log = LogFactory.getLog(JavaCompiler.class); // must not
be static
@Override
- protected void generateClass(Map<String,SmapStratum> smaps) throws
JasperException, IOException {
+ protected void generateClass(Map<String, SmapStratum> smaps) throws
JasperException, IOException {
long t1 = 0;
if (log.isDebugEnabled()) {
@@ -58,63 +58,66 @@ public class JavaCompiler extends Compiler {
javax.tools.JavaCompiler compiler =
ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnostics = new
DiagnosticCollector<>();
- StandardJavaFileManager fileManager =
compiler.getStandardFileManager(diagnostics, null,
- Charset.forName(ctxt.getOptions().getJavaEncoding()));
- List<File> compilationUnitsList = new ArrayList<>(1);
- compilationUnitsList.add(new File(ctxt.getServletJavaFileName()));
- Iterable<? extends JavaFileObject> compilationUnits =
-
fileManager.getJavaFileObjectsFromFiles(Collections.unmodifiableList(compilationUnitsList));
- // Perform Java compilation using the appropriate options
- List<String> compilerOptionsList = new ArrayList<>(6);
- compilerOptionsList.add("-classpath");
- compilerOptionsList.add(ctxt.getClassPath());
- compilerOptionsList.add("-source");
- compilerOptionsList.add(ctxt.getOptions().getCompilerSourceVM());
- compilerOptionsList.add("-target");
- compilerOptionsList.add(ctxt.getOptions().getCompilerTargetVM());
- List<String> compilerOptions =
Collections.unmodifiableList(compilerOptionsList);
- Boolean result =
- compiler.getTask(null, fileManager, diagnostics,
compilerOptions, null, compilationUnits).call();
-
- List<JavacErrorDetail> problemList = new ArrayList<>();
- if (!result.booleanValue()) {
- for (Diagnostic<? extends JavaFileObject> diagnostic :
diagnostics.getDiagnostics()) {
- if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
- try {
-
problemList.add(ErrorDispatcher.createJavacError(diagnostic.getSource().getName(),
pageNodes,
- new
StringBuilder(diagnostic.getMessage(Locale.getDefault())),
- (int) diagnostic.getLineNumber(), ctxt));
- } catch (JasperException e) {
-
log.error(Localizer.getMessage("jsp.error.compilation.jdtProblemError"), e);
+ try (StandardJavaFileManager fileManager =
compiler.getStandardFileManager(diagnostics, null,
+ Charset.forName(ctxt.getOptions().getJavaEncoding()))) {
+ List<File> compilationUnitsList = new ArrayList<>(1);
+ compilationUnitsList.add(new File(ctxt.getServletJavaFileName()));
+ Iterable<? extends JavaFileObject> compilationUnits = fileManager
+
.getJavaFileObjectsFromFiles(Collections.unmodifiableList(compilationUnitsList));
+ // Perform Java compilation using the appropriate options
+ List<String> compilerOptionsList = new ArrayList<>(6);
+ compilerOptionsList.add("-classpath");
+ compilerOptionsList.add(ctxt.getClassPath());
+ compilerOptionsList.add("-source");
+ compilerOptionsList.add(ctxt.getOptions().getCompilerSourceVM());
+ compilerOptionsList.add("-target");
+ compilerOptionsList.add(ctxt.getOptions().getCompilerTargetVM());
+ List<String> compilerOptions =
Collections.unmodifiableList(compilerOptionsList);
+ Boolean result = compiler.getTask(null, fileManager, diagnostics,
compilerOptions, null, compilationUnits)
+ .call();
+
+ List<JavacErrorDetail> problemList = new ArrayList<>();
+ if (!result.booleanValue()) {
+ for (Diagnostic<? extends JavaFileObject> diagnostic :
diagnostics.getDiagnostics()) {
+ if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
+ try {
+
problemList.add(ErrorDispatcher.createJavacError(diagnostic.getSource().getName(),
+ pageNodes, new
StringBuilder(diagnostic.getMessage(Locale.getDefault())),
+ (int) diagnostic.getLineNumber(), ctxt));
+ } catch (JasperException e) {
+
log.error(Localizer.getMessage("jsp.error.compilation.jdtProblemError"), e);
+ }
}
}
}
- }
- if (!ctxt.keepGenerated()) {
- File javaFile = new File(ctxt.getServletJavaFileName());
- if (!javaFile.delete()) {
- throw new
JasperException(Localizer.getMessage("jsp.warning.compiler.javafile.delete.fail",
javaFile));
+ if (!ctxt.keepGenerated()) {
+ File javaFile = new File(ctxt.getServletJavaFileName());
+ if (!javaFile.delete()) {
+ throw new JasperException(
+
Localizer.getMessage("jsp.warning.compiler.javafile.delete.fail", javaFile));
+ }
}
- }
- if (!problemList.isEmpty()) {
- JavacErrorDetail[] jeds = problemList.toArray(new
JavacErrorDetail[0]);
- errDispatcher.javacError(jeds);
- }
+ if (!problemList.isEmpty()) {
+ JavacErrorDetail[] jeds = problemList.toArray(new
JavacErrorDetail[0]);
+ errDispatcher.javacError(jeds);
+ }
- if (log.isDebugEnabled()) {
- long t2 = System.currentTimeMillis();
- log.debug(Localizer.getMessage("jsp.compiled",
ctxt.getServletJavaFileName(), Long.valueOf(t2 - t1)));
- }
+ if (log.isDebugEnabled()) {
+ long t2 = System.currentTimeMillis();
+ log.debug(Localizer.getMessage("jsp.compiled",
ctxt.getServletJavaFileName(), Long.valueOf(t2 - t1)));
+ }
- if (ctxt.isPrototypeMode()) {
- return;
- }
+ if (ctxt.isPrototypeMode()) {
+ return;
+ }
+
+ // JSR45 Support
+ if (!options.isSmapSuppressed()) {
+ SmapUtil.installSmap(smaps);
+ }
- // JSR45 Support
- if (!options.isSmapSuppressed()) {
- SmapUtil.installSmap(smaps);
}
}
diff --git a/java/org/apache/jasper/compiler/Node.java
b/java/org/apache/jasper/compiler/Node.java
index 2843442a3c..12270a8b5f 100644
--- a/java/org/apache/jasper/compiler/Node.java
+++ b/java/org/apache/jasper/compiler/Node.java
@@ -2883,7 +2883,7 @@ public abstract class Node implements TagConstants {
Node n = null;
try {
n = list.get(index);
- } catch (ArrayIndexOutOfBoundsException e) {
+ } catch (IndexOutOfBoundsException e) {
// Ignore
}
return n;
diff --git a/java/org/apache/jasper/compiler/PageInfo.java
b/java/org/apache/jasper/compiler/PageInfo.java
index cc753e4931..e0f3b3f1e7 100644
--- a/java/org/apache/jasper/compiler/PageInfo.java
+++ b/java/org/apache/jasper/compiler/PageInfo.java
@@ -476,7 +476,9 @@ public class PageInfo {
*/
public void popPrefixMapping(String prefix) {
Deque<String> stack = xmlPrefixMapper.get(prefix);
- stack.removeFirst();
+ if (stack != null) {
+ stack.removeFirst();
+ }
}
/**
diff --git a/java/org/apache/jasper/compiler/SmapStratum.java
b/java/org/apache/jasper/compiler/SmapStratum.java
index 902e827293..68afa20a46 100644
--- a/java/org/apache/jasper/compiler/SmapStratum.java
+++ b/java/org/apache/jasper/compiler/SmapStratum.java
@@ -406,7 +406,8 @@ public class SmapStratum {
}
// This is the match
- int inputOffset = (outputLineNumber - lineInfo.outputStartLine) /
lineInfo.outputLineIncrement;
+ int inputOffset = (outputLineNumber - lineInfo.outputStartLine)
+ / (lineInfo.outputLineIncrement == 0 ? 1 :
lineInfo.outputLineIncrement);
inputLineNumber = lineInfo.inputStartLine + inputOffset;
}
diff --git a/java/org/apache/jasper/compiler/SmapUtil.java
b/java/org/apache/jasper/compiler/SmapUtil.java
index df2ba26b00..fe12bff837 100644
--- a/java/org/apache/jasper/compiler/SmapUtil.java
+++ b/java/org/apache/jasper/compiler/SmapUtil.java
@@ -713,10 +713,16 @@ public class SmapUtil {
String fileName = lines[lineIndex].substring(i + 1);
smapStratum.addFile(fileName, lines[++lineIndex]);
lineIndex++;
+ if (lineIndex == lines.length) {
+ return null;
+ }
}
// Skip *L
lineIndex++;
+ if (lineIndex == lines.length) {
+ return null;
+ }
while (!lines[lineIndex].equals("*E")) {
LineInfo li = new LineInfo();
@@ -746,6 +752,9 @@ public class SmapUtil {
smapStratum.addLineInfo(li);
lineIndex++;
+ if (lineIndex == lines.length) {
+ return null;
+ }
}
return smapStratum;
@@ -765,27 +774,29 @@ public class SmapUtil {
found = true;
} else {
is = cl.getResourceAsStream(className.replace(".", "/") +
".class");
- // Alternative approach would be to read the class file as per
the
- // JLS. That would require duplicating a lot of BCEL
functionality.
- int b = is.read();
- while (b != -1) {
- if (b == 'S') {
- if ((b = is.read()) != 'M') {
- continue;
- }
- if ((b = is.read()) != 'A') {
- continue;
- }
- if ((b = is.read()) != 'P') {
- continue;
- }
- if ((b = is.read()) != '\n') {
- continue;
+ if (is != null) {
+ // Alternative approach would be to read the class file as
per the
+ // JLS. That would require duplicating a lot of BCEL
functionality.
+ int b = is.read();
+ while (b != -1) {
+ if (b == 'S') {
+ if ((b = is.read()) != 'M') {
+ continue;
+ }
+ if ((b = is.read()) != 'A') {
+ continue;
+ }
+ if ((b = is.read()) != 'P') {
+ continue;
+ }
+ if ((b = is.read()) != '\n') {
+ continue;
+ }
+ found = true;
+ break;
}
- found = true;
- break;
+ b = is.read();
}
- b = is.read();
}
}
diff --git a/java/org/apache/jasper/compiler/TagFileProcessor.java
b/java/org/apache/jasper/compiler/TagFileProcessor.java
index 42dfe29624..4ce15c5cab 100644
--- a/java/org/apache/jasper/compiler/TagFileProcessor.java
+++ b/java/org/apache/jasper/compiler/TagFileProcessor.java
@@ -19,6 +19,7 @@ package org.apache.jasper.compiler;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -643,12 +644,14 @@ public class TagFileProcessor {
* @param classFileName If non-null, remove only the class file with this
name.
*/
public void removeProtoTypeFiles(String classFileName) {
- for (Compiler c : tempVector) {
+ Iterator<Compiler> compilers = tempVector.iterator();
+ while (compilers.hasNext()) {
+ Compiler c = compilers.next();
if (classFileName == null) {
c.removeGeneratedClassFiles();
} else if
(classFileName.equals(c.getCompilationContext().getClassFileName())) {
c.removeGeneratedClassFiles();
- tempVector.remove(c);
+ compilers.remove();
return;
}
}
diff --git a/java/org/apache/jasper/resources/LocalStrings.properties
b/java/org/apache/jasper/resources/LocalStrings.properties
index 983f41d1b7..3890bfd122 100644
--- a/java/org/apache/jasper/resources/LocalStrings.properties
+++ b/java/org/apache/jasper/resources/LocalStrings.properties
@@ -423,6 +423,7 @@ jstl.writerAfterOS=Cannot use a writer if an output stream
has been used
org.apache.jasper.compiler.ELParser.invalidQuotesForStringLiteral=The String
literal [{0}] is not valid. It must be contained within single or double quotes.
org.apache.jasper.compiler.ELParser.invalidQuoting=The expression [{0}] is not
valid. Within a quoted String only [], [''] and ["] may be escaped with [].
+org.apache.jasper.compiler.ELParser.missingQuote=The expression [{0}] is not
valid as it is missing an end quote.
org.apache.jasper.compiler.TldCache.servletContextNull=The provided
ServletContext was null
org.apache.jasper.servlet.JasperInitializer.onStartup=Initializing Jasper for
context [{0}]
org.apache.jasper.servlet.TldScanner.webxmlAdd=Loading TLD for URI [{1}] from
resource path [{0}]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]