Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Environment:Ubuntu 6.10 Edgy Eft + Groovy r4630
-
Number of attachments :
Description
Serialization appears to work fine but deserialization fails to work at all.
The script;
import java.io.FileInputStream import java.io.FileOutputStream import java.io.ObjectInputStream import java.io.ObjectOutputStream import java.io.Serializable 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. assert data == newData
results in the output:
Caught: java.lang.ClassNotFoundException: Blah
at serialization.run(serialization.groovy:22)
at serialization.main(serialization.groovy)
after discussion with several other people I must say it is not the fault of groovy. Java uses the last defined ClassLoader to loader the class. In many environments this might mean that the wrong class loader is chosen or that it works one day and the other day not. The only secure way out of this is the solution I already posted on the mailing list