openrewrite / rewrite-logging-frameworks

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

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

Open koppor opened 3 weeks ago

koppor commented 3 weeks 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 weeks 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 weeks 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 1 week 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.