jep
jep copied to clipboard
class java.lang.UnsatisfiedLinkError cannot be cast to class java.lang.Exception (java.lang.UnsatisfiedLinkError and java.lang.Exception are in module java.base of loader 'bootstrap')
Issue I keep getting the UnsatisfiedLinkError whenever I try to initiate the Class Jep, I'm using Coldfusion framework (which is writting in java), and I have written a small sample code in java recently to just get started and it works just fine!
Just to dive into details, here's my Java class :
imports ...*
`public class JepIssue { public static void main(String[] args) throws JepException { // Jep Shared library should be linkable Jep jep = new SharedInterpreter();
//Redirect Python stream to Java
jep.eval("from jep import redirect_streams");
jep.eval("redirect_streams.setup()");
jep.eval("from java.lang import System" );
jep.eval("import sys" );
jep.eval("System.out.println('Hello from Java ')" );
// jep.eval("print('hello from Python')");
jep.eval("print(sys.version)");
jep.eval("print (sys.path)") ;
jep.eval("pays = {\"region\": [\"Paris\", \"Grenoble\"]}");
jep.eval("import pandas as pd");
jep.eval("tab = pd.DataFrame(pays)");
jep.eval("print(tab)");
}
public Jep Myjep() throws JepException{
return new SharedInterpreter();
}
}`
And even if you are unfamiliar with Coldfusion, I haven't done a big deal, I just used the JavaClassLoader repository On Github which allows to load dynamically java classes / jars.
I created the Jep,JepConfig and SharedInterpreter objects succesfully , but that is not enought to run Jep yet, because I do not have an instance yet, and that's where I'm stuck. here's my Coldfusion code (every line is commented) :
`
/*
This points to the jar we want to load.
Could also load a directory of .class files
*/
paths[1] = expandPath("jep.jar");
//create the loader
loader = createObject("component", "javaloader.JavaLoader").init(paths);
//The init() function initializes any variables needed by the component's functions. Then returns a reference to the current component.
//load the JepConfig class
JepConfig = loader.create("jep.JepConfig").init();
writedump(JepConfig); //writedump() is the equivalent of print()
//load the SharedInterpreter
JepInterp = loader.create("jep.SharedInterpreter");
writedump(JepInterp);
//at this stage we only have access to the class, but we don't have an instance
**JepJep = loader.create("jep.Jep").init();**
writedump(JepJep); // returns the UnsatisfiedLinkError , obvisouly because the class is not static
/*
Create the instance, just like me would in createObject("java", "HelloWorld").init()
This also could have been done in one line - loader.create("HelloWorld").init();
*/
//hello = HelloWorld.init();
</cfscript>`
Expected behavior As in Java : Jep jep = new SharedInterpreter(); in Coldfusion : JepJep = loader.create("jep.Jep").init(); // the .init() whether with or without the SharedInterpreter argument returns an error.
Environment
- OS Platform : Windows 10
- Python 3.8
- JDK 1.8
- Jep Version: 3.9.1
I have done the same process whether by using the JavaClassLoader or CreateObject("Java","ClassName").init(); I also created a java method with type jep and returns the initiated Jep in java but that didnt work as I expected. I thought of creating an issue and looking forward to some answers or hints!
Thanks!
Your error indicates that cold fusion is not able to handle the UnsatisfiedLinkError. To figure out what is going wrong you will need to get the message from the UnsatisfiedLinkError, if you can post that I may be able to provide more details.
The most likely problem is that your java classloader cannot find libjep. Normally this is fixed by setting the java.library.path property or the LD_LIBRARY_PATH environmental variable to the directory containing libjep.
@bsteffensmeier if the classloader cannot find libjep how would it be able to return the Jep object (but not being able to create an instance )? I have already configured the Path environement to that libjeb directory, same for Coldfusion /libs , here's the full UnsatisfiedLinkError stacktrace message :
at cfindex2ecfm1457549695.runPage(C:/ColdFusion2018/cfusion/wwwroot/30Nov/JavaLoader/example/loadJep/index.cfm:38)
java.lang.ClassCastException: class java.lang.UnsatisfiedLinkError cannot be cast to class java.lang.Exception (java.lang.UnsatisfiedLinkError and java.lang.Exception are in module java.base of loader 'bootstrap')
at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:176)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:84)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3380)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3357)
at cfindex2ecfm1457549695.runPage(C:\ColdFusion2018\cfusion\wwwroot\30Nov\JavaLoader\example\loadJep\index.cfm:38)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:262)
at coldfusion.tagext.lang.IncludeTag.handlePageInvoke(IncludeTag.java:729)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:565)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:597)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:43)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:162)
at coldfusion.filter.IpFilter.invoke(IpFilter.java:45)
at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:96)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:60)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
at coldfusion.CfmServlet.service(CfmServlet.java:226)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:311)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:46)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at coldfusion.inspect.weinre.MobileDeviceDomInspectionFilter.doFilter(MobileDeviceDomInspectionFilter.java:121)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:491)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:764)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1388)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)
Path environement variables :
And here's the objects being printed by Coldfusion :
@bsteffensmeier if the classloader cannot find libjep how would it be able to return the Jep object (but not being able to create an instance )?
You are correct it should not be possible to create a Jep instance if the library has not loaded.
here's the full UnsatisfiedLinkError stacktrace message :
Can you provide a message for the UnsatisfiedLinkError. The message generally indicates which library has failed to link but the message is not visibe in your stack trace because we are only seeing the the ClassCaastException.
This is as far as it goes sir :
The message says : Error casting an object of type class java.lang.UnsatisfiedLinkError cannot be cast to class java.lang.Exception (java.lang.UnsatisfiedLinkError and java.lang.Exception are in module java.base of loader 'bootstrap') to an incompatible type. This usually indicates a programming error in Java, although it could also mean you have tried to use a foreign object in a different way than it was designed.
My guess is that it has something to do with the instantiation arguments, because creating Jep works fine without the .init(), but for some reason I cannot have an instance of it , in the other hand it works just fine with my Java example which is really confusing!
Question if you may : what's the role of throwing JepException ? Don't get me wrong I'm not talking about what's a JepException.. In other words if I remove the "throws JepException " nothing will work anymore , is the instantiation of jep and the Exception are connected somehow ? I'm asking this because I've been stuck at instantiation Jep in Coldfusion framework for a while now and the fact that I needed to do the same Java code in Coldfusion to make sure it will work the same way but it didnt due to the above explanations, now what if this is related to that JepException ?
@Klodovskyy I'm not sure what you mean. JepException is basically a catch-all for anything that can go wrong when we interact with the cpython API. If you were to remove all "throws JepException" it could theoretically work, normal usage does not rely on that exception. But when errors or Python exceptions occur then the native code is creating and throwing JepEcxception so if those errors get thrown and aren't declared things would break.
@bsteffensmeier theoretically it should work without the JepException if there is no errors right ?
well check this out :
-Code with Exception :
-Code without Exception :
weird isn't it ? the reason I'm discussing this with you is that I'm thinking that I couldn't instantiate the sharedinterpreter in coldfusion because the lack of some kind of Required Exception maybe ?
I was thinking you meant removal of JepException from all the Jep classed. For a simple main like that you must handle the exception from jep because it is a checked exception.
I don't know enough about cold fusion to know if the problem is related to the exception however if coldfusion is able to load the other java classes I don't know why the exception would be a problem.
Coldfusion is written in java and can handle core java code as well, it loaded the classes(Jep, sharedInterpreter, subInterpreter etc..) succesfully it's just when it comes to the instantiation it returns this cast error ( name of this issue). I even checked the source code of jep and I found 2 occurences of this exception, both as I remmeber are related to path locating or loading of the .jar, which doesnt make sense to me ( if it cannot locate the jar how can it create an object of class jep.Jep ? ) .. even confused me more! I've tried with the mentioned JDKs ,Python Version in documentations using both Windows and Linux (Ubuntu), but the same issue kept popping
I am closing this as inactive, the error appears to be related to a very specific environment and cannot be reproduced in our testing.