diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 847398ce2d..dddb29ff17 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -2224,9 +2224,9 @@ void BlockStatement() #void: private void LocalTypeStartNoIdent() #void: // A lookahead {} -{ // notice: not default - "public" | "static" | "protected" | "private" | "final" - | "abstract" | "synchronized" | "native" | "transient" +{ // notice: not default, not synchronized, not final + "public" | "static" | "protected" | "private" + | "abstract" | "native" | "transient" | "volatile" | "strictfp" | "class" | "interface" diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java index ada51709ee..2c4faf85f9 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java @@ -222,6 +222,11 @@ public class ParserCornersTest extends BaseJavaTreeDumpTest { doTest("SwitchStatements"); } + @Test + public void testSynchronizedStatements() { + doTest("SynchronizedStmts"); + } + private static final String GENERICS_PROBLEM = "public class Test {\n public void test() {\n String o = super. doStuff(\"\");\n }\n}"; diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SynchronizedStmts.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SynchronizedStmts.java new file mode 100644 index 0000000000..2782f54288 --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SynchronizedStmts.java @@ -0,0 +1,9 @@ + +class Sync { + public static void getInstance() { + synchronized (0) { // note that synchronized is also a modifier + return; + } + } + +} diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SynchronizedStmts.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SynchronizedStmts.txt new file mode 100644 index 0000000000..8ee7e54976 --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SynchronizedStmts.txt @@ -0,0 +1,13 @@ ++- CompilationUnit[@PackageName = ""] + +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "Sync", @CanonicalName = "Sync", @Enum = "false", @Interface = "false", @Local = "false", @Nested = "false", @PackageName = "", @PackagePrivate = "true", @Record = "false", @RegularClass = "true", @SimpleName = "Sync", @TopLevel = "true", @Visibility = "package"] + +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + +- ClassOrInterfaceBody[@Size = "1"] + +- MethodDeclaration[@Abstract = "false", @Arity = "0", @Image = "getInstance", @Name = "getInstance", @Varargs = "false", @Visibility = "public", @Void = "true"] + +- ModifierList[@EffectiveModifiers = "{public, static}", @ExplicitModifiers = "{public, static}"] + +- VoidType[] + +- FormalParameters[@Size = "0"] + +- Block[@Size = "1", @containsComment = "false"] + +- SynchronizedStatement[] + +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "0", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @PrimitiveType = "int", @ValueAsDouble = "0.0", @ValueAsFloat = "0.0", @ValueAsInt = "0", @ValueAsLong = "0"] + +- Block[@Size = "1", @containsComment = "false"] + +- ReturnStatement[]