Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2034132 | 1.4.0 | Alan Bateman | P3 | Resolved | Fixed | beta |
Name: skT45625 Date: 05/12/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
Problem:
Transient fields of URL are not correctly restored during readObject.
Create a URL
Serialize it
Read serialized version back.
getPath returns null.
Source code:-------------------------------------------------------------------
package urlbug;
import java.net.*;
import java.io.*;
public class Test
{
public static void main( String[] argsest ) throws Exception
{
URL originalUrl = new URL( "file:/t:/line1.jpg" );
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( out );
oos.writeObject( originalUrl );
oos.close();
ByteArrayInputStream in = new ByteArrayInputStream(
out.toByteArray() );
ObjectInputStream ois = new ObjectInputStream( in );
URL restoredUrl = (URL)ois.readObject();
ois.close();
System.out.println( originalUrl.getPath() );
System.out.println( restoredUrl.getPath() );
}
}
(Review ID: 104795)
======================================================================
Name: skT45625 Date: 08/07/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
Deserialized file URL's return a null value for getPath (). Not sure if other
values are incorrect. Running the attached code produces incorrect output:
initial URL getPath () = /tmp/dir1/dir2/dummy.txt
serialized URL getPath () = null
-------------------------------------------------------------
import java.io.*;
import java.net.*;
public class UrlBug
{
public static void main (String [] args)
{
try
{
// create a bogus file URL and serialize it
URL url = new URL ("file:///tmp/dir1/dir2/dummy.txt");
FileOutputStream fileOutStream = new FileOutputStream ("url.ser");
ObjectOutputStream objectOutStream = new ObjectOutputStream
(fileOutStream);
objectOutStream.writeObject (url);
objectOutStream.close ();
fileOutStream.close ();
// deserialize URL from file and store in url2
FileInputStream fileInStream = new FileInputStream ("url.ser");
ObjectInputStream objectInStream = new ObjectInputStream (fileInStream);
URL url2 = (URL)objectInStream.readObject ();
objectInStream.close ();
fileInStream.close ();
// print the before and after values of getPath ()
System.out.println ("initial URL getPath () = " + url.getPath ());
System.out.println ("serialized URL getPath () = " + url2.getPath ());
} catch (FileNotFoundException ex)
{
ex.printStackTrace ();
} catch (IOException ex)
{
ex.printStackTrace ();
} catch (ClassNotFoundException ex)
{
ex.printStackTrace ();
}
}
}
(Review ID: 108052)
======================================================================
- backported by
-
JDK-2034132 readObject in java.net.URL fails to restore transient fields
-
- Resolved
-