Classes generated by gen-class aren't loadable from remote codebase for mis-implementation of static-initializer

Description

When a genclass'ed object is serialized and sent to a remote system, the remote system throws an exception loading the object:

Reproduce:

Cause:

A gen-classed class (in this case, SampleInterfaceImpl.class) uses a static-initializer for loading SampleInterfaceImpl__init.class like:

RT.load in default uses a context-classloader for loading __init.class but all classes depending on a gen-classed class must be loaded from the same classloader. In this case, RT.load must use a remote URLClassLoader which loads the main class.

Proposed:

Instead produce the equivalent of this in the static initializer:

With this code, RT.load will uses a same classloader which load SampleInterfaceImpl.class.

Patch: clj-1157-v2.diff

Screened by:

Environment

Tested on Mac OS X 10.9.1 and Oracle JVM 1.7.0_51 with Clojure 1.6 master SNAPSHOT

Attachments

2

Activity

Alex Miller September 25, 2014 at 4:16 PM

Added almost the same patch that does not have whitespace error.

Tsutomu Yano January 21, 2014 at 9:01 AM

I put a new patch applicable on the latest master branch.
This new patch is simpler and robust because the code-generation becomes very simple. Now It just call a method implemented with Java.

And I fixed my sample program and the 'HOW TO REPRODUCT THIS ISSUE' section of this ticket, because old description is not runnable on newest JVM. It is because the specification of remote method call of the newest JVM was changed from the old one. In the newest JVM, we need a 'java.rmi.server.useCodebaseOnly=false' option for making the behavior of remote call same as old one.
pull the newest sample.

Andy Fingerhut January 11, 2014 at 8:47 PM

Patch 20130204_fix_classloader.diff dated Feb 3, 2013 no longer applies cleanly as of the latest commits to Clojure master on Jan 11, 2014. The only conflict in applying the patch appears to be in the file src/jvm/clojure/asm/commons/GeneratorAdapter.java. This is probably due to the commit for ticket that was committed today, updating the ASM library.

Stuart Halloway March 1, 2013 at 6:12 PM

It seems overly complex to have the patch do so much code generation. Why not implement a method that does this job, and have the generated code call that?

Stuart Halloway March 1, 2013 at 4:20 PM

This sounds reasonable, but anything touching classloaders must be considered very carefully.

Completed

Details

Assignee

Reporter

Labels

Approval

Patch

Priority

Fix versions

Created February 4, 2013 at 7:06 AM
Updated July 31, 2015 at 9:39 PM
Resolved July 31, 2015 at 9:39 PM