From 4cba1125b2ab0d5da96dfb9fde7559d8ce8b4809 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 28 May 2026 20:33:17 +0200 Subject: [PATCH] Do not add `java.io.IO` import in `ReplaceSystemOutWithIOPrint` Fixes #1115. JEP 512 moved the new `IO` class to `java.lang.IO` for the final Java 25 release, so it is implicitly imported by every source file; the `java.io.IO` location only existed in the preview JEPs 477 and 495. Reverts the import added in #1093, which produced an import of the non-existent `java.io.IO`. --- .../io/ReplaceSystemOutWithIOPrint.java | 1 - .../io/ReplaceSystemOutWithIOPrintTest.java | 18 +----------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/main/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrint.java b/src/main/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrint.java index 543998d3c8..b8960f72fb 100644 --- a/src/main/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrint.java +++ b/src/main/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrint.java @@ -54,7 +54,6 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu if (!isSystemOutMethod(m)) { return m; } - maybeAddImport("java.io.IO", false); String methodName = m.getName().getSimpleName(); return m.getArguments().isEmpty() ? JavaTemplate.apply( "IO.#{}()", getCursor(), m.getCoordinates().replace(), methodName ) : diff --git a/src/test/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrintTest.java b/src/test/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrintTest.java index ac44344311..ba8fd79ee5 100644 --- a/src/test/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrintTest.java +++ b/src/test/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrintTest.java @@ -53,8 +53,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { IO.print("Hello"); @@ -77,8 +75,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { IO.println("Hello"); @@ -103,8 +99,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { IO.println("Hello"); @@ -128,8 +122,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { String message = "Hello World"; @@ -153,8 +145,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { IO.println(); @@ -180,8 +170,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { IO.print("Hello"); @@ -210,8 +198,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { String name = "John"; @@ -261,7 +247,7 @@ void test() { } @Test - void addsImportForRegularClassWithPackage() { + void doesNotAddImportForRegularClassWithPackage() { rewriteRun( java( """ @@ -276,8 +262,6 @@ public void greet() { """ package com.helloworld; - import java.io.IO; - public class Main { public void greet() { IO.println("hello");