Hi all,
is there somewhere documentation as of what class loader will be used if
Class.forName is called with only a String? and maybe if there is a way
to influence that? The background is, that deserialization often fails
to work in Groovy because of class loader issues when used in scripts.
Afaik deserialization uses Class.forName(String) to do its work.
I did find two "solutions" to this problem:
(1) ensure there is only one class loader.
this solves a few cases, but in other cases you want more complex
structures and it would be very nice if a evaluate call from inside a
script wold just do
(2) use this class:
> ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data))
> {
> protected Class resolveClass(ObjectStreamClass objectStreamClass) throws
> IOException, ClassNotFoundException {
> return Class.forName(objectStreamClass.getName(), true, myClassLoader);
> }
> };
instead of ObjectInputStream.
Now this gives me several problems... for once I would like to have more
control over the serialization and deserialization process, but with the
standard deserialization there is no chance it seems.
to at last document the problem I would like to know a bit more about
how the class loader is chosen. If I know it right, then it goes to the
frame before Class.forName was called and uses the class loader of the
calling class there. That means in this frame I would have to have my
Groovy class... which can not happen, because our stacks are bigger. So
the code usually ends up in in the class loader knowing the Groovy
runtime, and that loader does not know the scripts, which are defined in
a class loader being child of that loader.... or even deeper.
I wonder how invokedynamic would behave here... does invokedynamic add
stack frames? if not, then there is a chance that Class.forName would
work again. If its adding stack frames, then I see no chance.
btw, a sample to reproduce the problem in Groovy:
> class Blah implements Serializable {
> def x
> def y
> public Blah ( x , y ) {
> this.x = x
> this.y = y
> }
> }
>
> def fileName = 'thingy.txt'
> def data = [ new Blah ( 1 , 2 ) , new Blah ( 'flob' , 'adob' ) ]
> def file = new ObjectOutputStream ( new FileOutputStream ( fileName ) )
> file.writeObject ( data )
> file.close ( )
> file = new ObjectInputStream ( new FileInputStream ( fileName ) )
> def newData = file.readObject ( ) // ClassNotFoundException here.
bye Jochen
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
http://www.g2one.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---