Casting PyObjects to Java Interfaces fails when constructed from a URLClassLoader

Jimmy Mauri <[email protected]> Thu, 19 May 2016 20:22:01 -0400
Newsgroups gmane.comp.lang.jython.user
Message-ID <CAKs7Ag2xKr8cA8HNM5JqsnMxA0Y4ZFBHscjT_tOC-ibGUOzZBQ@mail.gmail.com>
For context, see sample project in:
https://github.com/ElCubanoPoderoso/jython-classloader-issue

I have a use-case where I must support dynamically loaded .jar files as
hot-deployable subapplications.  I was having trouble in instances where if
the .jar file was redeployed (say I made a code change and need to update
the environment), Jython starts to break down with class casting.  Upon the
first deployment, the application is able to properly load the .jar file,
instantiate the main class which creates the interpreter with the packaged
URLClassLoader into the PySystemState object, interprets the script and
creates the class object with the appropriate java interface cast to it.

However, the second invocation of said project causes the casting to fail
on subsequent executions, converting the object to a PySingleton and
rejecting the cast.  I'm having trouble understanding what I need to do to
resolve my issue.  Not being able to properly coerce the object to the
expected java interface is causing forced workarounds to add wrapper
objects to utilize them in Java code.

Note:  This is only observed when trying to cast to interfaces that reside
inside the .jar file and not in the system classloader.

The sample GitHub project linked was simplified to generate a
proof-of-concept that can be invoked via JUnit to reproduce the error.

My question is:  what is wrong with my current implementation that is
causing this issue?  As part of the requirement, I must be able to redeploy
without shutting down the JVM.  Any help in this matter would be
appreciated.

Thanks,
~Jimmy M.

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j

_______________________________________________
Jython-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-users