Skip to content

NoGuavaJava21 causing invalid code since v2.28.0 #590

@protocol7

Description

@protocol7

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions