Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
A Uniform Resource Locator (URL) specifies both the location of a resource and also a method to access it.  According to the Java API documentation for Class URL \[SD:[API 2006|AA. Bibliography#API 06]\] regarding the {{equals()}} method for {{java.net.URL}} objects:

Two URL objects are equal if they have the same protocol, reference equivalent hosts, have the same port number on the host, and the same file and fragment of the file.

Two hosts are considered equivalent if both host names can be resolved into the same IP addresses; else if either host name can't be resolved, the host names must be equal without regard to case; or both host names equal to null. Note:

The defined behavior for the equals() method is known to be inconsistent with virtual hosting in HTTP.

The concept of virtual Virtual hosting allows a web server to host multiple websites on the same computer, sometimes sharing the same IP address. Unfortunately, this technique was unanticipated when the URL class was designed. Consequently, when two completely different URLs resolve to the same IP address, the URL class considers them to be equal.

Another risk associated with the equals() method for URL objects is that the logic it uses when connected to the Internet differs from that used when disconnected. When connected to the Internet, the equals() method follows the steps described in the Java API; when disconnected, it performs a string compare on the two URLs. ConsquentlyConsequently, the URL.equals() method violates the consistency requirement for equals().

...

This solution still has problems. Two URLs with different string representation can still easily point refer to the same resource. However, the solution works well fails safe in this case because the equals() contract is preserved, and the system will never allow a malicious URL to be accepted by mistake.

...

Wiki Markup
A Uniform Resource Identifier (URI) contains a string of characters used to identify a resource; this is a more general concept than aan URL. The {{java.net.URI}} class provides string-based {{equals()}} and {{hashCode()}} methods that satisfy the general contracts for {{Object.equals()}} and {{Object.hashCode()}}; they do not invoke hostname resolution and are unaffected by network connectivity.  {{URI}} also provides methods for normalization and canonicalization that {{URL}} lacks. Finally, the {{URL.toURI()}} and {{URI.toURL()}} methods provide easy conversion between the two classes. It is recommended to use URIs instead of URLs whenever possible. According to the Java API \[[API 2006|AA. Bibliography#API 06]\], {{URI}} class documentation

...