Skip to content

NoSuchMethodError on java.lang.Enum.getEnumConstants #1387

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

Closed
nicolasstucki opened this issue Jul 14, 2016 · 5 comments
Closed

NoSuchMethodError on java.lang.Enum.getEnumConstants #1387

nicolasstucki opened this issue Jul 14, 2016 · 5 comments

Comments

@nicolasstucki
Copy link
Contributor

dotty> classOf[java.nio.file.AccessMode].getEnumConstants
java.lang.NoSuchMethodError: java.lang.Class.getEnumConstants()Ljava/lang/Object;
    at .<init>(<console>:8)
    at .<clinit>(<console>)
    at RequestResult$.<init>(<console>:3)
    at RequestResult$.<clinit>(<console>)
    at RequestResult$result(<console>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java...

This happens with any java enum class.

@DarkDimius
Copy link
Contributor

is it indeed a java.lang.Class.getEnumConstants()Ljava/lang/Object;? for some reason [ is missing.

@DarkDimius
Copy link
Contributor

DarkDimius commented Jul 14, 2016

        0: ldc           #15                 // class java/nio/file/AccessMode
         2: invokevirtual #21                 // Method java/lang/Class.getEnumConstants:()Ljava/lang/Object;
         5: checkcast     #23                 // class "[Ljava/nio/file/AccessMode;"
         8: areturn
result of For.scala after TreeTransform:{vcInlineMethods, isInstanceOfEvaluator, seqLiterals, intercepted, getters, elimByName, augmentScala2Traits, resolveSuper, arrayConstructors}:
package <empty> {
  @dotty.annotation.internal.SourceFile("For.scala") class FooR() extends Object
    (
  ) {
    def foo: Array[java.nio.file.AccessMode] =
      classOf[class AccessMode].getEnumConstants()
  }
}
result of For.scala after erasure:
package <empty> {
  @dotty.annotation.internal.SourceFile("For.scala") class FooR() extends Object
    (
  ) {
    def foo(): java.nio.file.AccessMode[] =
      classOf[class AccessMode].getEnumConstants().asInstanceOf[
        java.nio.file.AccessMode[]
      ]
  }
}

Seems like the problem is caused by incorrect erasure of getEnumConstants.

@smarter
Copy link
Member

smarter commented Jul 14, 2016

Our handling of Java T[] is known to be broken: #533

@smarter
Copy link
Member

smarter commented Jul 14, 2016

The culprit is indeed eraseArray which doesn't know that generic arrays coming from Java should be erased to Object[] instead of Object like Scala

smarter referenced this issue Jul 15, 2016
@odersky
Copy link
Contributor

odersky commented Jul 15, 2016

Fixed by #1391.

@odersky odersky closed this as completed Jul 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants