Scala Programming Language
  1. Scala Programming Language
  2. SI-5431

Reflection does not work with local classes

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0
    • Fix Version/s: Scala 2.10.0
    • Component/s: Reflection
    • Labels:

      Description

      import scala.reflect.mirror._
      
      object Test extends App {
        {
          class A
          classToType(classOf[A])
        }
      }
      
      java.lang.InternalError: Malformed class name
        at java.lang.Class.getSimpleName(Class.java:1133)
        at java.lang.Class.isAnonymousClass(Class.java:1188)
        at java.lang.Class.isLocalClass(Class.java:1199)
        at scala.reflect.runtime.JavaToScala$class.scala$reflect$runtime$JavaToScala$$sOwner(JavaToScala.scala:248)
        at scala.reflect.runtime.JavaToScala$$anonfun$classToScala$1.apply(JavaToScala.scala:386)
        at scala.reflect.runtime.JavaToScala$$anonfun$classToScala$1.apply(JavaToScala.scala:384)
        at scala.reflect.runtime.ConversionUtil$TwoWayCache.toScala(ConversionUtil.scala:31)
        at scala.reflect.runtime.JavaToScala$class.classToScala(JavaToScala.scala:384)
        at scala.reflect.runtime.Universe.classToScala(Universe.scala:11)
        at scala.reflect.runtime.JavaToScala$class.typeToScala(JavaToScala.scala:485)
        at scala.reflect.runtime.Universe.typeToScala(Universe.scala:11)
        at scala.reflect.runtime.Mirror.classToType(Mirror.scala:49)
        at scala.reflect.runtime.Mirror.classToType(Mirror.scala:9)
        at Test$delayedInit$body.apply(t5256c.scala:6)
        at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
        at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
        at scala.App$$anonfun$main$1.apply(App.scala:61)
        at scala.App$$anonfun$main$1.apply(App.scala:61)
        at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
        at scala.collection.immutable.List.foreach(List.scala:77)
        at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:31)
        at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45)
        at scala.App$class.main(App.scala:61)
        at Test$.main(t5256c.scala:3)
        at Test.main(t5256c.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:90)
        at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:38)
        at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:159)
        at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:90)
        at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:159)
        at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28)
        at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45)
        at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35)
        at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45)
        at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70)
        at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:92)
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
      

        Activity

        Hide
        Noah Cutler added a comment -

        Same on M1, hoping M2 brings the goodness; please, bare naked my case clazzass, it's been too long, groping in the dark for Strings, or wait, was that a tuple of tInts I've chanced upon?

        Seriously, being able to determine property names and corresponding types will be a god send, looking forward to trying out M2...

        Show
        Noah Cutler added a comment - Same on M1, hoping M2 brings the goodness; please, bare naked my case clazzass, it's been too long, groping in the dark for Strings, or wait, was that a tuple of tInts I've chanced upon? Seriously, being able to determine property names and corresponding types will be a god send, looking forward to trying out M2...
        Hide
        Miguel Garcia added a comment -

        Works for me:

        Welcome to Scala version 2.10.0-20120502-222338-24be606216 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
        Type in expressions to have them evaluated.
        Type :help for more information.
        
        scala> import scala.reflect.mirror._
        import scala.reflect.mirror._
        
        scala>
        
        scala> object Test extends App {
             |   {
             |     class A
             |     classToType(classOf[A])
             |   }
             | }
        defined module Test
        
        scala>
        
        Show
        Miguel Garcia added a comment - Works for me: Welcome to Scala version 2.10.0-20120502-222338-24be606216 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29). Type in expressions to have them evaluated. Type :help for more information. scala> import scala.reflect.mirror._ import scala.reflect.mirror._ scala> scala> object Test extends App { | { | class A | classToType(classOf[A]) | } | } defined module Test scala>
        Hide
        Miguel Garcia added a comment -

        comment-57227 indicates this ticket has been fixed.

        Show
        Miguel Garcia added a comment - comment-57227 indicates this ticket has been fixed.
        Hide
        Paul Phillips added a comment -

        I assume the thing which indicates this ticket has been fixed is not your comment (because that's where the comment-57227 link is pointing.) Is this one of this puzzles about liars and truth-tellers? I have to ask "If I were to ask you if this ticket is fixed, what would you say?" Meta-rhetoric ftw.

        Show
        Paul Phillips added a comment - I assume the thing which indicates this ticket has been fixed is not your comment (because that's where the comment-57227 link is pointing.) Is this one of this puzzles about liars and truth-tellers? I have to ask "If I were to ask you if this ticket is fixed, what would you say?" Meta-rhetoric ftw.
        Hide
        Paul Phillips added a comment -

        It seems unlikely this is fixed, because "Malformed class name" is part of our DNA until we change the name mangling scheme. But I'm sure there are a sufficient number of other tickets covering it somewhere.

        Show
        Paul Phillips added a comment - It seems unlikely this is fixed, because "Malformed class name" is part of our DNA until we change the name mangling scheme. But I'm sure there are a sufficient number of other tickets covering it somewhere.
        Hide
        Miguel Garcia added a comment -

        Would this help? (Quoting from SI-3623)

        $ scala -X | grep classfile
          -Xmax-classfile-name <n>       Maximum filename length for generated classes
        
        Show
        Miguel Garcia added a comment - Would this help? (Quoting from SI-3623 ) $ scala -X | grep classfile -Xmax-classfile-name <n> Maximum filename length for generated classes
        Hide
        Eugene Burmako added a comment - - edited
        Show
        Eugene Burmako added a comment - - edited I've worked around malformed class name, so it doesn't give us problems in reflection: https://github.com/scalamacros/kepler/blob/9983121a55195b80d48b452498fbb620c2efefb1/src/reflect/scala/reflect/runtime/JavaMirrors.scala#L498 .
        Hide
        Evgeny added a comment -

        I guess it is the same problem. Scala 2.10.3. Using -Xmax-classfile-name causes very disappointing exception:

        Caused by: java.lang.InternalError: Malformed class name
        	at java.lang.Class.getSimpleBinaryName(Class.java:1229)
        	at java.lang.Class.isMemberClass(Class.java:1212)
        	at scala.reflect.runtime.JavaMirrors$JavaMirror.sOwner(JavaMirrors.scala:770)
        	at scala.reflect.runtime.JavaMirrors$JavaMirror.scala$reflect$runtime$JavaMirrors$JavaMirror$$classToScala1(JavaMirrors.scala:942)
        	at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToScala$1.apply(JavaMirrors.scala:935)
        	at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToScala$1.apply(JavaMirrors.scala:935)
        	at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$toScala$1.apply(JavaMirrors.scala:104)
        	at scala.reflect.runtime.TwoWayCache.toScala(TwoWayCache.scala:38)
        	at scala.reflect.runtime.JavaMirrors$JavaMirror.toScala(JavaMirrors.scala:102)
        	at scala.reflect.runtime.JavaMirrors$JavaMirror.classToScala(JavaMirrors.scala:935)
        	at scala.reflect.runtime.JavaMirrors$JavaMirror.classSymbol(JavaMirrors.scala:206)
        	at scala.reflect.runtime.JavaMirrors$JavaMirror$JavaInstanceMirror.symbol(JavaMirrors.scala:245)
        	at scala.reflect.runtime.JavaMirrors$JavaMirror$JavaInstanceMirror.symbol(JavaMirrors.scala:243)
        
        Show
        Evgeny added a comment - I guess it is the same problem. Scala 2.10.3. Using -Xmax-classfile-name causes very disappointing exception: Caused by: java.lang.InternalError: Malformed class name at java.lang.Class.getSimpleBinaryName(Class.java:1229) at java.lang.Class.isMemberClass(Class.java:1212) at scala.reflect.runtime.JavaMirrors$JavaMirror.sOwner(JavaMirrors.scala:770) at scala.reflect.runtime.JavaMirrors$JavaMirror.scala$reflect$runtime$JavaMirrors$JavaMirror$$classToScala1(JavaMirrors.scala:942) at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToScala$1.apply(JavaMirrors.scala:935) at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToScala$1.apply(JavaMirrors.scala:935) at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$toScala$1.apply(JavaMirrors.scala:104) at scala.reflect.runtime.TwoWayCache.toScala(TwoWayCache.scala:38) at scala.reflect.runtime.JavaMirrors$JavaMirror.toScala(JavaMirrors.scala:102) at scala.reflect.runtime.JavaMirrors$JavaMirror.classToScala(JavaMirrors.scala:935) at scala.reflect.runtime.JavaMirrors$JavaMirror.classSymbol(JavaMirrors.scala:206) at scala.reflect.runtime.JavaMirrors$JavaMirror$JavaInstanceMirror.symbol(JavaMirrors.scala:245) at scala.reflect.runtime.JavaMirrors$JavaMirror$JavaInstanceMirror.symbol(JavaMirrors.scala:243)
        Hide
        Eugene Burmako added a comment -

        @Evgeny This is a separate issue. Could you provide a reproduction and submit a new bug?

        Show
        Eugene Burmako added a comment - @Evgeny This is a separate issue. Could you provide a reproduction and submit a new bug?

          People

          • Assignee:
            Eugene Burmako
            Reporter:
            Eugene Burmako
          • Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development