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

JUnitIncompatibleType on 2.27.0 throws ClassCastException for com.sun.tools.javac.code.Type$TypeVar around assertArrayEquals #4377

Open
XN137 opened this issue Apr 26, 2024 · 1 comment

Comments

@XN137
Copy link

XN137 commented Apr 26, 2024

thanks for dealing with #4291 but sadly even after that fix in 2.27.0 our code base still hits a compile error in this check:

[ERROR]      Please report this at https://github.com/google/error-prone/issues/new and include the following:
[ERROR]   
[ERROR]      error-prone version: 2.27.0
[ERROR]      BugPattern: JUnitIncompatibleType
[ERROR]      Stack Trace:
[ERROR]      java.lang.ClassCastException: class com.sun.tools.javac.code.Type$TypeVar cannot be cast to class com.sun.tools.javac.code.Type$ArrayType (com.sun.tools.javac.code.Type$TypeVar and com.sun.tools.javac.code.Type$ArrayType are in module jdk.compiler of loader 'app')
[ERROR]   	at com.google.errorprone.bugpatterns.collectionincompatibletype.JUnitIncompatibleType.matchMethodInvocation(JUnitIncompatibleType.java:79)
[ERROR]   	at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:449)
[ERROR]   	at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:746)
[ERROR]   	at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:150)
[ERROR]   	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1666)
[ERROR]   	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
[ERROR]   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
[ERROR]   	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)

problematic code snippet:

  protected <T> void runCircularTest(Format<T> format, T original) throws IOException {
    final Serializer<T, byte[]> serializer = getSerializer(format);

    final String outJson = serializer.toJson(original);
    final T backJson = serializer.fromJson(outJson);

    if (original instanceof byte[]) {
      assertArrayEquals((byte[]) original, (byte[]) backJson);  // <-- error happens here
    } else {
      assertEquals(original, backJson);
    }
  }
@XN137
Copy link
Author

XN137 commented Apr 27, 2024

another related error:

An unhandled exception was thrown by the Error Prone static analysis plugin.

[ERROR]      Please report this at https://github.com/google/error-prone/issues/new and include the following:
[ERROR]   
[ERROR]      error-prone version: 2.27.0
[ERROR]      BugPattern: JUnitIncompatibleType
[ERROR]      Stack Trace:
[ERROR]      java.lang.ClassCastException: class com.sun.tools.javac.code.Type$JCPrimitiveType$2 cannot be cast to class com.sun.tools.javac.code.Type$ArrayType (com.sun.tools.javac.code.Type$JCPrimitiveType$2 and com.sun.tools.javac.code.Type$ArrayType are in module jdk.compiler of loader 'app')
[ERROR]   	at com.google.errorprone.bugpatterns.collectionincompatibletype.JUnitIncompatibleType.matchMethodInvocation(JUnitIncompatibleType.java:80)
[ERROR]   	at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:449)
[ERROR]   	at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:746)
[ERROR]   	at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:150)

code:

protected void assertArraysEquals(String message, Object expected, Object actual) {
    (...)

    } else if (expected instanceof float[] && actual instanceof float[]) {
      assertArrayEquals(message, (float[]) expected, (float[]) actual, DELTA);  // <-- error happens here
    } else if (expected instanceof double[] && actual instanceof double[]) {
      assertArrayEquals(message, (double[]) expected, (double[]) actual, DELTA);
    }

(i am guessing it would also fail at the double[] assertion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant