-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8, 11, 17, 24, 25
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
There is a logical error in the URL.equals() method when comparing two URL instances that have null hosts but different port numbers. According to the documentation of java.net.URL class, two URL objects should be considered equal only when they meet multiple conditions, including having "the same port number on the host". However, when two URL objects both have null.
---------- BEGIN SOURCE ----------
import java.net.URL;
public class Main {
public static void main(String[] args) throws Exception {
URL urlNullHost1 = new URL("http", null, 80, "/Test");
URL urlNullHost2= new URL("http", null, 8080, "/Test");
if (urlNullHost1.equals(urlNullHost2)) {
throw new RuntimeException("Null hosts with different ports should not be equal");
}
}
}
---------- END SOURCE ----------
There is a logical error in the URL.equals() method when comparing two URL instances that have null hosts but different port numbers. According to the documentation of java.net.URL class, two URL objects should be considered equal only when they meet multiple conditions, including having "the same port number on the host". However, when two URL objects both have null.
---------- BEGIN SOURCE ----------
import java.net.URL;
public class Main {
public static void main(String[] args) throws Exception {
URL urlNullHost1 = new URL("http", null, 80, "/Test");
URL urlNullHost2= new URL("http", null, 8080, "/Test");
if (urlNullHost1.equals(urlNullHost2)) {
throw new RuntimeException("Null hosts with different ports should not be equal");
}
}
}
---------- END SOURCE ----------