This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: McKoi db error
Dman, attached the wrong version :-/ Take this one instead. Sorry for
the confusion.
Geert Bevin wrote:
I've attached a testcase of
the bug.
--
Geert Bevin Uwyn
"Use what you need" Lambermontlaan 148
http://www.uwyn.com 1030 Brussels
gbevin at uwyn dot com Tel & Fax +32 2 245 41 06
PGP Fingerprint : 4E21 6399 CD9E A384 6619 719A C8F4 D40D 309F D6A9
Public PGP key : available at servers pgp.mit.edu, wwwkeys.pgp.net
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class SerializationBug
{
public static class Expr implements java.io.Serializable
{
static final long serialVersionUID = 6981261114471924028L;
public Expr()
{
}
/*
* if this method is commented out you get the error message
*
* Exception in thread "main" java.lang.Error:
* IO Error: Unknown marker on stream: 0
* at SerializationBug.main(java.lang.String[]) (Unknown Source)
*/
private void writeObject(java.io.ObjectOutputStream out)
throws IOException
{
out.defaultWriteObject();
}
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
in.defaultReadObject();
}
}
public static class NodeType4 implements java.io.Serializable
{
static final long serialVersionUID = 7866310557831478639L;
// this member variable needs to be there too, otherwise
// the bug doesn't appear, not a single clue why
private long id;
public NodeType4()
{
}
}
public static class NodeType3 implements java.io.Serializable
{
static final long serialVersionUID = -108747827391465748L;
private Object first;
private Object second;
public NodeType3(Object first, Object second)
{
this.first = first;
this.second = second;
}
}
public static class NodeType2 implements java.io.Serializable
{
static final long serialVersionUID = -7783166856668779902L;
private Object first;
private Object second;
public NodeType2(Object first, Object second)
{
this.first = first;
this.second = second;
}
}
public static class NodeType1 implements java.io.Serializable
{
static final long serialVersionUID = 4133205808616807832L;
private Object first;
private Object second;
private Object third;
public NodeType1(Object first, Object second, Object third)
{
this.first = first;
this.second = second;
this.third = third;
}
}
public static void main(String[] args)
{
System.out.println("testing");
try
{
ByteArrayOutputStream byte_out = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(byte_out);
NodeType4 node6 = new NodeType4();
NodeType3 node5 = new NodeType3(node6, null);
NodeType4 node4 = new NodeType4();
NodeType3 node3 = new NodeType3(node4, new Expr());
NodeType2 node2 = new NodeType2(node3, node6);
NodeType1 node1 = new NodeType1(node2, null, null);
System.out.println("writing nodes");
out.writeObject(node1);
out.flush();
out.close();
out = null;
System.out.println("reading nodes");
byte[] buf = byte_out.toByteArray();
ObjectInputStream in =
new ObjectInputStream(new ByteArrayInputStream(buf));
try
{
in.readObject();
}
catch (ClassNotFoundException e1)
{
e1.printStackTrace();
}
}
catch (IOException e)
{
throw new Error("IO Error: " + e.getMessage());
}
}
}