diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 4a6cfbfda7..8511bbf890 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1921,7 +1921,7 @@ void AllocationExpression(): (LOOKAHEAD(2) PrimitiveType() ArrayDimsAndInits() | - ClassOrInterfaceType() ((Annotation() {checkForBadTypeAnnotations();})*) [ TypeArguments() ] + ClassOrInterfaceType() [ TypeArguments() ] ( ArrayDimsAndInits() | @@ -1937,8 +1937,9 @@ void AllocationExpression(): void ArrayDimsAndInits() : {} { + LOOKAHEAD(2) - ( LOOKAHEAD(2) "[" Expression() "]" )+ ( LOOKAHEAD(2) "[" "]" )* + ( LOOKAHEAD(2) ((Annotation() {checkForBadTypeAnnotations();})*) "[" Expression() "]" )+ ( LOOKAHEAD(2) "[" "]" )* | ( "[" "]" )+ ArrayInitializer() } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases18.java b/pmd-java/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases18.java index 0e9df63d68..b93b5a89b5 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases18.java +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases18.java @@ -184,6 +184,11 @@ public class ParserCornerCases18 { public Object createNonNullArray() { return new Object @NonNull[0]; } + + private static void testMultiDimArrayWithAnnotations() { + // ever used a 2D-Array in java?? + Object x = new Object @NonNull[2] @Nullable[1] @NonNull[3]; + } /**