Skip to main content

JDK 8 - Java Scripting - String values passed by to Java as jdk.nashorn.internal.runtime.ConsString objects

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2006-05-18

Yet another issue relating to Java scripting:

In this instance, a simple scripting is trying to pass a simple string back to Java, e.g.

myJavaObject.setString("Hello") ;

It appears that the object received by the Java setString object is a jdk.nashorn.internal.runtime.ConsString.

This then later is causing class cast exception (at least in our code base) :

java.lang.ClassCastException: jdk.nashorn.internal.runtime.ConsString cannot be cast to java.lang.String

To work around this, I have tried below which seems to get rid of the exception

myJavaObject.setString(new String("Hello")) ;

This means that this can potentially break existing pre Java 8 code bases.

Again can someone provide some explanation ?