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

StaticImports incorrectly removes used import, but only on JDK17 and JDK21, not JDK22 and JDK23 #177

Closed
koppor opened this issue Aug 21, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@koppor
Copy link

koppor commented Aug 21, 2024

Context: https://github.com/JabRef/jabref/blob/f4e87e5ef45bd87c373b17717343a59af7b4e931/rewrite.yml#L208

When using JDK21, everything is fine.

When using JDK17, imports are removed

set JAVA_HOME=C:\Program Files\Eclipse Adoptium\jdk-17.0.12.7-hotspot   
Changes have been made to src\test\java\org\jabref\gui\autocompleter\BibEntrySuggestionProviderTest.java by:
    org.openrewrite.java.testing.junit5.StaticImports
        org.openrewrite.java.UseStaticImport: {methodPattern=org.junit.jupiter.api.Assertions *(..)}
--- a/src/test/java/org/jabref/gui/autocompleter/BibEntrySuggestionProviderTest.java
+++ b/src/test/java/org/jabref/gui/autocompleter/BibEntrySuggestionProviderTest.java
@@ -11,7 +11,6 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;

 import static org.jabref.gui.autocompleter.AutoCompleterUtil.getRequest;
-import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;

 class BibEntrySuggestionProviderTest {
diff --git a/src/test/java/org/jabref/gui/autocompleter/PersonNameSuggestionProviderTest.java b/src/test/java/org/jabref/gui/autocompleter/PersonNameSuggestionProviderTest.java
index 980868f730..e9d112ae33 100644

This import, however, is necessary.


Since JDK17 is eol in 5 years from now, I wanted to report the issue. If someone stumbles over it.

@koppor koppor added the bug Something isn't working label Aug 21, 2024
@timtebeek timtebeek changed the title JDK17 support for org.openrewrite.java.testing.junit5.StaticImports StaticImports incorrectly removes used import, but only on JDK17, not JDK21 Aug 21, 2024
@timtebeek
Copy link
Contributor

Very strange that you're seeing differences on those two Java versions. You might want to check the very latest Gradle plugin version, as I see you're using an older version still that does not contain a recent fix to detect missing method types.

@timtebeek timtebeek added the question Further information is requested label Aug 21, 2024
@subhramit
Copy link

Very strange that you're seeing differences on those two Java versions. You might want to check the very latest Gradle plugin version, as I see you're using an older version still that does not contain a recent fix to detect missing method types.

Hi, JabRef developer here.
Issue persists on trying .\gradlew rewriteRun with id 'org.openrewrite.rewrite' version '6.20.1' in build.gradle.

@timtebeek
Copy link
Contributor

We just merged a fix for a very similar issue, there affecting static imports of variables, not methods:

Figured that might be interesting to call out here as the fix could be similar.

@timtebeek timtebeek removed the question Further information is requested label Sep 21, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Sep 21, 2024
@timtebeek
Copy link
Contributor

Reading this issue again I think it's logged against the wrong project. With the changes since it's hard to say if this has been solved or not; If you feel there's anything left to do then let's open an issue against rewrite-testing-frameworks with steps to reproduce, as it looks like StaticImports has been permanently enabled there already:
https://github.com/JabRef/jabref/blob/de81430c1472920304c8348207ee2af9ec525822/rewrite.yml#L212

@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenRewrite Nov 24, 2024
@koppor
Copy link
Author

koppor commented Nov 25, 2024

Just for reference:

  • Fails: JAVA_HOME=CC:\Program Files\Eclipse Adoptium\jdk-21.0.5.11-hotspot
  • Works: JAVA_HOME=C:\Program Files\Eclipse Adoptium\jdk-23.0.1.11-hotspot

@subhramit
Copy link

I think this is becoming increasingly common:
JabRef/jabref#12246 (comment)
JabRef/jabref@f377939

@timtebeek
Copy link
Contributor

Sorry to hear; Are there any missing types perhaps that differ between 21 and 21? Useing the Find missing types recipe, and the data table it produces, do you find any missing types in your codebase? If there are any missing types you might want to double-check your dependencies are set up correctly, or whether you're using Lombok, as Lombok leads to missing types.

Any help troubleshooting this would be appreciated, as it's hard for me to find the time with the amount of requests we have coming in.

@Siedlerchr
Copy link

Siedlerchr commented Dec 1, 2024

I encountered this issue with the removed imports now on 21.0.2 temurin on mac
openrewrite 6.27.2 and
org.openrewrite.recipe:rewrite-recipe-bom:2.22.0"

@koppor
Copy link
Author

koppor commented Dec 1, 2024

Sorry to hear; Are there any missing types perhaps that differ between 21 and 21? Useing the Find missing types recipe,

In the Java code exclusively in the JavaDoc commts

     /**
-     * @implNote Tests inspired by {@link org.jabref.model.database.BibDatabaseContextTest#getFileDirectoriesWithRelativeMetadata}
+     * @implNote Tests inspired by {@link ~~(MemberReference type is missing or malformed)~~>org.jabref.model.database.BibDatabaseContextTest#getFileDirectoriesWithRelativeMetadata}
      */

There are also type issues in build.gradle, but I assume, they do not harm?


I made a check on my WSL (together with SDKMan). My results:

Version working
21-tem no
21.0.1-tem no
21.0.3-tem no
21.0.4-tem no
21.0.5-tem no
22.0.1-tem yes
23-tem yes
23.0.1-tem yes

I do not know why it worked here with JDK21 in August.

@koppor koppor changed the title StaticImports incorrectly removes used import, but only on JDK17, not JDK21 StaticImports incorrectly removes used import, but only on JDK17 and JDK21, not JDK22 and JDK23 Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

4 participants