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

Groovy parser fails when using duplicate static star imports #4068

Closed
Jnb1234 opened this issue Mar 4, 2024 · 2 comments · Fixed by #4982
Closed

Groovy parser fails when using duplicate static star imports #4068

Jnb1234 opened this issue Mar 4, 2024 · 2 comments · Fixed by #4982
Assignees
Labels
bug Something isn't working parser-groovy

Comments

@Jnb1234
Copy link

Jnb1234 commented Mar 4, 2024

What version of OpenRewrite are you using?

I am using

  • OpenRewrite 6.8.4
  • Gradle plugin 7.4.2
  • rewrite-module v1.2.3

How are you running OpenRewrite?

I am using the Gradle plugin, and my project is a single module project.

plugins {
    id 'maven-publish'
    id 'groovy'
    id 'idea'
    id 'net.researchgate.release' version '2.8.1'
    id "com.github.ben-manes.versions" version "0.36.0"
    id "com.gorylenko.gradle-git-properties" version "2.3.2"
    id 'java-library'
    id 'org.openrewrite.rewrite' version '6.8.4'
}

rewrite {
    activeRecipe("org.openrewrite.java.RemoveUnusedImports")
}

What is the smallest, simplest way to reproduce the problem?

@Test
void staticStarImport() {
  rewriteRun(
    groovy(
      """
        import static java.util.Collections.*
        import static java.util.Collections.*
      """
    )
  );
}

What did you expect to see?

No parsing error

What did you see instead?

parsing error

What is the full stack trace of any errors you encountered?

Error during rewrite dry run
org.opentest4j.AssertionFailedError: [When parsing and printing the source code back to text without modifications, the printed source didn't match the original source code. This means there is a bug in the parser implementation itself. Please open an issue to report this, providing a sample of the code that generated this error for "file.groovy":
diff --git a/file.groovy b/file.groovy
index dff510f..56679bc 100644
--- a/file.groovy
+++ b/file.groovy
@@ -1,2 +1,2 @@ 
 import static java.util.Collections.*
-import static java.util.Collections.*
\ No newline at end of file
+import static java.util.Collections.//*
\ No newline at end of file
] 
expected: 
  "import static java.util.Collections.*
  import static java.util.Collections.*"
 but was: 
  "import static java.util.Collections.*
  import static java.util.Collections.//*"

Are you interested in contributing a fix to OpenRewrite?

@Jnb1234 Jnb1234 added the bug Something isn't working label Mar 4, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Mar 4, 2024
@timtebeek
Copy link
Contributor

Thanks for the clear example @Jnb1234 ! It seems to fail on this particular line

Is there any reason why the types might be absent in your case above? Are those imports on the classpath?

@Jnb1234
Copy link
Author

Jnb1234 commented Mar 4, 2024

They are on the classpath. If you comment one of the imports the parsing issue goes away.

Edited... You may be correct about the classpath. Let me try again in the demo project... I changed the import as it was an internal import.... I will update as with a better example. Though I am not sure how it would compile if not on the classpath.

The following compiles with no parsing issues so it is on the classpath I think.

package openrewrite.issues
import static org.mockito.Mockito.*
// import static org.mockito.Mockito.*
class DuplicateImport {

}

// Also note the following works.
package openrewrite.issues
import static org.mockito.Mockito.any
import static org.mockito.Mockito.any
class DuplicateImport {

}

@jevanlingen jevanlingen changed the title Parsing issue with duplicate imports Groovy parser fails when using duplicate static star imports Jan 28, 2025
@jevanlingen jevanlingen self-assigned this Feb 3, 2025
@jevanlingen jevanlingen moved this from Backlog to In Progress in OpenRewrite Feb 3, 2025
@jevanlingen jevanlingen linked a pull request Feb 3, 2025 that will close this issue
3 tasks
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser-groovy
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants