A DESCRIPTION OF THE PROBLEM :
This is more or less a follow up toJDK-8151244 which was resolved as "Not an issue". However, it is, and it also causes to break a documented guaranty: the documentation to URI states: "For any URI u, it is always the case that [...] n all cases,
new URI(u.getScheme(),
u.getUserInfo(), u.getAuthority(),
u.getPath(), u.getQuery(),
u.getFragment())
.equals(u)".
Neglecting the fact, that this particular constructor does not exist, the following code fails (using the EUR sign as mentioned in the documentation):
URI uri=new URI("https://www.example.com/get%E2%82%AC.html");
URI newURI=new URI(uri.getScheme(),
uri.getAuthority(),
uri.getPath(), uri.getQuery(),
uri.getFragment());
assertEquals(uri, newURI);
If you try to recreate (parts of) the original URI this way, it will be broken afterwards.
---------- BEGIN SOURCE ----------
import static org.junit.Assert.assertEquals;
import java.net.URI;
import java.net.URISyntaxException;
public class Test {
@Test
public void testURI() throws URISyntaxException {
URI uri=new URI("https://www.example.com/get%E2%82%AC.html");
URI newURI=new URI(uri.getScheme(),
uri.getAuthority(),
uri.getPath(), uri.getQuery(),
uri.getFragment());
assertEquals(uri, newURI);
}
}
---------- END SOURCE ----------
FREQUENCY : always
This is more or less a follow up to
new URI(u.getScheme(),
u.getUserInfo(), u.getAuthority(),
u.getPath(), u.getQuery(),
u.getFragment())
.equals(u)".
Neglecting the fact, that this particular constructor does not exist, the following code fails (using the EUR sign as mentioned in the documentation):
URI uri=new URI("https://www.example.com/get%E2%82%AC.html");
URI newURI=new URI(uri.getScheme(),
uri.getAuthority(),
uri.getPath(), uri.getQuery(),
uri.getFragment());
assertEquals(uri, newURI);
If you try to recreate (parts of) the original URI this way, it will be broken afterwards.
---------- BEGIN SOURCE ----------
import static org.junit.Assert.assertEquals;
import java.net.URI;
import java.net.URISyntaxException;
public class Test {
@Test
public void testURI() throws URISyntaxException {
URI uri=new URI("https://www.example.com/get%E2%82%AC.html");
URI newURI=new URI(uri.getScheme(),
uri.getAuthority(),
uri.getPath(), uri.getQuery(),
uri.getFragment());
assertEquals(uri, newURI);
}
}
---------- END SOURCE ----------
FREQUENCY : always
- relates to
-
JDK-8151244 URI Constructor Doesn't Encode Path Correctly
-
- Closed
-