Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Rawi01
Copy link
Collaborator

@Rawi01 Rawi01 commented May 27, 2025

This PR fixes #3883

Eclipse changed how they handle records. Instead of generating fields early on it now does it in a later stage. To keep the support in lombok we now map the record components to fields ourself and add theses fields to our AST. To keep the test output the same I added a patch that removes the implicit fields from the output if they are present.

Copy link
Contributor

@rgrunber rgrunber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this out and it works well for me. Records with a @Builder annotation no longer emit an error. "Document does not match AST" also remains fixed.

@durvalprintes
Copy link

I built the branch and tested the new jar, the errors disappeared.

rgrunber added a commit to rgrunber/vscode-java that referenced this pull request Jun 24, 2025
rgrunber added a commit to rgrunber/vscode-java that referenced this pull request Jun 24, 2025
rgrunber added a commit to rgrunber/vscode-java that referenced this pull request Jun 24, 2025
rgrunber added a commit to redhat-developer/vscode-java that referenced this pull request Jun 24, 2025
@hashpyrit
Copy link

hashpyrit commented Jul 7, 2025

The problem still occurs if you you do custom constructor field validation for your record:

public record FailedEvent(Long assetId, DigitalAssetIdentifier assetIdentifier, @NonNull String user, String failureMessage) {

    @Builder <--- this line gets the error that the constructor is not defined
    public FailedEvent {
        if (assetId == null && assetIdentifier == null) {
            throw new IllegalArgumentException("Either assetId or assetIdentifier must be provided");
        }
    }
}

I downloaded lombok-edge.jar today as well as I tried the lombok-1.18.39-4050.jar. Fails with both. I'm using Spring Tools For Eclipse 4.31.0 which is using Eclipse JDT 3.20.200.v20250528-1830.

@vkushnir-onseo
Copy link

Hello! Dear @Rawi01 just cloned this branch, run ant dist and tried generated jar with eclipse and issue still there. Few possible cases: I did smth wrong or fix is not complete or eclipse again changed logic related to records handling

Version: 2025-06 (4.36.0)
Build id: 20250605-1316
Lombok v1.18.37 "Edgy Guinea Pig" - 2025-07-09 is installed. https://projectlombok.org/

@Rawi01
Copy link
Collaborator Author

Rawi01 commented Jul 9, 2025

@vkushnir-onseo This branch should generate a build of version 1.18.39. You either built the wrong branch or made a mistake in your eclipse setup. Rather than building it yourself, you can also download the artifact from the GitHub Actions run. (https://github.com/projectlombok/lombok/actions/runs/15284242422?pr=3888)

@alphademirkaya-hub
Copy link

@Rawi01 thanks a lot it works!

Copy link
Collaborator

@rzwitserloot rzwitserloot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rawi01 Without spending some time delving into why we added 'hey if you see TerminalToken being loaded, apply this patch' is no longer needed – trying to get a grip on why we can simply the fixing of dom.rewrite.TokenScanner. Can you confirm we no longer need it / OSGI check takes care of it?

For context: Up to ~3 months ago, this fix was only applied if we witnessed TerminalToken. 3 months ago, this was updated to 'either if you see any OSGI signs or if you see TerminalToken, apply it' and now we've arrived at: "If you see any OSGI signs, apply it. Don't worry about TerminalToken".

EDIT: Hmm, not sure github makes it possible to see what this is referring to. It's about commit 'Use simpler addScriptIfWitness', 98d980d.

@rzwitserloot rzwitserloot merged commit 7aa264e into projectlombok:master Aug 7, 2025
59 checks passed
@rgrunber
Copy link
Contributor

rgrunber commented Aug 7, 2025

@rzwitserloot I think that commit was related to #3885 (comment) . Upstream replaces TerminalTokens with TerminalToken in newer versions. I think the logic should be "if you see TerminalToken, we're using a newer Eclipse runtime, so apply the patch".

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 this pull request may close these issues.

[BUG] @Builder annotation broken with Java records
7 participants