projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.93k stars 2.4k forks source link

[BUG] @Builder with Javadoc causes error markers in Java editor with Eclipse 2024-09 (4.33.0) #3757

Closed meldorq closed 1 month ago

meldorq commented 2 months ago

Describe the bug

Since the upgrade to Eclipse 2024-09 (4.33) the @Builder annotation leads to error markers in the Java editor under special circumstances.

To Reproduce

Create a simple maven project in Eclipse containing these two classes:

MyClass.java

package test;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class MyClass {

    /**
     * .
     */
    private String name;

}

MyClass2.java

package test;

public class MyClass2 {

    public void myMethod() {

        MyClass x = MyClass.builder().build();
    }

}

The reference to builder() in MyClass2 is underlined red with the error message 'The method builder() is undefined for the type MyClass'

When I remove the Javadoc comment from name in MyClass, the error goes away.

Expected behavior

There shouldn't be an error.

Version info (please complete the following information):

mduggen commented 1 month ago

Also with:

cxfly commented 1 month ago

Lombok version: 1.18.34 Eclipse Platform 4.33.0.v20240903-0618

There is an error log in the eclipse background, which should be caused by the incompatibility of the new eclipse version. This can be solved by annotating the type with @NoArgsConstructor @AllArgsConstructor

eclipse error log: !MESSAGE Lombok annotation handler class lombok.eclipse.handlers.HandleBuilder failed !STACK 0 java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "compilationUnit" is null at lombok.eclipse.handlers.EclipseHandlerUtil.setDocComment(EclipseHandlerUtil.java:2841) at lombok.eclipse.handlers.EclipseHandlerUtil.setDocComment(EclipseHandlerUtil.java:2830)

image

org.eclipse.jdt.internal.core.CompilationUnit

H-Lo commented 1 month ago

I'm joining the error club. Compilation works, but in editor I get red error marks on my builder calls.

Spring Tool Suite 4 Version: 4.25.0.RELEASE Build Id: 202409101855 Revision: a82190b58c93608a59d9bda759d6df93d9e84ca1

Lombok version: 1.18.34


How to reproduce:

SearchReqOk.java

package lomboktest;
import org.apache.commons.lang3.StringUtils;
import lombok.Builder;
import lombok.Getter;
@Builder @Getter public class SearchReqOk {
    //
    // No JavaDoc
    //
    private final String q;
    public static class SearchReqOkBuilder {
        public SearchReqOkBuilder q(final String q) { this.q = StringUtils.trimToNull(q); return this; }
    }
}

SearchReqDefective.java

package lomboktest;
import org.apache.commons.lang3.StringUtils;
import lombok.Builder;
import lombok.Getter;
@Builder @Getter public class SearchReqDefective {
    /**
     * JavaDoc
     */
    private final String q;
    public static class SearchReqDefectiveBuilder {
        public SearchReqDefectiveBuilder q(final String q) { this.q = StringUtils.trimToNull(q); return this; }
    }
}

UseBuilder.java

package lomboktest;
import lomboktest.SearchReqDefective.SearchReqDefectiveBuilder;
import lomboktest.SearchReqOk.SearchReqOkBuilder;
public class UseBuilder {
    public static void main(final String[] args) {
        final SearchReqOkBuilder ok = SearchReqOk.builder().q("ok");
        System.out.println(ok.build());
        final SearchReqDefectiveBuilder defective = SearchReqDefective.builder().q("not-ok");
        System.out.println(error.build());
    }
}

lombok-error

H-Lo commented 1 month ago

If you don't like this error, quick fix is to convert JavaDoc to a normal Java comment:

/**
 * Do not use JavaDoc comment style. Or Javadoc, don't know should I use camel case or not.
 */

/*
 * Such a comment does not trigger an error in Eclipse.
 */
Rawi01 commented 1 month ago

This issue is a duplicate of #3706 and already fixed. You can use the latest pipeline build until a new version gets release.