-
Bug
-
Resolution: Fixed
-
P4
-
8, 11, 16, 18
-
b12
-
generic
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8303164 | 17.0.7 | Paul Hohensee | P4 | Resolved | Fixed | b04 |
ADDITIONAL SYSTEM INFORMATION :
Fedora 33 Linux 5.13.9-100.fc33.x86_64
openjdk version "16.0.2" 2021-07-20
A DESCRIPTION OF THE PROBLEM :
Given an absolute URI: 'http://example.com' (note no trailing '/')
and a relative path: 'test'
intuitively one would expect resolving to result in 'http://example.com/test'
This is how Python behaves, for example.
However, doing so in Java leads to a surprising result: 'http://example.comtest'
Seemingly the relative path ends up in the authority!
Under the hood, it turns out that 'test' is correctly set as the path, but there is never a '/' character introduced to separate the authority from the path.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The attached test case shows the issue.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
http://example.com/test
ACTUAL -
http://example.comtest
---------- BEGIN SOURCE ----------
import java.net.URI;
class UriResolve {
public static void main(String[] args) {
var base = URI.create("http://example.com");
var rel = URI.create("test");
System.out.format("base a: %s p: %s u: %s%n", base.getAuthority(), base.getPath(), base);
System.out.format("rel a: %s p: %s u: %s%n", rel.getAuthority(), rel.getPath(), rel);
var res = base.resolve(rel);
System.out.format("res a: %s p: %s u: %s%n", res.getAuthority(), res.getPath(), res);
}
}
---------- END SOURCE ----------
FREQUENCY : always
Fedora 33 Linux 5.13.9-100.fc33.x86_64
openjdk version "16.0.2" 2021-07-20
A DESCRIPTION OF THE PROBLEM :
Given an absolute URI: 'http://example.com' (note no trailing '/')
and a relative path: 'test'
intuitively one would expect resolving to result in 'http://example.com/test'
This is how Python behaves, for example.
However, doing so in Java leads to a surprising result: 'http://example.comtest'
Seemingly the relative path ends up in the authority!
Under the hood, it turns out that 'test' is correctly set as the path, but there is never a '/' character introduced to separate the authority from the path.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The attached test case shows the issue.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
http://example.com/test
ACTUAL -
http://example.comtest
---------- BEGIN SOURCE ----------
import java.net.URI;
class UriResolve {
public static void main(String[] args) {
var base = URI.create("http://example.com");
var rel = URI.create("test");
System.out.format("base a: %s p: %s u: %s%n", base.getAuthority(), base.getPath(), base);
System.out.format("rel a: %s p: %s u: %s%n", rel.getAuthority(), rel.getPath(), rel);
var res = base.resolve(rel);
System.out.format("res a: %s p: %s u: %s%n", res.getAuthority(), res.getPath(), res);
}
}
---------- END SOURCE ----------
FREQUENCY : always
- backported by
-
JDK-8303164 Resolving URI relative path with no / may lead to incorrect toString
-
- Resolved
-
- duplicates
-
JDK-4666701 URI.resolve wrong when base path empty and given URI relative
-
- Closed
-
-
JDK-8214448 URI::resolve broken if the base URI has an empty path
-
- Closed
-
-
JDK-8233764 Invalid URI aftter calling resolve()
-
- Closed
-
- relates to
-
JDK-6523089 java.net.URI.relativize(java.net.URI) mishandles non-slash-terminated base URI
-
- Open
-
(3 links to)