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

NoGuavaJava21 causing invalid code since v2.28.0 #590

Open
protocol7 opened this issue Oct 24, 2024 · 0 comments
Open

NoGuavaJava21 causing invalid code since v2.28.0 #590

protocol7 opened this issue Oct 24, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@protocol7
Copy link

protocol7 commented Oct 24, 2024

What version of OpenRewrite are you using?

  • org.openrewrite:rewrite-core:8.38.0
  • org.openrewrite.recipe:rewrite-migrate-java:2.28.0

What is the smallest, simplest way to reproduce the problem?

Since the latest release of OpenRewrite, we're seeing it generate invalid code seemingly related to the Guava collections, perhaps related to #586.

I have not been able to reproduce these as tests, so including some samples here in the meantime.

Rewritten by org.openrewrite.java.migrate.guava.NoGuavaJava11:

   public static ImmutableList<Class<? extends Provider<ClientInterceptor>>>
       defaultClientInterceptorProviders() {
-    return ImmutableList.of(
+    return List.of(
         OutgoingRequestLoggingServerInterceptorProvider.class,
         CtxTrackerClientInterceptorProvider.class,
         RequestMetadataClientInterceptorProvider.class,

Note that the method is declared to return ImmutableList but has here been rewritten to actually return a java.util.List.

Here's a more involved example, in this case rewritten by org.openrewrite.staticanalysis.RemoveUnusedPrivateFields and org.openrewrite.java.migrate.guava.NoGuavaJava21:

 public class DiagramRules {
-  private static final ImmutableSet<String> INCLUDE_COMPONENT_TYPES =
-      ImmutableSet.of(
-          "service",
-          "data",
-          "other");

   static boolean includeType(final String type) {
     return INCLUDE_COMPONENT_TYPES.contains(type);

Note how INCLUDE_COMPONENT_TYPES is still referenced. The code is only removed if both recipes are enabled.

Both of these examples causes compiler errors. We have plenty of these examples and have rolled back to the previous version for now.

@protocol7 protocol7 added the bug Something isn't working label Oct 24, 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
Status: No status
Development

No branches or pull requests

1 participant