MersenneTwisterRNG serialization

12 views
Skip to first unread message

Alfonso Garcia

unread,
Oct 27, 2014, 6:53:48 AM10/27/14
to watch...@googlegroups.com
Is the MersenneTwisterRNG class really serializable? The following test fails and I can't quite understand why, as all declared members appear to be Serializable


import org.uncommons.maths.random.MersenneTwisterRNG;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

public class MersenneSerializationTest {

   
@Test
   
public void testMersenneSerialization() throws IOException {

       
Random r = new MersenneTwisterRNG();
       
       
FileOutputStream fos = new FileOutputStream("data/engine_mersennetest.ser");
       
DebugObjectOuputStream oos = new ObjectOuputStream(fos);
       
        oos
.writeObject(r);
       
        oos
.close();
        fos
.close();

   
}

}

The stack trace says

java.io.NotSerializableException: java.lang.Object
    at java
.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
    at java
.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
    at java
.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
    at java
.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
    at java
.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
    at java
.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
    at
MersenneSerializationTest.testMersenneSerialization

Reply all
Reply to author
Forward
0 new messages