diff --git a/src/main/resources/META-INF/rewrite/java-version-11.yml b/src/main/resources/META-INF/rewrite/java-version-11.yml index 5fbd0db412..02e9cd8afa 100644 --- a/src/main/resources/META-INF/rewrite/java-version-11.yml +++ b/src/main/resources/META-INF/rewrite/java-version-11.yml @@ -63,12 +63,13 @@ recipeList: - org.openrewrite.java.migrate.util.OptionalNotPresentToIsEmpty - org.openrewrite.java.migrate.util.OptionalNotEmptyToIsPresent - org.openrewrite.java.migrate.util.OptionalStreamRecipe - - org.openrewrite.java.migrate.InternalBindContextFactory + - org.openrewrite.java.migrate.InternalBindPackages - org.openrewrite.java.migrate.RemovedSecurityManagerMethods - org.openrewrite.java.migrate.UpgradePluginsForJava11 - org.openrewrite.java.migrate.RemovedPolicy - org.openrewrite.java.migrate.ReferenceCloneMethod - org.openrewrite.java.migrate.ThreadStopDestroy + --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.UpgradeBuildToJava11 @@ -228,16 +229,16 @@ recipeList: onlyIfVersionsMatch: true --- type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.java.migrate.InternalBindContextFactory -displayName: Use `com.sun.xml.bind.v2.ContextFactory` instead of `com.sun.xml.internal.bind.v2.ContextFactory` -description: Do not use the `com.sun.xml.internal.bind.v2.ContextFactory` class. +name: org.openrewrite.java.migrate.InternalBindPackages +displayName: Use `com.sun.xml.bind.*` instead of `com.sun.xml.internal.bind.*` +description: Do not use APIs from `com.sun.xml.internal.bind.*` packages. tags: - java11 recipeList: - - org.openrewrite.java.ChangeType: - oldFullyQualifiedTypeName: com.sun.xml.internal.bind.v2.ContextFactory - newFullyQualifiedTypeName: com.sun.xml.bind.v2.ContextFactory - ignoreDefinition: true + - org.openrewrite.java.ChangePackage: + oldPackageName: com.sun.xml.internal.bind + newPackageName: com.sun.xml.bind + recursive: true --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.RemovedPolicy diff --git a/src/test/java/org/openrewrite/java/migrate/Java8ToJava11Test.java b/src/test/java/org/openrewrite/java/migrate/InternalBindPackagesTest.java similarity index 73% rename from src/test/java/org/openrewrite/java/migrate/Java8ToJava11Test.java rename to src/test/java/org/openrewrite/java/migrate/InternalBindPackagesTest.java index 9e49b33e4e..3678b619c9 100644 --- a/src/test/java/org/openrewrite/java/migrate/Java8ToJava11Test.java +++ b/src/test/java/org/openrewrite/java/migrate/InternalBindPackagesTest.java @@ -24,18 +24,18 @@ import static org.openrewrite.java.Assertions.java; -class Java8ToJava11Test implements RewriteTest { +class InternalBindPackagesTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "sun.internal.new")) - .recipeFromResources("org.openrewrite.java.migrate.Java8toJava11"); + .classpathFromResources(new InMemoryExecutionContext(), "sun.internal.newClass")) + .recipeFromResources("org.openrewrite.java.migrate.InternalBindPackages"); } @DocumentExample @Test - void internalBindContextFactory() { + void contextFactoryImportVariants() { //language=java rewriteRun( java( @@ -91,8 +91,7 @@ void bar() { } """, """ - import com.sun.xml.bind.v2.ContextFactory; - import com.sun.xml.internal.bind.v2.*; + import com.sun.xml.bind.v2.*; class Foo3 { void bar() { @@ -105,4 +104,31 @@ void bar() { ) ); } + + @Test + void wellKnownNamespace() { + rewriteRun( + //language=java + java( + """ + package com.ibm.test; + public class TestInternalBindPackages { + public void testInternalBindPackages() { + com.sun.xml.internal.bind.v2.WellKnownNamespace namespace = null; + namespace.hashCode(); + } + } + """, + """ + package com.ibm.test; + public class TestInternalBindPackages { + public void testInternalBindPackages() { + com.sun.xml.bind.v2.WellKnownNamespace namespace = null; + namespace.hashCode(); + } + } + """ + ) + ); + } } diff --git a/src/test/resources/META-INF/rewrite/classpath/sun.internal.newClass.jar b/src/test/resources/META-INF/rewrite/classpath/sun.internal.newClass.jar new file mode 100644 index 0000000000..d9164870e4 Binary files /dev/null and b/src/test/resources/META-INF/rewrite/classpath/sun.internal.newClass.jar differ