Name: rmT116609 Date: 06/17/2004
FULL PRODUCT VERSION :
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
The equals(Object) method on URI correctly compares "percent" escape sequences in a case-insensitive fashion, so the following URIs are equal:
http://example.com/%5bsegment%5d
http://example.com/%5Bsegment%5D
compareTo(Object) however, reports that these two URIs are different. Looking at the documentation, it is noteable that the compareTo docs omit the crucial phrase:
"...and the hexadecimal digits of escaped octets are compared without regard to case."
present in the docs for equals(Object). However, the docs also say:
" This method satisfies the general contract of the Comparable.compareTo method."
which is somewhat disingenuous considering that the abovementioned contract says:
'It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals." '
There is no such indication of violation in the URI docs. Furthermore, it seems perverse that URI should behave in this way, since this makes it impossible to use URIs reliably in structures like TreeMaps.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the supplied test code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
uri1.equals(uri2): 'true'.
uri1.compareTo(uri2): '0'.
ACTUAL -
uri1.equals(uri2): 'true'.
uri1.compareTo(uri2): '32'.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.net.URI;
public class Test {
public static void main(String[] args) {
try{
URI uri1 = new URI("http://example.com/%5bsegment%5d");
URI uri2 = new URI("http://example.com/%5Bsegment%5D");
System.err.println("uri1.equals(uri2): '" + uri1.equals(uri2) + "'.");
System.err.println("uri1.compareTo(uri2): '" + uri1.compareTo(uri2) + "'.");
}
catch(Exception e){
e.printStackTrace();
}
}
}
---------- END SOURCE ----------
(Incident Review ID: 280020)
======================================================================
- csr for
-
JDK-8233857 URI compareTo inconsistent with equals for mixed-case escape sequences
-
- Closed
-