ADDITIONAL SYSTEM INFORMATION :
System:
Linux ceres 4.19.0-18-amd64 #1 SMP Debian 4.19.208-1 (2021-09-29) x86_64 GNU/Linux
Java:
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12)
OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (build 17.0.1+12, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
Class.getResource and Class.getResourceAsStream will fail if the argument contains a supplementary codepoint (that is, a codepoint whose Unicode value is greater than 0xfff and which is represented in a String as a high and low surrogate pair).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a file (or .jar entry) whose name includes a supplementary codepoint in the same package as a class, and pass that name to Class.getResource or Class.getResourceAsStream.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When the resource exists, the getResource and getResourceAsStream methods should succeed without throwing any exceptions and should returned a non-null value.
ACTUAL -
Exception in thread "main" java.lang.IllegalArgumentException: Error decoding percent encoded characters
at java.base/sun.net.www.ParseUtil.decode(ParseUtil.java:218)
at java.base/sun.net.www.protocol.file.Handler.openConnection(Handler.java:80)
at java.base/sun.net.www.protocol.file.Handler.openConnection(Handler.java:72)
at java.base/java.net.URL.openConnection(URL.java:1094)
at ResourceUrlWithSupplementary.main(ResourceUrlWithSupplementary.java:7)
---------- BEGIN SOURCE ----------
import java.io.IOException;
public class ResourceUrlWithSupplementary {
public static void main(String[] args)
throws IOException {
ResourceUrlWithSupplementary.class.getResource("\uD83D\uDC31").openConnection();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Create a resource URL for the class itself, then use the resource name containing the supplementary character as a relative URL in the two-argument constructor of URL:
URL url = ResourceUrlWithSupplementary.class.getResource(
ResourceUrlWithSupplementary.class.getSimpleName() + ".class");
url = new URL(url, "\uD83D\uDC31");
url.openConnection();
FREQUENCY : always