ExhaustiveRefasterTypeMigration

WARNING

LikelyError

View source code on GitHub

Summary

The set of unmigrated methods listed by the @TypeMigration annotation must be minimal yet exhaustive

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ExhaustiveRefasterTypeMigration") to the enclosing element.

Disable this pattern completely by adding -Xep:ExhaustiveRefasterTypeMigration:OFF as compiler argument. Learn more.

Samples

Replacement

Shows the difference in example code before and after the bug pattern is applied.

 import com.google.errorprone.refaster.annotation.BeforeTemplate;
 import tech.picnic.errorprone.refaster.annotation.TypeMigration;
 
 class A {
-  @TypeMigration(of = Util.class)
+  @TypeMigration(
+      unmigratedMethods = {
+        "publicStaticVoidMethod()",
+        "publicStringMethodWithArg(int)",
+        "publicStringMethodWithArg(String)",
+        "Util()"
+      },
+      of = Util.class)
   class AnnotatedWithoutMethodListing {
     {
       new Util().publicStringMethodWithArg(1);
     }
 
     @BeforeTemplate
     void before() {
       Util.publicStaticIntMethod2();
     }
   }
 
-  @TypeMigration(
-      of = Util.class,
-      unmigratedMethods = {"publicStaticIntMethod2()", "extra", "publicStringMethodWithArg(int)"})
+  @TypeMigration(of = Util.class, unmigratedMethods = "publicStringMethodWithArg(int)")
   class AnnotatedWithIncorrectMethodReference {
     @BeforeTemplate
     void before() {
       new Util().publicStringMethodWithArg("1");
       Util.publicStaticVoidMethod();
       Util.publicStaticIntMethod2();
     }
   }
 
-  @TypeMigration(
-      of = Util.class,
-      unmigratedMethods = {"publicStaticVoidMethod()", "publicStaticVoidMethod()"})
+  @TypeMigration(of = Util.class, unmigratedMethods = "publicStaticVoidMethod()")
   class AnnotatedWithDuplicateMethodReference {
     @BeforeTemplate
     void before() {
       new Util().publicStringMethodWithArg(1);
       new Util().publicStringMethodWithArg("1");
       Util.publicStaticIntMethod2();
     }
   }
 }
 

Identification

Shows code lines which will (not) be flagged by this bug pattern.
A //BUG: Diagnostic contains: comment is placed above any violating line.

import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import tech.picnic.errorprone.refaster.annotation.TypeMigration;

class A {
  class UnannotatedEmptyClass {}

  // BUG: Diagnostic contains: Migration of type 'int' is unsupported
  @TypeMigration(of = int.class)
  class AnnotatedWithPrimitive {}

  @TypeMigration(
      of = Util.class,
      unmigratedMethods = {
        "publicStaticIntMethod2()",
        "publicStringMethodWithArg(int)",
        "publicStaticVoidMethod()"
      })
  class AnnotatedEmptyClass {}

  @TypeMigration(
      of = Util.class,
      unmigratedMethods = {
        "publicStaticVoidMethod()",
        "publicStringMethodWithArg(int)",
        "publicStaticIntMethod2()"
      })
  class AnnotatedEmptyClassWithUnsortedMethodListing {}

  class UnannotatedTemplate {
    @BeforeTemplate
    void before(int value) {
      Util.publicStaticVoidMethod();
      Util.publicStaticIntMethod2();
      new Util().publicStringMethodWithArg(value);
    }
  }

  @TypeMigration(
      of = Util.class,
      unmigratedMethods = {
        "publicStaticIntMethod2()",
        "publicStringMethodWithArg(int)",
        "publicStaticVoidMethod()"
      })
  class AnnotatedWithoutBeforeTemplate {
    {
      Util.publicStaticIntMethod2();
    }

    @AfterTemplate
    void after(int value) {
      Util.publicStaticVoidMethod();
      new Util().publicStringMethodWithArg(value);
    }
  }

  @TypeMigration(of = Util.class)
  class AnnotatedFullyMigrated {
    @BeforeTemplate
    void before() {
      new Util().publicStringMethodWithArg(Util.publicStaticIntMethod2());
    }

    @BeforeTemplate
    void before2() {
      Util.publicStaticVoidMethod();
    }
  }

  @TypeMigration(of = Util.class, unmigratedMethods = "publicStringMethodWithArg(int)")
  class AnnotatedPartiallyMigrated {
    @BeforeTemplate
    void before() {
      Util.publicStaticVoidMethod();
      Util.publicStaticIntMethod2();
    }
  }

  // BUG: Diagnostic contains: The set of unmigrated methods listed by the `@TypeMigration`
  // annotation must be minimal yet exhaustive
  @TypeMigration(of = Util.class, unmigratedMethods = "publicStringMethodWithArg(int)")
  class AnnotatedWithIncompleteMethodListing {
    @BeforeTemplate
    void before() {
      Util.publicStaticIntMethod2();
    }
  }

  // BUG: Diagnostic contains: The set of unmigrated methods listed by the `@TypeMigration`
  // annotation must be minimal yet exhaustive
  @TypeMigration(
      of = Util.class,
      unmigratedMethods = {"publicStaticIntMethod2()", "publicStringMethodWithArg(int)"})
  class AnnotatedWithMigratedMethodReference {
    @BeforeTemplate
    void before() {
      Util.publicStaticVoidMethod();
      Util.publicStaticIntMethod2();
    }
  }

  // BUG: Diagnostic contains: The set of unmigrated methods listed by the `@TypeMigration`
  // annotation must be minimal yet exhaustive
  @TypeMigration(
      of = Util.class,
      unmigratedMethods = {"extra", "publicStringMethodWithArg(int)"})
  class AnnotatedWithUnknownMethodReference {
    @BeforeTemplate
    void before() {
      Util.publicStaticVoidMethod();
      Util.publicStaticIntMethod2();
    }
  }
}

Copyright © 2017-2024 Picnic Technologies BV