Main Tutorials

PMD error – Can’t use JDK 1.5 for loop syntax when running in JDK 1.4 mode!

When i integrate Hudson and PMD together to run the PMD static code analysis process in my web project. I hit the following error message. By the way , i’m using Maven 2 to mange my web project.


Caused by: net.sourceforge.pmd.ast.ParseException: 
Can't use JDK 1.5 for loop syntax when running in JDK 1.4 mode!
	at net.sourceforge.pmd.ast.JavaParser.checkForBadJDK15ForLoopSyntaxArgumentsUsage
(JavaParser.java:36)
	at net.sourceforge.pmd.ast.JavaParser.ForStatement(JavaParser.java:4517)
	at net.sourceforge.pmd.ast.JavaParser.Statement(JavaParser.java:3969)
	at net.sourceforge.pmd.ast.JavaParser.BlockStatement(JavaParser.java:4100)
	at net.sourceforge.pmd.ast.JavaParser.Block(JavaParser.java:4061)
	at net.sourceforge.pmd.ast.JavaParser.MethodDeclaration(JavaParser.java:1333)
	at net.sourceforge.pmd.ast.JavaParser.ClassOrInterfaceBodyDeclaration(JavaParser.java:1007)
	at net.sourceforge.pmd.ast.JavaParser.ClassOrInterfaceBody(JavaParser.java:926)
	at net.sourceforge.pmd.ast.JavaParser.ClassOrInterfaceDeclaration(JavaParser.java:463)
	at net.sourceforge.pmd.ast.JavaParser.TypeDeclaration(JavaParser.java:355)
	at net.sourceforge.pmd.ast.JavaParser.CompilationUnit(JavaParser.java:126)
	at net.sourceforge.pmd.parsers.Java14Parser.parse(Java14Parser.java:17)
	at net.sourceforge.pmd.PMD.processFile(PMD.java:89)
	at net.sourceforge.pmd.PMD.processFile(PMD.java:66)
	at net.sourceforge.pmd.PMD.processFile(PMD.java:152)

The error message “Can’t use JDK 1.5 for loop syntax when running in JDK 1.4 mode” is look like JDK incompatible issue. PMD default JDK is using 1.4, we need to specify the PMD JDK version manually in Maven pom.xml file.


<!-- PMD Static Code Analysis  -->
   <plugin>
     <artifactId>maven-pmd-plugin</artifactId>
     <version>2.3</version>
     <configuration>
          <targetJdk>1.5</targetJdk>
     </configuration>
</plugin>

Done, PMD run with no errors.

P.S Do not put targetJdk = 1.6, cause PMD only support 1.4 and 1.5 at the moment, put JDK1.6 will make PMD ignore the setting and use JDK1.4 instead.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments