- ALM used: GitHub
- CI system used: Jenkins
- Scanner command used:
mvn -X -Duser.home=.home org.sonarsource.scanner.maven:sonar-maven-plugin:sonar --batch-mode ...
- Languages of the repository: Java, JSP, JS
- Error observed
[WARNING] 15:08:30.510 Unresolved imports/types have been detected during analysis. Enable DEBUG mode to see them.
[DEBUG] 15:08:30.510 Unresolved imports/types:
- org.apache.jsp.tag cannot be resolved to a type
* <pathtodir>/target/sonar/jsp/org/apache/jsp/WEB_002dINF/views/sonar_jsp.java
Create 2 files
sonar.jsp
<%@ taglib prefix="t" tagdir="/WEB-INF/tags"%>
<t:sonartemplate>test content</t:sonartemplate>
sonartemplate.tag
<!DOCTYPE html>
<%@ tag language="java" description="Template to reproduce Sonar JSP issue"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<jsp:doBody/>
</body>
</html>
Extra details:
The compiled jsp in the target/sonar directory has lines
// t:sonartemplate
org.apache.jsp.tag.web.sonartemplate_tag _jspx_th_t_005fsonartemplate_005f0 = new org.apache.jsp.tag.web.sonartemplate_tag();
The compiled tag is also existing in the target/sonar directory but maybe not added to the sonar analyzer properly.
Hello, @lrozenblyum, I was able to reproduce your problem in SonarQube Enterprise edition. There is a semantic issue when the AST is generated and it should be caused by the missing tag name.
In sonar.jsp there is a reference to the tag named sonartemplate:
<t:sonartemplate>test content</t:sonartemplate>
In sonartemplate.tag the tag is missing the name attribute:
<%@ tag language="java" description="Template to reproduce Sonar JSP issue"%>
Can you try by using the following version?
<!DOCTYPE html>
<%@ tag name="sonartemplate" language="java" description="Template to reproduce Sonar JSP issue"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<jsp:doBody/>
</body>
</html>
Cheers,
Angelo
Hello @angelo.buono!
I tried the suggestion and it fails transpiling now.
It seems the tag
directive doesn’t support the name
attribute, see also Declaring Tags (The Java EE 5 Tutorial)
[DEBUG] 12:49:24.901 Error transpiling Orange/src/main/webapp/WEB-INF/views/sonar.jsp. Error:
java.lang.RuntimeException: org.apache.jasper.JasperException: file:/home/jenkins/workspace/workspace/Analyze-Branch-Sonar/Orange/src/main/webapp/WEB-INF/tags/sonartemplate.tag (line: [2], column: [1]) [Tag directive] has invalid attribute: [name]
at org.apache.jasper.compiler.ImplicitTagLibraryInfo.getTagFile(ImplicitTagLibraryInfo.java:185)
at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1232)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1475)
at org.apache.jasper.compiler.Parser.parse(Parser.java:144)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:245)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:106)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:207)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:392)
at org.sonar.java.jsp.Jasper.transpileJsp(Jasper.java:166)
at org.sonar.java.jsp.Jasper.generateFiles(Jasper.java:103)
at org.sonar.plugins.java.JavaSensor.runJasper(JavaSensor.java:171)
at org.sonar.plugins.java.JavaSensor.execute(JavaSensor.java:113)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:62)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:48)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:66)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:48)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:64)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:192)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:188)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:185)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:159)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
at org.sonar.scanner.bootstrap.ScannerContainer.doAfterStart(ScannerContainer.java:399)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:131)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:60)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:54)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at jdk.proxy3/jdk.proxy3.$Proxy25.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:88)
at org.sonarsource.scanner.maven.SonarQubeMojo.execute(SonarQubeMojo.java:106)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Caused by: org.apache.jasper.JasperException: file:/home/jenkins/workspace/workspace/Analyze-Branch-Sonar/Orange/src/main/webapp/WEB-INF/tags/sonartemplate.tag (line: [2], column: [1]) [Tag directive] has invalid attribute: [name]
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:299)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:99)
at org.apache.jasper.compiler.JspUtil.checkAttributes(JspUtil.java:208)
at org.apache.jasper.compiler.TagFileProcessor$TagFileDirectiveVisitor.visit(TagFileProcessor.java:148)
at org.apache.jasper.compiler.Node$TagDirective.accept(Node.java:680)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2381)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2437)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2443)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:467)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2381)
at org.apache.jasper.compiler.TagFileProcessor.parseTagFileDirectives(TagFileProcessor.java:503)
at org.apache.jasper.compiler.ImplicitTagLibraryInfo.getTagFile(ImplicitTagLibraryInfo.java:183)
... 66 more
[WARNING] 12:49:24.909 Some JSP pages failed to transpile. Enable debug log for details.
Hello @lrozenblyum, I’m afraid I can’t help you with this issue; it is not related to SonarQube or the Java Analyzer.
I would recommend reading the documentation about Tag Handlers and searching for examples and solutions online, for example, jsp - how to use the directive 'name-from-attribute' - Stack Overflow.
Cheers,
Angelo
@angelo.buono maybe we have some confusion here. You’ve sent a link to the documentation for the ‘tld’ file and attribute ‘name’ inside it.
But in our case we don’t have the *.tld file at all.
We have just a *.tag file
Hello, @lrozenblyum.
I want to clarify that the goal of the Sonar Community is to gather feedback to improve our products, not to assist users with problems in their projects.
I’m not an expert in JSP and the answers I can provide you are a result of checking documentation and googling.
After checking the documentation about Declaring Tag Files:
Unpackaged Tag Files
Tag files placed in a subdirectory of /WEB-INF/tags/ do not require a TLD file and don’t have to be packaged. Thus, to create reusable JSP code, you simply create a new tag file and place the code inside it.
And the documentation about configuring Tag Libraries, I think that you may be missing configuring the taglib in the web.xml
:
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/tags</taglib-uri>
<taglib-location>/WEB-INF/tags</taglib-location>
</taglib>
</jsp-config>
I hope this helps. Please reach out if you find an issue with the project’s analysis.
Kind regards,
Angelo
1 Like
I see, thanks for your contribution @angelo.buono.
Yes originally I’ve reported the issue with the analysis log which I believe could be an issue on the sonar scanner.
[WARNING] 15:08:30.510 Unresolved imports/types have been detected during analysis. Enable DEBUG mode to see them.
[DEBUG] 15:08:30.510 Unresolved imports/types:
- org.apache.jsp.tag cannot be resolved to a type
* <pathtodir>/target/sonar/jsp/org/apache/jsp/WEB_002dINF/views/sonar_jsp.java
1 Like