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

Reflection does not work with local classes #5431

Closed
scabug opened this issue Feb 1, 2012 · 10 comments
Closed

Reflection does not work with local classes #5431

scabug opened this issue Feb 1, 2012 · 10 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Feb 1, 2012

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)
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 1, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5431?orig=1
Reporter: @xeno-by
Affected Versions: 2.10.0

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 20, 2012

Noah Cutler (virtualeyes) said:
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...

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 3, 2012

@magarciaEPFL said:

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>
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 5, 2012

@magarciaEPFL said:
[#comment-57227] indicates this ticket has been fixed.

@scabug scabug closed this May 5, 2012
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 30, 2012

@paulp said:
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.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 30, 2012

@paulp said:
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.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 30, 2012

@magarciaEPFL said:
Would this help? (Quoting from #3623)

$ scala -X | grep classfile
  -Xmax-classfile-name <n>       Maximum filename length for generated classes
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 30, 2012

@xeno-by said (edited on Jun 30, 2012 2:07:36 PM UTC):
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.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jan 29, 2014

Evgeny (akshaal) said:
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)
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 6, 2014

@xeno-by said:
@evgeny This is a separate issue. Could you provide a reproduction and submit a new bug?

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.