From f0b9bea23ef9b7930127f91379a0f8151042d9fd Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Wed, 7 Aug 2024 13:33:40 +0200 Subject: [PATCH] Fix #343 (le null check) --- resources/bytecode/javFiles/Bug343.jav | 2 ++ .../parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java | 5 ++++- src/test/java/TestComplete.java | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 resources/bytecode/javFiles/Bug343.jav diff --git a/resources/bytecode/javFiles/Bug343.jav b/resources/bytecode/javFiles/Bug343.jav new file mode 100644 index 00000000..3fa99067 --- /dev/null +++ b/resources/bytecode/javFiles/Bug343.jav @@ -0,0 +1,2 @@ +public record Bug343() { +} \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index de36c9f0..6d33464a 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -254,7 +254,10 @@ public class SyntaxTreeGenerator { List implementedInterfaces = new ArrayList<>(); List constructorParameters = new ArrayList<>(); List constructorStatements = new ArrayList<>(); - for (RecordComponentContext component : recordDeclaration.recordHeader().recordComponentList().recordComponent()) { + + List components = recordDeclaration.recordHeader().recordComponentList() != null ? + recordDeclaration.recordHeader().recordComponentList().recordComponent(): List.of(); + for (RecordComponentContext component : components) { int fieldmodifiers = allmodifiers.get("private") + allmodifiers.get("final"); String fieldname = component.identifier().getText(); Token fieldoffset = component.getStart(); diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index c4599e02..f3a7c638 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -1147,4 +1147,11 @@ public class TestComplete { var clazz = classFiles.get("Bug338"); var instance = clazz.getDeclaredConstructor().newInstance(); } + + @Test + public void testBug343() throws Exception { + var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug343.jav"); + var clazz = classFiles.get("Bug343"); + var instance = clazz.getDeclaredConstructor().newInstance(); + } }