Accessing Scala Code from Java Codebase

Dear all,

I am grappling with this codebase called JPF that is unfortunately developed in Java. I would like to get JPF to analyse my Scala stuff. Apparently, I am missing something basic in plugging Scala code into Java codebase. That I say because JPF fails to find the class files of my Scala.Can anyone help on that please?

TIA,
–Hossein

What commands are you issuing and what error message are you getting?

Hi Seth,

The error message is this:

Executing command: java -jar C:…\JPF\JPF_HOME\build\RunJPF.jar +shell.port=4242 C:…JPF\jpf-tut-new\src\examples\MyRCTest.jpf
[SEVERE] cannot load application class RC2

I am using ScalaIDE to verify my src/examples/MyRCTest.jpf that is as follows:

target = RC2

listener=tutorial.RangeChecker

rc.field=RC2.data
rc.min=0
rc.max=42

where RC2 is the following simple Scala file:

object RC2 {
var data: Int = ???

def setData(d: Int) {data = d}

def main(args: Array[String]) {
setData( 42)
setData(-42)
}
}

I have even copied RC2.class and RC2$.class to my src/classes and build/main. But, I still get the same error message, which indicates JPF not being able to locate files.

Any idea?

TIA,
–Hossein

What requirements does JPF have for ‘application classes’? If JPF needs
to instantiate those classes, it will probably have some expectations
about the accessibility and signatures of their constructors, for
example, which a Scala object is unlikely to meet. (Those are just some
ideas, I have no idea what JPF is.) Could RC2 be a class instead of an
object?

PS: Maybe it was just there for illustration, but the line

var data: Int = ???

will cause an exception to be thrown from RC2’s constructor.

Hi Clint,

I don’t know all their requirements, in fact. More to the point is that I don’t know how to find that out. I haven’t been able to find a clear list in their documentations. Neither is the JPF mailing list active/informative.

Well, the thing is that JPF’s entry point has to be a Java main method. So, I also tried:

class MyRCTest3 extends App {
  var data: Int = 0
  setData( 42)
  setData(-42)
  
  def setData(d: Int) {data = d}
  
  def getInstance() = new MyRCTest3
}

But, then, after updating my .jpf file to

target = MyRCTest3
target.classpath = ...

listener=tutorial.RangeChecker

rc.field=MyRCTest3.data
rc.min=0
rc.max=42

I get the following error:

[SEVERE] cannot load application class scala.reflect.ScalaSignature

I javap’ed my MyRCTest3.class and there is no mention of scala.reflect.ScalaSignature. I wonder where JPF gets that from… :confused: Anyway, maybe I should ask how do I find scala.reflect.ScalaSignature on my machine?

TIA,
–Hossein

scala.reflect.ScalaSignature is located in the scala-library-*.jar, * being whatever Scala version you’re using.

I think it’s an annotation that the compiler applies to the classes it generates to preserve some extra information that the compiler and possibly runtime reflection needs later on.

Thank you Jasper. I updated my .jpf file accordingly to

target = MyRCTest3
target.native_classpath = C:\\...\\org.scala-lang.scala-library.source_2.11.8.v20160304-115712-1706a37eb8.jar
target.classpath = ...

listener=tutorial.RangeChecker

rc.field=MyRCTest3.data
rc.min=0
rc.max=42

And, I still get the same error.

[SEVERE] cannot load application class scala.reflect.ScalaSignature

Am I pointing JPF to the wrong jar? Or, is JPF being too stupid in not finding it there?

I am just guessing here, but possibly native_classpath is where it looks for native libraries (meaning dll, so, …)? What about the normal classpath variable? If that doesn’t work, possibly (still guessing) there is also a bootclasspath?

Hello,

Is that a jar file containing sources? You need to put the jar file
containing the compiles class files on the class path.

 Best, Oliver

The problem is that I don’t know the syntax for more than one classpath item.

And, I get the same error message with both bootclasspath and boot_classpath. Perhaps, JPF is simply ignoring its unknown keys. And, I don’t know where to find the list of key… :disappointed:

What’s your next guess? :wink:

Sorry Olivier. But, I don’t comprehend your words. Would you mind paraphrasing/expanding?

Hello,

The most commonly used kind of jar file is the one that contains the
class files to satisfy dependencies. But there are also jar files that
instead provide source code or documentation. The word “source” in the name
of your jar file made me wonder whether you got one of those.

 Best, Oliver

You can probably add multiple entries to your classpath by separating them with :.
My next guess would be what Oliver is saying.

I see. So, I changed it to the only other similarly-named file I have:

org.scala-lang.scala-library_2.11.8.v20160304-115712-1706a37eb8.jar

And, I get the same error.

Didn’t work either. I’ll try to pick that specifically up with the JPF list.

But, one thing I’d like here is that, given that there is no mention of scala.reflect.ScalaSignature in my javap outputs, I wonder where that ended up getting in my code from. Any idea?