This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Making Serializable Classes


Ranjan Bagchi wrote:
>
> I was experimenting with creating classes in Kawa, and was curious about making
> Serializable classes.
> ...
> What didn't work fine was deserializing the object:  I get the following error
> java.lang.ClassNotFoundException: MyClass
>  at java.net.URLClassLoader$1.run(URLClassLoader.java:201)

The problem is that dynamically generated classes are loaded from 
ArrayClassLoaders, and a new ArrayCloassLoader instance is created
for each itme an expression is evaluated.  This works find for normal
Scheme code, but not for classes that must be referenced by name.

The fix to change Kawa so it uses a shared ArrayClassLoader (perhaps
one per top-level Environment), but it gets a little trickier because
we want to garbage collect anonyous temporary classes.

A work-around is to wrap your entire program in a (begin ...).
That seems to work.

A better solution is to compile any code that uses define-class:

java kawa.repl -C MyModule.scm)
java kawa.repl -e '(load <MyModule>)' --

That makes MyClass visble to the default system class loader.
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]