This is the mail archive of the java@gcc.gnu.org mailing list for the Java 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: McKoi db error


Tom Tromey wrote:
If readObject and writeObject aren't implemented, all serialization
implementations are required to fall back on the default behavior.
Are you saying that libgcj doesn't do this in some situation?

Yes, exactly. In certain cases when the writeObject method is not implemented and the readObject method is. I've attached a testcase of the bug.

That would be a libgcj bug.

It feels like it.


I don't know of any java.io bugs that would cause this behavior.
It is possible that you've run into a serialization bug, however.
The easiest way to tell would be to try to reduce it to a simple test

I'm communicating with the author, but it's extremely tedious to find since there's a *lot* of code in between the writing and the reading that fails. I'll keep you posted though.

case.  You could also look through gnats to see if there are other
serialization bugs; maybe you've run into a known one.  I'm afraid
this is an area that hasn't gotten a lot of attention in the past.

Ok, thanks for the help.


Geert Bevin

--
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.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class SerializationBug
{
	public static class Expr implements java.io.Serializable
	{
		static final long serialVersionUID = 6981261114471924028L;
		private ArrayList elements = new ArrayList();
		private transient ArrayList eval_stack;
		private StringBuffer text;
		public Expr()
		{
			text = new StringBuffer();
		}
		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;
		private long id;
		private final static Object GLOB_LOCK = new Object();
		private static int GLOB_ID = 0;
	
		public NodeType4()
		{
			synchronized (GLOB_LOCK)
			{
				id = (System.currentTimeMillis() << 16) | (GLOB_ID & 0x0FFFF);
				++GLOB_ID;
			}
		}
	}

	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;
		}
	}

	private static Class c1 = com.mckoi.JDBCDriver.class;

	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());
		}
	}
}


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