Repository navigation
SONARJAVA-7285 Compile Jasper helper classes with the JDK compiler - #6453
aurelien-coet-sonarsource wants to merge 6 commits into
Conversation
dc20e3c to
3486e62
Compare
| var compiler = ToolProvider.getSystemJavaCompiler(); | ||
| if (compiler == null) { | ||
| throw new JasperException("A JDK compiler is required to process JSP tag files"); | ||
| } |
There was a problem hiding this comment.
⚠️ Bug: JSP tag files now fail on JRE-only scanners that ship without javac
JasperOptions.getCompilerClassName() now always returns JasperCompiler. Tomcat 9.0.123's JspCompilationContext.createCompiler() uses that class directly and never falls back to JDTCompiler, and this PR also removes JDTCompiler*.class from the shaded jar. JasperCompiler.generateClass relies on ToolProvider.getSystemJavaCompiler(), which returns null when the jdk.compiler module is missing. That module is missing from the Temurin JREs SonarScanner downloads through JRE auto-provisioning (Temurin 21 module list, ToolProvider docs, scanner JRE provisioning).
Before this PR, Jasper compiled tag-file helper classes with JDTCompiler, using the unrelocated org.eclipse.jdt.internal.compiler classes that jdt-package still provides. That works on a plain JRE. After this PR, any JSP that uses a .tag file throws JasperException("A JDK compiler is required...") on a JRE runtime. Jasper.generateFiles catches the exception, drops the page, and logs only a generic warning, so those pages are silently left out of the analysis in the default scanner setup.
Suggested fix: fall back to the previous ECJ/JDT path (or another in-process compiler) when no system compiler is available, rather than failing. Also log a clear, user-visible warning that tag-file JSPs need a JDK.
Was this helpful? React with 👍 / 👎
Code Review
|
| Auto-apply | Compact | Unblock |
|
|
|
Was this helpful? React with 👍 / 👎 | Gitar
|
d5e9f9f to
847e881
Compare




Summary by Gitar
JasperCompiler, which compiles JSP tag helpers with the JDK compiler viaToolProviderJasperOptions.getCompilerClassName()now returnsJasperCompilerJDTCompiler*classes from the shaded jar insonar-java-plugin/pom.xmlJasperOptionsTestto expect the new compiler class nameThis will update automatically on new commits.