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

Classloading problems in REPL with Scala reflection #5256

Closed
scabug opened this issue Nov 30, 2011 · 6 comments
Closed

Classloading problems in REPL with Scala reflection #5256

scabug opened this issue Nov 30, 2011 · 6 comments
Assignees
Labels

Comments

@scabug
Copy link

@scabug scabug commented Nov 30, 2011

Scala reflection doesn't work in REPL due to classloading issues, see:

Welcome to Scala version 2.10.0.r26077-b20111127225325 (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> class A
defined class A

scala> classToType(classOf[A])
java.lang.NullPointerException
	at scala.reflect.runtime.JavaToScala$class.javaClass(JavaToScala.scala:46)
	at scala.reflect.runtime.Universe.javaClass(Universe.scala:11)
	at scala.reflect.runtime.JavaToScala$class.javaClass(JavaToScala.scala:44)
	at scala.reflect.runtime.Universe.javaClass(Universe.scala:11)
	at scala.reflect.runtime.JavaToScala$class.isJavaClass(JavaToScala.scala:51)
	at scala.reflect.runtime.Universe.isJavaClass(Universe.scala:11)
	at scala.reflect.runtime.Loaders$PackageScope.lookupEntry(Loaders.scala:113)
	at scala.reflect.internal.Types$Type.findDecl(Types.scala:872)
	at scala.reflect.internal.Types$Type.decl(Types.scala:498)
	at scala.reflect.internal.SymbolTable.openPackageModule(SymbolTable.scala:185)
	at scala.reflect.runtime.Loaders$LazyPackageType.complete(Loaders.scala:88)
	at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:910)
	at scala.reflect.runtime.JavaToScala$class.makeScalaPackage(JavaToScala.scala:334)
	at scala.reflect.runtime.Universe.makeScalaPackage(Universe.scala:11)
	at scala.reflect.runtime.JavaToScala$class.packageNameToScala(JavaToScala.scala:322)
	at scala.reflect.runtime.Universe.packageNameToScala(Universe.scala:11)
	at scala.reflect.runtime.JavaToScala$class.makeScalaPackage(JavaToScala.scala:331)
	at scala.reflect.runtime.Universe.makeScalaPackage(Universe.scala:11)
	at scala.reflect.runtime.JavaToScala$$anonfun$packageToScala$1.apply(JavaToScala.scala:314)
	at scala.reflect.runtime.JavaToScala$$anonfun$packageToScala$1.apply(JavaToScala.scala:314)
	at scala.reflect.runtime.ConversionUtil$TwoWayCache.toScala(ConversionUtil.scala:30)
	at scala.reflect.runtime.JavaToScala$class.packageToScala(JavaToScala.scala:313)
	at scala.reflect.runtime.Universe.packageToScala(Universe.scala:11)
	at scala.reflect.runtime.JavaToScala$class.scala$reflect$runtime$JavaToScala$$sOwner(JavaToScala.scala:249)
	at scala.reflect.runtime.JavaToScala$$anonfun$classToScala$1.apply(JavaToScala.scala:375)
	at scala.reflect.runtime.JavaToScala$$anonfun$classToScala$1.apply(JavaToScala.scala:354)
	at scala.reflect.runtime.ConversionUtil$TwoWayCache.toScala(ConversionUtil.scala:30)
	at scala.reflect.runtime.JavaToScala$class.classToScala(JavaToScala.scala:353)
	at scala.reflect.runtime.Universe.classToScala(Universe.scala:11)
	at scala.reflect.runtime.Universe.<init>(Universe.scala:41)
	at scala.reflect.runtime.Mirror.<init>(Mirror.scala:9)
	at scala.reflect.runtime.Mirror$.<init>(Mirror.scala:46)
	at scala.reflect.runtime.Mirror$.<clinit>(Mirror.scala)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:247)
	at scala.reflect.ReflectionUtils$.singletonInstance(ReflectionUtils.scala:34)
	at scala.reflect.package$.mirror(package.scala:11)
...
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Nov 30, 2011

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Dec 1, 2011

@xeno-by said:
Related to this bug is #5226. Strangely enough, it manifests itself only on Mac (at least, I wasn't able to reproduce it on my Windows laptop). Also, the aforementioned issue also mentions a workaround that seems to work.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jan 20, 2012

@retronym said:
Workaround is to use -Yrepl-sync.

scala>   ~/code/scala scala210 -Yrepl-sync
Welcome to Scala version 2.10.0-M1 (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> Thread.currentThread.getContextClassLoader
res0: ClassLoader = Cl#611660851

scala> reflect.mirror.classToSymbol(classOf[List[_]])
res1: reflect.mirror.Symbol = class List

scala> 

scala>   ~/code/scala scala210
Welcome to Scala version 2.10.0-M1 (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> Thread.currentThread.getContextClassLoader
res0: ClassLoader = null

scala> reflect.mirror.classToSymbol(classOf[List[_]])
java.lang.NullPointerException
	at scala.reflect.runtime.JavaToScala$class.javaClass(JavaToScala.scala:48)
	at scala.reflect.runtime.Universe.javaClass(Universe.scala:11)
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jan 31, 2012

@paulp said (edited on Jan 31, 2012 2:44:24 PM UTC):
This fails differently now (and fails the same with -Yrepl-sync) on OSX. Can anyone comment on where the responsibility lies?

scala> classToType(classOf[A])
java.lang.AssertionError: assertion failed: <none>/class /<none>/
	at scala.Predef$.assert(Predef.scala:160)
	at scala.reflect.runtime.JavaToScala$$anonfun$classToScala$1.apply(JavaToScala.scala:360)
	at scala.reflect.runtime.JavaToScala$$anonfun$classToScala$1.apply(JavaToScala.scala:354)
	at scala.reflect.runtime.ConversionUtil$TwoWayCache.toScala(ConversionUtil.scala:31)
	at scala.reflect.runtime.JavaToScala$class.classToScala(JavaToScala.scala:354)
	at scala.reflect.runtime.Universe.classToScala(Universe.scala:11)
	at scala.reflect.runtime.JavaToScala$class.scala$reflect$runtime$JavaToScala$$sOwner(JavaToScala.scala:245)

Oh, I see it's calling getSimpleName, that's probably doomed anyway.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jan 31, 2012

@xeno-by said:
Yeah, speaking of getSimpleName, this is how I went from this bug to #5425. Regarding the assertion, I'll take a look once class names are sorted out.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 2, 2012

@xeno-by said:
Fixed by scala/scala@1e07077

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.