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] Overlapping source positions for generated code causing Error Prone 2.21.0 to crash #3476

Closed
msridhar opened this issue Aug 4, 2023 · 2 comments

Comments

@msridhar
Copy link
Contributor

msridhar commented Aug 4, 2023

Describe the bug

When running Error Prone 2.21.0 on a project using Lombok, generated synthetic nodes with overlapping source offsets are causing a crash in Error Prone's NotJavadoc check.

To Reproduce

To repro, check out this branch:

https://github.com/msridhar/NullAway/tree/not-javadoc-lombok-crash-repro

And then run ./gradlew :test-java-lib-lombok:compileJava. When building on either JDK 11 or JDK 17 I get this crash:

NullAway/test-java-lib-lombok/src/main/java/com/uber/lombok/LombokDTO.java:23: error: An unhandled exception was thrown by the Error Prone static analysis plugin.
package com.uber.lombok;
^
     Please report this at https://github.com/google/error-prone/issues/new and include the following:

     error-prone version: 2.21.0
     BugPattern: NotJavadoc
     Stack Trace:
     java.lang.IllegalArgumentException: Overlapping ranges not permitted but found [1233..1241] overlapping [1233..1241]
        at com.google.common.base.Preconditions.checkArgument(Preconditions.java:445)
        at com.google.common.collect.ImmutableRangeSet$Builder.build(ImmutableRangeSet.java:807)
        at com.google.errorprone.bugpatterns.BugChecker.suppressedRegions(BugChecker.java:321)
        at com.google.errorprone.bugpatterns.javadoc.NotJavadoc.matchCompilationUnit(NotJavadoc.java:62)
        at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:449)
        at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:555)
        at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:150)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:56)
        at com.google.errorprone.scanner.Scanner.scan(Scanner.java:58)
        at com.google.errorprone.scanner.ErrorProneScannerTransformer.apply(ErrorProneScannerTransformer.java:43)
        at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:156)
        at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:132)
        [...]

The same crash reproduces with the latest Lombok release, 1.18.28.

Expected behavior

No crash.

Version info (please complete the following information):

  • Lombok version 1.18.28
  • JDK 11 or 17 javac, Error Prone 2.21.0

Additional context

Reported on the Error Prone issue tracker at google/error-prone#4040. I believe Lombok tries to generate valid source offsets now, so hopefully this can be fixed on the Lombok side.

@Rawi01
Copy link
Collaborator

Rawi01 commented Aug 5, 2023

Every generated method/field gets the position of the annotation that triggers the generation. If there are multiple methods they all end up with the same source range. I don't know that there is a better solution for this, if you have one in your mind please let me know.

I think the best solution is to tell error prone to ignore generate stuff.

@Rawi01 Rawi01 closed this as completed Aug 5, 2023
@msridhar
Copy link
Contributor Author

msridhar commented Aug 5, 2023

Thanks for looking into this. The specific Error Prone crash this was causing got fixed in that checker. I feel like this kind of thing may creep up again in the future, but I don't know how complicated it would be to generate non-overlapping source ranges in these cases, and I don't have a specific suggestion there.

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

No branches or pull requests

2 participants