diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 34a5347f04..60da8efd49 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -935,7 +935,6 @@ void RecordConstructorDeclaration(): modifiers = Modifiers() { jjtThis.setModifiers(modifiers); } [TypeParameters()] { jjtThis.setImage(token.image); } - [ "throws" NameList() ] "{" ( BlockStatement() )* "}" } diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java14PreviewTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java14PreviewTest.java index 27fb1b1ac1..be98bbb9d5 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java14PreviewTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java14PreviewTest.java @@ -98,7 +98,7 @@ public class Java14PreviewTest { Assert.assertEquals("Point", recordDecl.getImage()); Assert.assertFalse(recordDecl.isNested()); List components = recordDecl.getFirstChildOfType(ASTRecordComponentList.class) - .findChildrenOfType(ASTRecordComponent.class); + .findChildrenOfType(ASTRecordComponent.class); Assert.assertEquals(2, components.size()); Assert.assertEquals("x", components.get(0).getVariableDeclaratorId().getImage()); Assert.assertEquals("y", components.get(1).getVariableDeclaratorId().getImage()); @@ -109,6 +109,13 @@ public class Java14PreviewTest { java14.parseResource("Point.java"); } + @Test(expected = ParseException.class) + public void recordCtorWithThrowsShouldFail() { + java14p.parse(" record R {" + + " R throws IOException {}" + + " }"); + } + @Test public void innerRecords() { ASTCompilationUnit compilationUnit = java14p.parseResource("Records.java"); diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/Records.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/Records.java index a1be788be7..2368b2ae7c 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/Records.java +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/Records.java @@ -57,8 +57,5 @@ public class Records { public record PersonRecord(String firstName, String lastName) implements Person, java.io.Serializable { - PersonRecord throws IOException { // compact ctor with throws list - throw new IOException(); - } } }