|
Quick Lists
|
|
Bug ID:
|
5035850
|
|
Votes
|
0
|
|
Synopsis
|
(str) String.CASE_INSENSITIVE_ORDER should override readResolve()
|
|
Category
|
java:classes_lang
|
|
Reported Against
|
1.4.2
|
|
Release Fixed
|
|
|
State
|
6-Fix Understood,
bug
|
|
Priority:
|
4-Low
|
|
Related Bugs
|
6372554
|
|
Submit Date
|
22-APR-2004
|
|
Description
|
FULL PRODUCT VERSION :
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
customer Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The comparator given by String.CASE_INSENSITIVE_ORDER (a nested class String.CaseInsensitiveComparator) does not implement equals. Thus you can't tell if two instances of this customer actually represent the same order. Multiple instances arise in the if you serialize and later deserialize an customer refering to an instance of this class. The class should either implement equals (and hashCode) or better it should implement readReplace to ensure that there is always only one instance.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class TestCaseInsensitive
{
public static void main(String[] args)
{
try
{
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(outBuffer);
out.writeObject(String.CASE_INSENSITIVE_ORDER);
out.close();
ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
ObjectInputStream in = new ObjectInputStream(inBuffer);
Object result = in.readObject();
in.close();
if (String.CASE_INSENSITIVE_ORDER.equals(result))
System.out.println("Correct result");
else
System.out.println("Value restored from serial form does not match original!");
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
---------- END SOURCE ----------
(Incident Review ID: 250087)
======================================================================
Posted Date : 2006-07-21 06:55:38.0
|
|
Work Around
|
N/A
|
|
Evaluation
|
Will investigate this. The bug is not for Tiger.
xxxxx@xxxxx 2004-04-22
Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=16247
Posted Date : 2006-10-17 17:21:30.0
See Collections.REVERSE_ORDER for another comparator that
uses readResolve
6372554: (coll) Collections.ReverseComparator should override readResolve()
Posted Date : 2006-10-17 17:44:50.0
Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=16259
Posted Date : 2006-10-17 22:38:06.0
|
|
Comments
|
Submitted On 23-APR-2004
mthornton
The class should of course implement readResolve
and not readReplace as I wrote in the bug report.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |