Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] NPE on @SuperBuilder HandleSuperBuilder.constructorExists(HandleSuperBuilder.java:1198) #2704

Closed
AndreBritoGit opened this issue Jan 6, 2021 · 3 comments · Fixed by #2770

Comments

@AndreBritoGit
Copy link

Describe the bug
I'm getting a nullPointerException when I have a @SuperBuilder and also have a default, no args, costructor.
This only happens on Eclipse! Both IntelliJ and VSCode behaves fine with the same code

To Reproduce
Have the following classes on Eclipse IDE
Parent.java

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@NoArgsConstructor
@SuperBuilder
public abstract class Parent {

  int a;
  String b;
  String type;

}

Child.java

import java.util.ArrayList;
import java.util.List;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;

@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
public class Child extends Parent {

  public Child() {
    this.type = "C";
  }

  @Builder.Default
  List<Integer> c = new ArrayList<>();
}

Expected behavior
Child class to have a .builder() method.

Current Behavior

!ENTRY org.eclipse.jdt.core 4 0 2021-01-06 16:51:38.377 !MESSAGE Lombok annotation handler class lombok.eclipse.handlers.HandleSuperBuilder failed !STACK 0 java.lang.NullPointerException at lombok.eclipse.handlers.HandleSuperBuilder.constructorExists(HandleSuperBuilder.java:1198) at lombok.eclipse.handlers.HandleSuperBuilder.handle(HandleSuperBuilder.java:316) at lombok.eclipse.HandlerLibrary$AnnotationHandlerContainer.handle(HandlerLibrary.java:106) at lombok.eclipse.HandlerLibrary.handleAnnotation(HandlerLibrary.java:237) at lombok.eclipse.TransformEclipseAST$AnnotationVisitor.visitAnnotationOnType(TransformEclipseAST.java:267) at lombok.eclipse.EclipseNode.traverse(EclipseNode.java:107) at lombok.eclipse.EclipseAST.traverseChildren(EclipseAST.java:233) at lombok.eclipse.EclipseNode.traverse(EclipseNode.java:74) at lombok.eclipse.EclipseAST.traverseChildren(EclipseAST.java:233) at lombok.eclipse.EclipseNode.traverse(EclipseNode.java:69) at lombok.eclipse.EclipseAST.traverse(EclipseAST.java:226) at lombok.eclipse.TransformEclipseAST.go(TransformEclipseAST.java:224) at lombok.eclipse.TransformEclipseAST.transform(TransformEclipseAST.java:185) at lombok.eclipse.TransformEclipseAST.transform_swapped(TransformEclipseAST.java:110) at jdk.internal.reflect.GeneratedMethodAccessor45.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at lombok.launch.PatchFixesHider$Util.invokeMethod(PatchFixesHider.java:119) at lombok.launch.PatchFixesHider$Transform.transform_swapped(PatchFixesHider.java:190) at org.eclipse.jdt.internal.compiler.parser.Parser.endParse(Parser.java:11687) at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:12880) at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:13104) at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:13061) at org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.convert(SourceTypeConverter.java:144) at org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.buildCompilationUnit(SourceTypeConverter.java:100) at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.resolve(HierarchyResolver.java:755) at org.eclipse.jdt.internal.core.hierarchy.IndexBasedHierarchyBuilder.buildForProject(IndexBasedHierarchyBuilder.java:265) at org.eclipse.jdt.internal.core.hierarchy.IndexBasedHierarchyBuilder.buildFromPotentialSubtypes(IndexBasedHierarchyBuilder.java:350) at org.eclipse.jdt.internal.core.hierarchy.IndexBasedHierarchyBuilder.build(IndexBasedHierarchyBuilder.java:166) at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.compute(TypeHierarchy.java:323) at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.refresh(TypeHierarchy.java:1319) at org.eclipse.jdt.internal.core.CreateTypeHierarchyOperation.executeOperation(CreateTypeHierarchyOperation.java:94) at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:740) at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:806) at org.eclipse.jdt.internal.core.SourceType.newTypeHierarchy(SourceType.java:950) at org.eclipse.jdt.internal.core.SourceType.newTypeHierarchy(SourceType.java:907) at org.eclipse.jdt.internal.ui.javaeditor.codemining.JavaImplementationCodeMining.countMethodImplementations(JavaImplementationCodeMining.java:195) at org.eclipse.jdt.internal.ui.javaeditor.codemining.JavaImplementationCodeMining.lambda$0(JavaImplementationCodeMining.java:105) at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1736) at java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1728) at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020) at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656) at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

Version info (please complete the following information):

  • Lombok v1.18.16 "Envious Ferret" is installed.
  • Platform Eclipse IDE for Enterprise Java Developers (includes Incubating components) Version: 2020-12 (4.18.0) Build id: 20201210-1552
@AndreBritoGit
Copy link
Author

AndreBritoGit commented Jan 6, 2021

FYI

I've managed to fix this by adding a null check on that line and adding a new if condition for no args constructor like so:

        if (def.arguments==null  ||  def.arguments.length < 1) continue;
	if (def.arguments!=null && def.arguments.length != 1) continue;
        ...

If it makes sense maybe include it in a PR

@janrieke
Copy link
Contributor

janrieke commented Jan 7, 2021

Can confirm.

Changing the failing line to if (def.arguments == null || def.arguments.length != 1) continue; should fix this.

@gypsy
Copy link

gypsy commented Jan 20, 2021

Similar reproduce scenario:

import lombok.Getter;
import lombok.NonNull;
import lombok.experimental.SuperBuilder;

public class LombokTest {

	public static void main(String[] args) {
		ConcreteClass cc = new ConcreteClass();
		System.out.println("cc name: " + cc.getName());
	}

	@SuperBuilder
	public static abstract class AbstractParentClass {
		@Getter @NonNull
		private final String name;
	}
	
	@SuperBuilder
	public static class ConcreteClass extends AbstractParentClass {
		public ConcreteClass() {
			this("default_name");
		}
		
		public ConcreteClass(String myName) {
			super(builder().name(myName));
		}
	}
}

Running from command line it works as expected:

➜  java git:(master) ✗ javac -cp .:/Applications/Eclipse.app/Contents/Eclipse/lombok-1.18.16.jar LombokTest.java 
➜  java git:(master) ✗ java -cp .:/Applications/Eclipse.app/Contents/Eclipse/lombok-1.18.16.jar LombokTest
cc name: default_name
➜  java git:(master) ✗ java -version
java version "11.0.10" 2021-01-19 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.10+8-LTS-162)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.10+8-LTS-162, mixed mode)

Looking forward to the fix to be included in next version. Thank you for all your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants