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

java.lang.IllegalArgumentException: Cannot edit synthetic AST nodes with specific record constructor #3404

Closed
janedbal opened this issue Aug 19, 2022 · 2 comments

Comments

@janedbal
Copy link

Following record definition causes failure:

public record MyRequest(DateRange dateRange)
{

    public MyRequest(final String startDate)
    {
        this(new DateRange(startDate));
    }

    public record DateRange(String startDate) {}

}

Callstack:

error-prone version: 2.15.0
     BugPattern: UngroupedOverloads
     Stack Trace:
     java.lang.IllegalArgumentException: Cannot edit synthetic AST nodes
  	at com.google.errorprone.fixes.SuggestedFix$Builder.checkNotSyntheticConstructor(SuggestedFix.java:357)
  	at com.google.errorprone.fixes.SuggestedFix$Builder.replace(SuggestedFix.java:206)
  	at com.google.errorprone.bugpatterns.UngroupedOverloads.checkOverloads(UngroupedOverloads.java:154)
  	at com.google.errorprone.bugpatterns.UngroupedOverloads.lambda$matchClass$0(UngroupedOverloads.java:106)
  	at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:273)
  	at com.google.common.collect.CollectSpliterators$1.lambda$forEachRemaining$1(CollectSpliterators.java:127)
  	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
  	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
  	at com.google.common.collect.CollectSpliterators$1.forEachRemaining(CollectSpliterators.java:127)
  	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
  	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
  	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
  	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
  	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
  	at com.google.errorprone.bugpatterns.UngroupedOverloads.matchClass(UngroupedOverloads.java:108)
  	at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:449)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:547)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:150)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:860)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:111)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:119)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:152)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:560)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:150)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:614)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:60)
  	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:152)
  	at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:132)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1394)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1341)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:933)
  	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
  	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
  	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
  	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
  	at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:136)
  	at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:182)
  	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1209)
  	at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:198)
  	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
  	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
  	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
  	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
  	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
  	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
  	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
  	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
  	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
  	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
  	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
  	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
  	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
  	at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
  	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
  	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
  	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
  	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
  	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
  	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
  	at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
@dhoepelman
Copy link

dhoepelman commented Dec 29, 2022

A workaround (thanks @gijskant) is to (superfluously) define the canonical constructor:

public record MyRequest(DateRange dateRange)
{
    // Explicitly define constructor to work around https://github.com/google/error-prone/issues/3404
    public MyRequest(DateRange dateRange) {
      this.dateRange = dateRange;
    }

    public MyRequest(final String startDate) {
        this(new DateRange(startDate));
    }
}

Stephan202 added a commit to PicnicSupermarket/error-prone that referenced this issue Dec 29, 2022
@Stephan202
Copy link
Contributor

I filed PR #3632, which aims to address this issue. Reviews welcome :)

Stephan202 added a commit to PicnicSupermarket/error-prone that referenced this issue Dec 31, 2022
copybara-service bot pushed a commit that referenced this issue Dec 31, 2022
Fixes #3404.

Fixes #3632

FUTURE_COPYBARA_INTEGRATE_REVIEW=#3632 from PicnicSupermarket:bugfix/issue-3404 897aa79
PiperOrigin-RevId: 498732782
copybara-service bot pushed a commit that referenced this issue Dec 31, 2022
Fixes #3404.

Fixes #3632

FUTURE_COPYBARA_INTEGRATE_REVIEW=#3632 from PicnicSupermarket:bugfix/issue-3404 897aa79
PiperOrigin-RevId: 498732782
benkard pushed a commit to benkard/jgvariant that referenced this issue Jan 14, 2023
This MR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [com.google.errorprone:error_prone_core](https://errorprone.info) ([source](https://github.com/google/error-prone)) |  | minor | `2.16` -> `2.18.0` |
| [com.google.errorprone:error_prone_annotations](https://errorprone.info) ([source](https://github.com/google/error-prone)) | compile | minor | `2.16` -> `2.18.0` |
| [org.apache.maven.plugins:maven-failsafe-plugin](https://maven.apache.org/surefire/) | build | patch | `3.0.0-M7` -> `3.0.0-M8` |
| [org.apache.maven.plugins:maven-surefire-plugin](https://maven.apache.org/surefire/) | build | patch | `3.0.0-M7` -> `3.0.0-M8` |

---

### Release Notes

<details>
<summary>google/error-prone</summary>

### [`v2.18.0`](https://github.com/google/error-prone/releases/tag/v2.18.0): Error Prone 2.18.0

[Compare Source](google/error-prone@v2.17.0...v2.18.0)

New Checkers:

-   [`InjectOnBugCheckers`](https://errorprone.info/bugpattern/InjectOnBugCheckers)
-   [`LabelledBreakTarget`](https://errorprone.info/bugpattern/LabelledBreakTarget)
-   [`UnusedLabel`](https://errorprone.info/bugpattern/UnusedLabel)
-   [`YodaCondition`](https://errorprone.info/bugpattern/YodaCondition)

Fixes issues: [#&#8203;1650](google/error-prone#1650), [#&#8203;2706](google/error-prone#2706), [#&#8203;3404](google/error-prone#3404), [#&#8203;3493](google/error-prone#3493), [#&#8203;3504](google/error-prone#3504), [#&#8203;3519](google/error-prone#3519), [#&#8203;3579](google/error-prone#3579), [#&#8203;3610](google/error-prone#3610), [#&#8203;3632](google/error-prone#3632), [#&#8203;3638](google/error-prone#3638), [#&#8203;3645](google/error-prone#3645), [#&#8203;3646](google/error-prone#3646), [#&#8203;3652](google/error-prone#3652), [#&#8203;3690](google/error-prone#3690)

**Full Changelog**: google/error-prone@v2.17.0...v2.18.0

### [`v2.17.0`](https://github.com/google/error-prone/releases/tag/v2.17.0): Error Prone 2.17.0

[Compare Source](google/error-prone@v2.16...v2.17.0)

New Checkers:

-   [`AvoidObjectArrays`](https://errorprone.info/bugpattern/AvoidObjectArrays)
-   [`Finalize`](https://errorprone.info/bugpattern/Finalize)
-   [`IgnoredPureGetter`](https://errorprone.info/bugpattern/IgnoredPureGetter)
-   [`ImpossibleNullComparison`](https://errorprone.info/bugpattern/ProtoFieldNullComparison)
-   [`MathAbsoluteNegative`](https://errorprone.info/bugpattern/MathAbsoluteNegative)
-   [`NewFileSystem`](https://errorprone.info/bugpattern/NewFileSystem)
-   [`StatementSwitchToExpressionSwitch`](https://errorprone.info/bugpattern/StatementSwitchToExpressionSwitch)
-   [`UnqualifiedYield`](https://errorprone.info/bugpattern/UnqualifiedYield)

Fixed issues: [#&#8203;2321](google/error-prone#2321), [#&#8203;3144](google/error-prone#3144), [#&#8203;3297](google/error-prone#3297), [#&#8203;3428](google/error-prone#3428), [#&#8203;3437](google/error-prone#3437), [#&#8203;3462](google/error-prone#3462), [#&#8203;3482](google/error-prone#3482), [#&#8203;3494](google/error-prone#3494)

**Full Changelog**: google/error-prone@v2.16...v2.17.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

👻 **Immortal**: This MR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants