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
	at net.sourceforge.pmd.ast.JavaParser.ForStatement(
	at net.sourceforge.pmd.ast.JavaParser.Statement(
	at net.sourceforge.pmd.ast.JavaParser.BlockStatement(
	at net.sourceforge.pmd.ast.JavaParser.Block(
	at net.sourceforge.pmd.ast.JavaParser.MethodDeclaration(
	at net.sourceforge.pmd.ast.JavaParser.ClassOrInterfaceBodyDeclaration(
	at net.sourceforge.pmd.ast.JavaParser.ClassOrInterfaceBody(
	at net.sourceforge.pmd.ast.JavaParser.ClassOrInterfaceDeclaration(
	at net.sourceforge.pmd.ast.JavaParser.TypeDeclaration(
	at net.sourceforge.pmd.ast.JavaParser.CompilationUnit(
	at net.sourceforge.pmd.parsers.Java14Parser.parse(
	at net.sourceforge.pmd.PMD.processFile(
	at net.sourceforge.pmd.PMD.processFile(
	at net.sourceforge.pmd.PMD.processFile(

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  -->

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 the Author

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


0 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
0 Comment authors
Recent comment authors
newest oldest most voted