[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug classpath/25313] New: InetAddress objects do not serialize/deserial
From: |
Josh at allDucky dot com |
Subject: |
[Bug classpath/25313] New: InetAddress objects do not serialize/deserialize |
Date: |
8 Dec 2005 18:04:18 -0000 |
When attempting to serialize an InetAddress to a byte array and subsequently
deserialize the array to reconstruct a new InetAddress, the result is always a
null Object.
This operation works properly using Sun Java 1.5:
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
I tested the following combinations:
sun compiler, sun jvm/classpath --> success
sun compiler, gij jvm/classpath --> failed
gcj compiler, gij jvm/classpath --> failed
gcj compiler, sun jvm/classpath --> success
gcj compiler to a.out --> failed
Thus, I think its pretty clear the the problem lies in the gnu classpath
libraries.
Here is the source code that I used to produce the problem.
===============================================================================
GCJBug.java
===============================================================================
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
/**
* @author jdanziger
*
*/
public class GCJBug
{
/**
* @param args (duh)
*/
public static void main(String[] args)
{
InetAddress addr, copy ;
byte[] serialized_data ;
try { addr = InetAddress.getLocalHost() ; }
catch (Exception e) { throw new RuntimeException(e) ; }
serialized_data = serializeObject(addr) ;
copy = (InetAddress) deserializeObject(serialized_data) ;
System.out.println("serialized_data length: " + serialized_data.length +
" bytes.") ;
System.out.println("addr: " + addr) ;
System.out.println("copy: " + copy) ;
} // end public static void main(String[] args)
/**
* Converts the object to a serialized byte array, which saves us the
* trouble of making a binary format for sending the data across the
* network
*
* There is a possibility that this function causes deadlock if the size
* of the serialized object is greater than the allocated byte buffer,
* but I am not sure if there is an easy way to fix it. For now, we assume
* that everything that we try to seralize is less than that size, or
* else it would never make it across the network.
*
* @return a byte array representing the serialized version of this object
*/
public static byte[] serializeObject(Object o)
{
/* we try to make the buffer large enough to avoid deadlock */
ByteArrayOutputStream byte_out = new ByteArrayOutputStream(1024) ;
ObjectOutputStream obj_out ;
try
{
obj_out = new ObjectOutputStream(byte_out) ;
obj_out.writeObject(o) ;
}
catch (IOException e)
{
throw new RuntimeException(e) ;
}
return byte_out.toByteArray() ;
} // end public static byte[] serializeObject(Object o)
/**
* Converts a byte stream created by serializeObject() to an object. Its
* real type can be determined using the instanceof operator.
*
* @see serializeObject()
* @return the object represented by the byte array
*/
public static Object deserializeObject(byte[] b)
{
ByteArrayInputStream bis = new ByteArrayInputStream(b) ;
ObjectInputStream ois ;
Object o ;
try
{
ois = new ObjectInputStream(bis) ;
o = ois.readObject() ;
}
catch (Exception e)
{
throw new RuntimeException("Error deserializing object") ;
}
return o ;
} // end public static Object deserializeObject(byte[] b)
} // end class
===============================================================================
END GCJBug.java
===============================================================================
--
Summary: InetAddress objects do not serialize/deserialize
Product: classpath
Version: unspecified
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: classpath
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Josh at allDucky dot com
GCC build triplet: i386-redhat-linux
GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25313
- [Bug classpath/25313] New: InetAddress objects do not serialize/deserialize,
Josh at allDucky dot com <=