manifold-systems / manifold

Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
http://manifold.systems/
Apache License 2.0
2.42k stars 125 forks source link

Manifold, Lombok, ErrorProne together triggers a StringIndexOutOfBoundsException without no-bootstrap #618

Closed superxiao closed 3 months ago

superxiao commented 3 months ago

Describe the bug As I was migrating my build system from maven to gradle, I noticed gradlew assemble a project with Manifold, Lombok and ErrorProne fails with the folloing error:

/java/util/Optional.java:[2,1] An unhandled exception was thrown by the Error Prone static analysis plugin.
[ERROR]      Please report this at https://github.com/google/error-prone/issues/new and include the following:
[ERROR]   
[ERROR]      error-prone version: 2.30.0
[ERROR]      BugPattern: UnusedVariable
[ERROR]      Stack Trace:
[ERROR]      java.lang.StringIndexOutOfBoundsException: begin -1, end 186, length 3351
...

ErrorProne and Lombok are know to not play nice together https://github.com/google/error-prone/issues/1250 However I did not have a problem with the maven build where both of them are used along with Manifold. The problem only arose when I tried to convert it to a gradle build. First I thought it was gradle, or the lombok gradle plugin, or the errorprone gradle plugin - turns out it was none of them. It was because in the gradle build I was not explicitly using the no-bootstrap option for Manifold, which the maven build is using by -Xplugin:Manifold no-bootstrap. Without this option, the maven build fails for the same error.

I don't think this is an issue where Manifold needs to do anything about, but I just figured posting this could help others who may also run into this unique problem.

To Reproduce Steps to reproduce the behavior:

  1. Create a java project with Manifold, Lombok, and ErrorProne
  2. Specify manifold plugin by Xplugin:Manifold without the no-bootstrap option - if using a gradle build, then using the manifold gradle plugin would also reproduce this.

Expected behavior

Screenshots

Desktop (please complete the following information):

Additional context I'm not quite sure whether no-bootstrap is the right option to use here as I'm building jdk17 and the manifold documentation says:

If you know your code will never run on Java 9+ and/or you don't mind the Java 9+ warning message, you can eliminate the dasBoot() static initializer via the no-bootstrap plugin argument...

In fact I don't know why this option was in the maven build in the first place (I did not create the build).

Stack trace

/java/util/Optional.java:[2,1] An unhandled exception was thrown by the Error Prone static analysis plugin.
[ERROR]      Please report this at https://github.com/google/error-prone/issues/new and include the following:
[ERROR]   
[ERROR]      error-prone version: 2.30.0
[ERROR]      BugPattern: UnusedVariable
[ERROR]      Stack Trace:
[ERROR]      java.lang.StringIndexOutOfBoundsException: begin -1, end 186, length 3351
[ERROR]     at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606)
[ERROR]     at java.base/java.lang.String.substring(String.java:2709)
[ERROR]     at java.base/java.lang.String.subSequence(String.java:2747)
[ERROR]     at com.google.errorprone.VisitorState.getOffsetTokens(VisitorState.java:599)
[ERROR]     at com.google.errorprone.fixes.SuggestedFixes.replaceIncludingComments(SuggestedFixes.java:1680)
[ERROR]     at com.google.errorprone.bugpatterns.UnusedVariable.buildUnusedVarFixes(UnusedVariable.java:477)
[ERROR]     at com.google.errorprone.bugpatterns.UnusedVariable.matchCompilationUnit(UnusedVariable.java:280)
[ERROR]     at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:449)
[ERROR]     at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:555)
[ERROR]     at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:150)
[ERROR]     at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:614)
[ERROR]     at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:60)
[ERROR]     at com.google.errorprone.scanner.Scanner.scan(Scanner.java:58)
[ERROR]     at com.google.errorprone.scanner.ErrorProneScannerTransformer.apply(ErrorProneScannerTransformer.java:43)
[ERROR]     at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:227)
[ERROR]     at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:132)
[ERROR]     at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1397)
[ERROR]     at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1344)
[ERROR]     at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:933)
[ERROR]     at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
[ERROR]     at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
[ERROR]     at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
[ERROR]     at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
[ERROR]     at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:136)
[ERROR]     at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:183)
[ERROR]     at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1140)
[ERROR]     at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:193)
[ERROR]     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:126)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:328)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:316)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:174)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.access$000(MojoExecutor.java:75)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:162)
[ERROR]     at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:159)
[ERROR]     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:105)
[ERROR]     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:73)
[ERROR]     at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:53)
[ERROR]     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:118)
[ERROR]     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:261)
[ERROR]     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:173)
[ERROR]     at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:101)
[ERROR]     at org.apache.maven.cli.MavenCli.execute(MavenCli.java:906)
[ERROR]     at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:283)
[ERROR]     at org.apache.maven.cli.MavenCli.main(MavenCli.java:206)
[ERROR]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[ERROR]     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]     at java.base/java.lang.reflect.Method.invoke(Method.java:569)
[ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:283)
[ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:226)
[ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:407)
[ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:348)
[ERROR]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[ERROR]     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]     at java.base/java.lang.reflect.Method.invoke(Method.java:569)
[ERROR]     at org.apache.maven.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:52)
[ERROR]     at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:161)
[ERROR]     at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:73)