From 674386e49b7688ebd925216ff41de744d46668d1 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Tue, 20 Aug 2024 22:01:55 +0200 Subject: [PATCH] [fixes #3706] Add null check for compilation unit --- .../eclipse/handlers/EclipseHandlerUtil.java | 1 + .../noerrors/builderJavadoc/BuilderJavadoc.java | 14 ++++++++++++++ .../resource/noerrors/builderJavadoc/Usage.java | 7 +++++++ .../lombok/eclipse/compile/NoErrorsTest.java | 17 +++++++++++++++-- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 test/eclipse/resource/noerrors/builderJavadoc/BuilderJavadoc.java create mode 100644 test/eclipse/resource/noerrors/builderJavadoc/Usage.java diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 31554a869..83f8c941b 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -2838,6 +2838,7 @@ public static void setDocComment(CompilationUnitDeclaration cud, TypeDeclaration if (doc == null) return; ICompilationUnit compilationUnit = cud.compilationResult.compilationUnit; + if (compilationUnit == null) return; if (compilationUnit.getClass().equals(COMPILATION_UNIT)) { try { compilationUnit = (ICompilationUnit) Permit.invoke(COMPILATION_UNIT_ORIGINAL_FROM_CLONE, compilationUnit); diff --git a/test/eclipse/resource/noerrors/builderJavadoc/BuilderJavadoc.java b/test/eclipse/resource/noerrors/builderJavadoc/BuilderJavadoc.java new file mode 100644 index 000000000..745511a54 --- /dev/null +++ b/test/eclipse/resource/noerrors/builderJavadoc/BuilderJavadoc.java @@ -0,0 +1,14 @@ +package pkg; + +import lombok.Builder; + +@Builder +public class BuilderJavadoc { + /** + * Javadoc + * + * @param test ABC + * @return test + */ + private String test; +} \ No newline at end of file diff --git a/test/eclipse/resource/noerrors/builderJavadoc/Usage.java b/test/eclipse/resource/noerrors/builderJavadoc/Usage.java new file mode 100644 index 000000000..edf3d53d0 --- /dev/null +++ b/test/eclipse/resource/noerrors/builderJavadoc/Usage.java @@ -0,0 +1,7 @@ +package pkg; + +public class Usage { + public void test() { + BuilderJavadoc.builder().test("test").build(); + } +} \ No newline at end of file diff --git a/test/eclipse/src/lombok/eclipse/compile/NoErrorsTest.java b/test/eclipse/src/lombok/eclipse/compile/NoErrorsTest.java index 6d81d3812..d50496705 100644 --- a/test/eclipse/src/lombok/eclipse/compile/NoErrorsTest.java +++ b/test/eclipse/src/lombok/eclipse/compile/NoErrorsTest.java @@ -28,6 +28,7 @@ import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IProblemRequestor; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.WorkingCopyOwner; import org.eclipse.jdt.core.compiler.IProblem; import org.junit.Rule; @@ -47,6 +48,19 @@ public class NoErrorsTest { public void fieldNameConstantsInAnnotation() throws Exception { ICompilationUnit cu = setup.getPackageFragment().getCompilationUnit("Usage.java"); + List problems = collectProblems(cu); + assertTrue(problems.isEmpty()); + } + + @Test + public void builderJavadoc() throws Exception { + ICompilationUnit cu = setup.getPackageFragment().getCompilationUnit("Usage.java"); + + List problems = collectProblems(cu); + assertTrue(problems.isEmpty()); + } + + private List collectProblems(ICompilationUnit cu) throws JavaModelException { final List problems = new ArrayList(); final IProblemRequestor requestor = new IProblemRequestor() { @Override @@ -83,7 +97,6 @@ public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) { workingCopy.discardWorkingCopy(); } - System.out.println(problems); - assertTrue(problems.isEmpty()); + return problems; } }