Skip to content

Commit

Permalink
Merge pull request #3726 from Rawi01/npe-builder-javadoc
Browse files Browse the repository at this point in the history
Add null check for compilation unit
  • Loading branch information
rzwitserloot authored Sep 10, 2024
2 parents 6d094fe + 674386e commit 1ac3950
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2843,6 +2843,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);
Expand Down
14 changes: 14 additions & 0 deletions test/eclipse/resource/noerrors/builderJavadoc/BuilderJavadoc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package pkg;

import lombok.Builder;

@Builder
public class BuilderJavadoc {
/**
* Javadoc
*
* @param test ABC
* @return test
*/
private String test;
}
7 changes: 7 additions & 0 deletions test/eclipse/resource/noerrors/builderJavadoc/Usage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pkg;

public class Usage {
public void test() {
BuilderJavadoc.builder().test("test").build();
}
}
17 changes: 15 additions & 2 deletions test/eclipse/src/lombok/eclipse/compile/NoErrorsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,6 +48,19 @@ public class NoErrorsTest {
public void fieldNameConstantsInAnnotation() throws Exception {
ICompilationUnit cu = setup.getPackageFragment().getCompilationUnit("Usage.java");

List<IProblem> problems = collectProblems(cu);
assertTrue(problems.isEmpty());
}

@Test
public void builderJavadoc() throws Exception {
ICompilationUnit cu = setup.getPackageFragment().getCompilationUnit("Usage.java");

List<IProblem> problems = collectProblems(cu);
assertTrue(problems.isEmpty());
}

private List<IProblem> collectProblems(ICompilationUnit cu) throws JavaModelException {
final List<IProblem> problems = new ArrayList<IProblem>();
final IProblemRequestor requestor = new IProblemRequestor() {
@Override
Expand Down Expand Up @@ -83,7 +97,6 @@ public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) {
workingCopy.discardWorkingCopy();
}

System.out.println(problems);
assertTrue(problems.isEmpty());
return problems;
}
}

0 comments on commit 1ac3950

Please sign in to comment.