Hello Eirik,

The code in URLJarFile which does that check for "~" seems to have been introduced for https://bugs.openjdk.org/browse/JDK-4447921. It doesn't tell why the "~" was necessary.

In any case, I don't think any kind of clean up or introducing tests for "~" is worth it, given it's not clear what that usage signifies.

-Jaikiran

On 26/03/25 3:43 pm, Eirik Bjørsnøs wrote:
Hi,

Various URL scheme code paths contain branches for local or non-local file URLs:

See URLJarFile::isFileURL for an example where the host is compared as follows:

    String host = url.getHost();
    if (host == null || host.isEmpty() || host.equals("~") ||
    host.equalsIgnoreCase("localhost"))
        return true;


Equivalent checks are found in unix and windows Handler::openConnection.

In JarFileFactory::urlFor however, the logic is slightly different in that the comparison with ~ (tilde) is missing:

    String host = url.getHost();
    if (host != null && !host.isEmpty() &&
    !host.equalsIgnoreCase("localhost")) {

I have tried to find an RFC or any other mention of "~" in host names, but found nothing. Can anyone shine light on the meaning and interpretation of this character as a host name?

In any case, I think if we could add the tilde logic to JarFileFactory::urlFor, then all these four checks would be equivalent and a prime candidate for a consolidating cleanup PR, perhaps also expanding a bit on the documentation for the consolidated method(s).

My take is that the missing test was a simple oversight, that adding it should not be harmful and that this would enable a nice consolidation of this particular logic. .

Thoughts?

Eirik.






Reply via email to