I'm trying to find a workaround for Nashorn to be compatible with every version of Java from 1.8 upwards as said in another question I asked earlier.
I'm currently trying to catch UnsupportedClassVersionError
in order to find out if the system is able to run the standalone Nashorn for Java 15 like this (Kotlin code):
scriptEngine = try {
// Java >= 15
org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory().scriptEngine
} catch(e: UnsupportedClassVersionError) {
// Java < 15
@Suppress("DEPRECATION")
jdk.nashorn.api.scripting.NashornScriptEngineFactory().scriptEngine
}
However it looks like the error is not caught. The stack trace is as follows:
java.lang.UnsupportedClassVersionError: org/openjdk/nashorn/api/linker/NashornLinkerExporter has been compiled by a more recent version of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions up to 55.0
I also have tried to catch NoClassDefFoundError
inverting the previous try/catch (load Java < 15 Nashorn, if it doesn't exist load the standalone one) but the error is the same.
Edit: looks like the error is thrown by the Java < 15 Nashorn itself.