openrewrite / rewrite-logging-frameworks

OpenRewrite recipes for assisting with Java logging migration tasks.
Apache License 2.0
26 stars 21 forks source link

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

Closed koppor closed 1 week ago

koppor commented 3 months ago

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.

timtebeek commented 3 months ago

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.

subhramit commented 3 months ago

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 commented 2 months ago

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 commented 1 week ago

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

koppor commented 6 days ago

Just for reference:

subhramit commented 2 days ago

I think this is becoming increasingly common: https://github.com/JabRef/jabref/pull/12246#issuecomment-2508840286 https://github.com/JabRef/jabref/pull/12198/commits/f37793967797f786bd329efd1459668f51791873

timtebeek commented 2 days ago

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 commented 20 hours ago

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 commented 17 hours ago

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.