#1172 PMD doesn't allow annotations in for loop initializer

New Tickets
open
nobody
None
PMD
3-Major
Bug
4.3
17 hours ago
2014-03-20
Björn Kautler
No

I use PMD Plugin of SonarQube which ships PMD 4.3.
It throws the following error:

11:36:09.776 ERROR - Fail to execute PMD. Following file is ignored: ....java
net.sourceforge.pmd.ast.ParseException: Encountered " "@" "@ "" at line 837, column 39.
Was expecting one of:
    "boolean" ...
    "byte" ...
    "char" ...
    "double" ...
    "false" ...
    "float" ...
    "int" ...
    "long" ...
    "new" ...
    "null" ...
    "short" ...
    "super" ...
    "this" ...
    "true" ...
    "void" ...
    <INTEGER_LITERAL> ...
    <FLOATING_POINT_LITERAL> ...
    <HEX_FLOATING_POINT_LITERAL> ...
    <CHARACTER_LITERAL> ...
    <STRING_LITERAL> ...
    <IDENTIFIER> ...
    "(" ...
    "++" ...
    "--" ...
    "boolean" ...
    "char" ...
    "byte" ...
    "short" ...
    "int" ...
    "long" ...
    "float" ...
    "double" ...
    <IDENTIFIER> ...
    "boolean" ...
    "char" ...
    "byte" ...
    "short" ...
    "int" ...
    "long" ...
    "float" ...
    "double" ...

        at net.sourceforge.pmd.ast.JavaParser.generateParseException(JavaParser.java:9853) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.jj_consume_token(JavaParser.java:9737) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.ForInit(JavaParser.java:4831) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.ForStatement(JavaParser.java:4689) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4070) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.BlockStatement(JavaParser.java:4201) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Block(JavaParser.java:4162) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4025) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.IfStatement(JavaParser.java:4517) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4061) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.BlockStatement(JavaParser.java:4201) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Block(JavaParser.java:4162) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4025) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.IfStatement(JavaParser.java:4522) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4061) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.BlockStatement(JavaParser.java:4201) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Block(JavaParser.java:4162) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4025) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.IfStatement(JavaParser.java:4517) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4061) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.BlockStatement(JavaParser.java:4201) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Block(JavaParser.java:4162) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4025) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.IfStatement(JavaParser.java:4517) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4061) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.IfStatement(JavaParser.java:4522) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4061) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.BlockStatement(JavaParser.java:4201) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Block(JavaParser.java:4162) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4025) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.IfStatement(JavaParser.java:4517) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4061) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.IfStatement(JavaParser.java:4522) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4061) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.BlockStatement(JavaParser.java:4201) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Block(JavaParser.java:4162) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4025) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.IfStatement(JavaParser.java:4522) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4061) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.BlockStatement(JavaParser.java:4201) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Block(JavaParser.java:4162) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4025) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.IfStatement(JavaParser.java:4517) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4061) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.BlockStatement(JavaParser.java:4201) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Block(JavaParser.java:4162) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4025) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.IfStatement(JavaParser.java:4517) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4061) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.BlockStatement(JavaParser.java:4201) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Block(JavaParser.java:4162) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4025) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.IfStatement(JavaParser.java:4517) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4061) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.IfStatement(JavaParser.java:4522) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:4061) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.BlockStatement(JavaParser.java:4201) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.Block(JavaParser.java:4162) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.MethodDeclaration(JavaParser.java:1416) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.ClassOrInterfaceBodyDeclaration(JavaParser.java:1085) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.ClassOrInterfaceBody(JavaParser.java:1004) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.ClassOrInterfaceDeclaration(JavaParser.java:514) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.TypeDeclaration(JavaParser.java:406) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.ast.JavaParser.CompilationUnit(JavaParser.java:164) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.parsers.Java17Parser.parse(Java17Parser.java:23) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.PMD.processFile(PMD.java:98) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.PMD.processFile(PMD.java:75) ~[pmd-4.3.jar:na]
        at net.sourceforge.pmd.PMD.processFile(PMD.java:210) ~[pmd-4.3.jar:na]
        at org.sonar.plugins.pmd.PmdTemplate.process(PmdTemplate.java:72) ~[sonar-pmd-plugin-2.0.jar:na]
        at org.sonar.plugins.pmd.PmdExecutor.executeRules(PmdExecutor.java:108) [sonar-pmd-plugin-2.0.jar:na]
        at org.sonar.plugins.pmd.PmdExecutor.executePmd(PmdExecutor.java:83) [sonar-pmd-plugin-2.0.jar:na]
        at org.sonar.plugins.pmd.PmdExecutor.execute(PmdExecutor.java:69) [sonar-pmd-plugin-2.0.jar:na]
        at org.sonar.plugins.pmd.PmdSensor.analyse(PmdSensor.java:52) [sonar-pmd-plugin-2.0.jar:na]
        at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:72) [sonar-batch-4.1.2.jar:na]
        at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:114) [sonar-batch-4.1.2.jar:na]
        at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:150) [sonar-batch-4.1.2.jar:na]
        at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92) [sonar-plugin-api-4.1.2.jar:na]
        at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77) [sonar-plugin-api-4.1.2.jar:na]
        at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:211) [sonar-batch-4.1.2.jar:na]
        at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:206) [sonar-batch-4.1.2.jar:na]
        at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:204) [sonar-batch-4.1.2.jar:na]
        at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:199) [sonar-batch-4.1.2.jar:na]
        at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92) [sonar-plugin-api-4.1.2.jar:na]
        at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77) [sonar-plugin-api-4.1.2.jar:na]
        at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:58) [sonar-batch-4.1.2.jar:na]
        at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:45) [sonar-batch-4.1.2.jar:na]
        at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:82) [sonar-batch-4.1.2.jar:na]
        at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92) [sonar-plugin-api-4.1.2.jar:na]
        at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77) [sonar-plugin-api-4.1.2.jar:na]
        at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapContainer.java:144) [sonar-batch-4.1.2.jar:na]
        at org.sonar.batch.bootstrap.BootstrapContainer.doAfterStart(BootstrapContainer.java:132) [sonar-batch-4.1.2.jar:na]
        at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92) [sonar-plugin-api-4.1.2.jar:na]
        at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77) [sonar-plugin-api-4.1.2.jar:na]
        at org.sonar.batch.bootstrapper.Batch.startBatch(Batch.java:92) [sonar-batch-4.1.2.jar:na]
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:74) [sonar-batch-4.1.2.jar:na]
        at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:45) [sonar-runner-batch6759992777271299235.jar:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_11]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_11]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_11]
        at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_11]
        at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87) [sonar-runner-dist-2.3.jar:na]
        at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75) [sonar-runner-dist-2.3.jar:na]
        at java.security.AccessController.doPrivileged(Native Method) [na:1.7.0_11]
        at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69) [sonar-runner-dist-2.3.jar:na]
        at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50) [sonar-runner-dist-2.3.jar:na]
        at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102) [sonar-runner-dist-2.3.jar:na]
        at org.sonar.runner.api.Runner.execute(Runner.java:90) [sonar-runner-dist-2.3.jar:na]
        at org.sonar.runner.Main.executeTask(Main.java:70) [sonar-runner-dist-2.3.jar:na]
        at org.sonar.runner.Main.execute(Main.java:59) [sonar-runner-dist-2.3.jar:na]
        at org.sonar.runner.Main.main(Main.java:41) [sonar-runner-dist-2.3.jar:na]

for a code line that reads

for (@SuppressWarnings("unchecked")
Enumeration<TreeNode> e = parent.children(); e.hasMoreElements();)
{
   ...
}

Discussion

  • Björn Kautler
    Björn Kautler
    2014-03-30

    hm, duplicate of [#1007], sorry

     

    Related

    Issues: #1007

  • Andreas Dangel
    Andreas Dangel
    2014-03-30

    Yes, it's fixed with PMD 5.0.2. However, SonarQube would need to be updated to use at least this version instead of PMD 4.3.
    There are currently no plans to fix this bug in PMD 4.3.

     
  • Björn Kautler
    Björn Kautler
    2014-05-22

    SonarQube released a new version of the pmd plugin that incorporates pmd 5.1.1, so this bug should be gone. I just get a StackOverflowError from within PMD now, but I'll open a separate issue for this if there is none.