problem with scala.tools.interpreter.IMain bind

120 views
Skip to first unread message

debasish

unread,
Jun 18, 2011, 4:29:28 PM6/18/11
to scala-user
Hi -

I am getting this error in bind from tools.nsc.interpreter.IMain ..
can anyone please help me out ? The bind used to work in earlier
versions of Scala .. Here's the REPL ..

Welcome to Scala version 2.9.0.final (Java HotSpot(TM) Server VM, Java
1.6.0_24).

Type in expressions to have them evaluated.

Type :help for more information.

scala> import scala.tools.nsc.interpreter.IMain
import scala.tools.nsc.interpreter.IMain

scala> val i = new IMain
i: scala.tools.nsc.interpreter.IMain =
scala.tools.nsc.interpreter.IMain@d5b561

scala> class ResHolder(var value: Any)
defined class ResHolder

scala> val holder = new ResHolder(null)
holder: ResHolder = ResHolder@1fd54c4

scala> i.bind("$res__", holder.getClass.getName, holder)
<console>:5: error: not found: value $line3

var value: ResHolder = _

^
<console>:6: error: not found: value $line3

def set(x: Any) = value = x.asInstanceOf[ResHolder]

^
res0: scala.tools.nsc.interpreter.Results.Result = Error


Thanks.

Florian

unread,
Jun 29, 2011, 8:07:31 AM6/29/11
to scala-user
Hi,

I'm getting the same error (using the Interpreter class in Scala 2.8
works fine).

Welcome to Scala version 2.9.0.1 (OpenJDK Server VM, Java 1.6.0_20).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import scala.tools.nsc.interpreter.IMain
import scala.tools.nsc.interpreter.IMain

scala> val i = new IMain
i: scala.tools.nsc.interpreter.IMain =
scala.tools.nsc.interpreter.IMain@18aecf1

scala> class Test(val value: Int)
defined class Test

scala> val t = new Test(42)
t: Test = Test@6af2fb

scala> i.bind("test", t)
java.lang.InternalError: Malformed class name
at java.lang.Class.getSimpleName(Class.java:1150)
at java.lang.Class.isAnonymousClass(Class.java:1205)
at
scala.tools.nsc.interpreter.RichClass.isScalaAnonymous(RichClass.scala:
16)
at scala.tools.nsc.interpreter.TypeStrings
$class.scalaName(TypeStrings.scala:47)
at scala.tools.nsc.interpreter.TypeStrings
$.scalaName(TypeStrings.scala:114)
at scala.tools.nsc.interpreter.TypeStrings
$class.fromManifest(TypeStrings.scala:88)
at scala.tools.nsc.interpreter.TypeStrings
$.fromManifest(TypeStrings.scala:114)
at scala.tools.nsc.interpreter.NamedParam
$Typed.<init>(NamedParam.scala:27)
at scala.tools.nsc.interpreter.NamedParamCreator
$class.apply(NamedParam.scala:15)
at scala.tools.nsc.interpreter.NamedParam$.apply(NamedParam.scala:25)
at scala.tools.nsc.interpreter.NamedParamCreator
$class.tuple(NamedParam.scala:22)
at scala.tools.nsc.interpreter.NamedParam$.tuple(NamedParam.scala:25)
at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:545)
at .<init>(<console>:12)
at .<clinit>(<console>)
at .<init>(<console>:11)
at .<clinit>(<console>)
at $export(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
43)
at java.lang.reflect.Method.invoke(Method.java:616)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:
592)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun
$10.apply(IMain.scala:828)
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV
$sp(Line.scala:43)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:31)
at java.lang.Thread.run(Thread.java:636)

scala> i.bind("test", t.getClass.getName, t)
<console>:5: error: not found: value $line3
var value: Test = _
^
<console>:6: error: not found: value $line3
def set(x: Any) = value = x.asInstanceOf[Test]
^
res2: scala.tools.nsc.interpreter.Results.Result = Error



Is this a bug? Thanks in advance.

Norbert Tausch

unread,
Jun 29, 2011, 8:51:28 AM6/29/11
to scala...@googlegroups.com
Today I also had this 'java.lang.InternalError: Malformed class name'
error the first time:

Exception in thread "main" java.lang.InternalError: Malformed class name
at java.lang.Class.getSimpleName(Unknown Source)
at java.lang.Class.isAnonymousClass(Unknown Source)
at java.lang.Class.isLocalClass(Unknown Source)

***
But: In my case the class is pre-compiled 'normally' by the Scala
compiler and then later used in a Scala program run by the Scala
interpreter.

It hasn't appeared in the last Scala version with the old scala
interpreter interface. This is something new.

The class can be decompiled by the jad decompiler. There seems nothing
wrong. Perhaps this has something to do with class loaders. My Scala
interpreter uses its default class loader which is linked to a Java
parent class loader using this code:

class QueryInterpreter(classPath: String, parentClassLoader: ClassLoader)
{
val settings: Settings = new Settings()
val interpreterOutputStream = new ByteArrayOutputStream()
var interpreter: Interpreter = null

try
{
settings.classpath.value = classPath
settings.embeddedDefaults(parentClassLoader) <-- ***** Here
is the link to the parent class loader set *******

interpreter = new Interpreter(settings, new
PrintWriter(interpreterOutputStream))
interpreter.setContextClassLoader
}
catch
{
case exception =>
{
// Print error message if there is one
flushToConsole()

throw new Exception(exception)
}
}

.......
}


Best regards

Norbert Tausch

Reply all
Reply to author
Forward
0 new messages