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

2.0.3...2.2.2: IllegalArgumentException: Not an array type for method like void method(@Nullable Object[]) #102

Closed
vlsi opened this issue Jan 10, 2021 · 5 comments · Fixed by #105

Comments

@vlsi
Copy link
Contributor

vlsi commented Jan 10, 2021

Sample:

public interface EqualityComparer<T> {
  boolean equal(T v1, T v2);

  int hashCode(T t);
}
  private static class ArrayEqualityComparer
      implements EqualityComparer<@Nullable Object[]> {
    @Override public boolean equal(@Nullable Object[] v1, @Nullable Object[] v2) {
      return Arrays.deepEquals(v1, v2);
    }

    @Override public int hashCode(@Nullable Object[] t) {
      return Arrays.deepHashCode(t);
    }
  }

Error (in jandex 2.0.3.Final and 2.2.2.Final):

Caused by: java.lang.IllegalArgumentException: Not an array type!
  at org.jboss.jandex.Type.asArrayType(Type.java:254)
  at org.jboss.jandex.Indexer.resolveTypePath(Indexer.java:621)
  at org.jboss.jandex.Indexer.resolveTypeAnnotation(Indexer.java:593)
  at org.jboss.jandex.Indexer.resolveTypeAnnotations(Indexer.java:478)
  at org.jboss.jandex.Indexer.index(Indexer.java:1458)
  at com.github.vlsi.jandex.JandexWork.execute(JandexWork.kt:52)

See https://issues.apache.org/jira/browse/CALCITE-4459

@vlsi
Copy link
Contributor Author

vlsi commented Jan 10, 2021

Smaller case:

public interface EqualityComparer<T> {
  boolean equal(T v1, T v2);

  int hashCode(T t);
}
  private static class ArrayEqualityComparer
      implements EqualityComparer<Object[]> {
    @Override public boolean equal(Object[] v1, Object[] v2) {
      return Arrays.deepEquals(v1, v2);
    }

    @Override public int hashCode(@Nullable Object[] t) {
      return Arrays.deepHashCode(t);
    }
  }

javac 11, javap:

  public int hashCode(java.lang.Object[]);
    descriptor: ([Ljava/lang/Object;)I
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=2, args_size=2
         0: aload_1
         1: invokestatic  #4                  // Method java/util/Arrays.deepHashCode:([Ljava/lang/Object;)I
         4: ireturn
      LineNumberTable:
        line 497: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   Lorg/apache/calcite/linq4j/function/Functions$ArrayEqualityComparer;
            0       5     1     t   [Ljava/lang/Object;
    RuntimeVisibleTypeAnnotations:
      0: #29(): METHOD_FORMAL_PARAMETER, param_index=0, location=[ARRAY]
        org.checkerframework.checker.nullness.qual.Nullable

  public int hashCode(java.lang.Object);
    descriptor: (Ljava/lang/Object;)I
    flags: (0x1041) ACC_PUBLIC, ACC_BRIDGE, ACC_SYNTHETIC
    Code:
      stack=2, locals=2, args_size=2
         0: aload_0
         1: aload_1
         2: checkcast     #5                  // class "[Ljava/lang/Object;"
         5: invokevirtual #6                  // Method hashCode:([Ljava/lang/Object;)I
         8: ireturn
      LineNumberTable:
        line 490: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       9     0  this   Lorg/apache/calcite/linq4j/function/Functions$ArrayEqualityComparer;
    RuntimeVisibleTypeAnnotations:
      0: #29(): METHOD_FORMAL_PARAMETER, param_index=0, location=[ARRAY]
        org.checkerframework.checker.nullness.qual.Nullable

@vlsi
Copy link
Contributor Author

vlsi commented Jan 10, 2021

I guess the issue is caused by ACC_BRIDGE, ACC_SYNTHETIC method.
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6695379 Copy method annotations and parameter annotations to synthetic bridge methods might be relevant.

@n1hility
Copy link
Contributor

Thanks for the report. I'll need to research various compiler outputs. It looks like the generated bridge is referring to a type path that is not valid with this signature. This will probably need to be gracefully ignored.

@vlsi
Copy link
Contributor Author

vlsi commented Jan 11, 2021

What do you think if a GitHub Action was added that tried to parse Apache Calcite codebase with the current jandex? Calcite has a significant amount of type annotations added in apache/calcite#2268

It won't make debug easier, however, it might help to prevent regressions.

@n1hility
Copy link
Contributor

@vlsi i think thats a great idea. I would be happy to regression test with calcite.

vlsi added a commit to vlsi/jandex that referenced this issue Jan 16, 2021
javac copies annotations to bridge methods (which is good), however the annotations
might become invalid. For instance, the bridge signature for @nullable Object[] is
Object (non-array), so usage=ARRAY signature is invalid
We ignore those annotations for the bridge methods.

See https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6695379

fixes smallrye#102
vlsi added a commit to vlsi/jandex that referenced this issue Jan 16, 2021
javac copies annotations to bridge methods (which is good), however the annotations
might become invalid. For instance, the bridge signature for @nullable Object[] is
Object (non-array), so usage=ARRAY signature is invalid
We ignore those annotations for the bridge methods.

See https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6695379

fixes smallrye#102
n1hility pushed a commit to n1hility/jandex that referenced this issue Jan 19, 2021
javac copies annotations to bridge methods (which is good), however the annotations
might become invalid. For instance, the bridge signature for @nullable Object[] is
Object (non-array), so usage=ARRAY signature is invalid
We ignore those annotations for the bridge methods.

See https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6695379

fixes smallrye#102
n1hility pushed a commit to n1hility/jandex that referenced this issue Jan 19, 2021
javac copies annotations to bridge methods (which is good), however the annotations
might become invalid. For instance, the bridge signature for @nullable Object[] is
Object (non-array), so usage=ARRAY signature is invalid
We ignore those annotations for the bridge methods.

See https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6695379

fixes smallrye#102
n1hility pushed a commit to vlsi/jandex that referenced this issue Jan 20, 2021
javac copies annotations to bridge methods (which is good), however the annotations
might become invalid. For instance, the bridge signature for @nullable Object[] is
Object (non-array), so usage=ARRAY signature is invalid
We ignore those annotations for the bridge methods.

See https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6695379

fixes smallrye#102
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants