开发者

Using a Scala symbol literal results in NoSuchMethod

I have recently begun using Scala. I've written a DSL in it which can be used to describe a processing pipeline in medici. In my DSL, I've made use of symbols to signify an anchor, which can be used to put a fork (or a tee, if you prefer) in the pipeline. Here's a small sample program that runs correctly:

object Test extends PipelineBuilder {
    connector("TCP") / Map("tcpProtocol" -> new DirectProtocol())
    "tcp://localhost:4858" --> "ByteToStringProcessor" --> Symbol("hello")
    "stdio://in?promptMessage=enter name:%20" --> Symbol("hello")
    Symbol("hello") --> "SayHello" / Map("prefix" -> "\n\t")  --> "stdio://out"
}

For some reason, when I use a symbol literal in my program, I get a NoSuchMethod exception at runtime:

java.lang.NoSuchMethodError: scala.Symbol.intern()Lscala/Symbol;
        at gov.pnnl.mif.scaladsl.Test$.<init>(Test.scala:7)
        at gov.pnnl.mif.scaladsl.Test$.<clinit>(Test.scala)
        at gov.pnnl.mif.scaladsl.Test.main(Test.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce开发者_如何学JAVAssorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at scala.tools.nsc.ObjectRunner$$anonfun$run$1.apply(ObjectRunner.scala:75)
        at scala.tools.nsc.ObjectRunner$.withContextClassLoader(ObjectRunner.scala:49)
        at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:74)
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:154)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

This happens regardless of how the symbol is used. Specifically, I've tried using the symbol in the pipeline, and in a simple println('foo) statement.

The question: What could possibly cause a symbol literal's mere existence to cause a NoSuchMethodError? In my DSL I am using an implicit function which converts symbols to instances of the Anchor class, like so:

    implicit def makeAnchor(a: Symbol):Anchor = anchor(a)

Sadly, my understanding of Scala is weak enough that I can't think of why that might be causing my NoSuchMethodError.


The most likely explanation is that you are compiling with a different version of Scala than you have on the classpath at runtime.

Checking the run-time version of Scala

Add the following to your main() method:

println(classOf[scala.Symbol].getProtectionDomain.getCodeSource)

This will tell you where you are loading the Scala library from, for example:

(file:/Users/jason/usr/scala-2.8.0.RC2/lib/scala-library.jar )

Checking the compile-time version of Scala

I don't know how you are invoking scalac. Assuming it's from the command line, run scalac -version.


Could you possibly have multiple versions of Scala installed, as from the 2.7.1 source at least (http://scala-tools.org/scaladocs/scala-library/2.7.1/Symbol.scala.html) it doesn't look like Symbol has an intern method?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜