Skip to content

[BUG] Endless loop while compile #3225

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

Closed
PhoenixmitX opened this issue Jul 6, 2022 · 2 comments · Fixed by #3619
Closed

[BUG] Endless loop while compile #3225

PhoenixmitX opened this issue Jul 6, 2022 · 2 comments · Fixed by #3619
Assignees
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug eclipse

Comments

@PhoenixmitX
Copy link

PhoenixmitX commented Jul 6, 2022

Describe the bug
When i try to compile the following code i get an infinite build loop.
Looks like this in the build console:

3c8a4595 Validate documents [Done]
61e7cad1 Building [Done]
45f4bbe0 Validate documents [Done]
bea75a86 Building [Done]
5aabff5f Publish Diagnostics [Done]
6696590e Building [Done]
7174362f Validate documents [Done]
a047644d Publish Diagnostics [Done]
6b2c49a3 Building [Done]

To Reproduce
Try to compile this code:

@ExtensionMethod({LombokEndlessLoop.Extensions.class})
public class LombokEndlessLoop {

  public void compileEndlessLoop() {
    // endless loop
    // "".ifNotNull(String::toString).ifNotNull(System.out::println);
  }
  
  @UtilityClass
  public static class Extensions {
    
    public static <T, R> R ifNotNull(T t, Function<T, R> function) {
      return t != null ? function.apply(t) : null;
   }

   public static <T> void ifNotNull(T t, Consumer<T> function) {
      if (t != null) {
         function.accept(t);
      }
   }
}

After pasting the code it compiles a single time correct.
You have to make a change in the file an safe

Expected behavior
No endless loops

Version info:

  • Lombok 1.18.24 (maven)
  • VSCode with lombok extension and manual updated lombok.jar since the extension is outdated
  • javac 18.0.1
  • maven.compiler.source 17
  • maven.compiler.target 17
@Rawi01 Rawi01 added bug eclipse accepted The issue/enhancement is valid, sensible, and explained in sufficient detail labels Jul 21, 2022
@Rawi01
Copy link
Collaborator

Rawi01 commented Nov 3, 2022

This also fails if you try to call the extension method by hand because the method is ambiguous. The loop happens because lombok is unable to find a matching method, it simply picks the first method that has the same name and a matching first parameter.
For eclipse it also checks the argument types and add an error message if it does not match. It does not try to find a better match. In javac this will usually work as long as both extension methods are in the same class because it runs before the compiler resolves the methods. If the right method is in a different class it will still fail.

@rspilker
Copy link
Collaborator

This is part of the latest edge release, all feedback is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug eclipse
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants