-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
Description
Describe the issue
URLConnection.getContentType() returns null content type for html resource. Running the same sample with JDK returns text/html content type.
The result is the same for building a native image from a class file or from a jar file:
URLConnectionSample.java code:
import java.net.URL;
import java.net.URLConnection;
public class URLConnectionSample {
public static void main(String[] args) throws Exception {
String path = "/index.html";
URL url = URLConnectionSample.class.getResource(path);
URLConnection connection = url.openConnection();
String type = connection.getContentType();
System.out.printf("connection: %s%n", connection);
System.out.printf("connection type: %s%n", type);
}
}
// java + class
> java URLConnectionSample
connection: sun.net.www.protocol.file.FileURLConnection:file:/home/samples/url/index.html
connection type: text/html
// native image + class
> native-image -H:IncludeResources=\\Qindex.html\\E URLConnectionSample
./urlconnectionsample
connection: com.oracle.svm.core.jdk.resources.ResourceURLConnection:resource:/index.html
connection type: null
// java + jar
> jar cf url-connection-sample.jar URLConnectionSample.class index.html
> java -cp url-connection-sample.jar URLConnectionSample
connection: sun.net.www.protocol.jar.JarURLConnection:jar:file:/home/samples/url/url-connection-sample.jar!/index.html
connection type: text/html
// native image + jar
> native-image -cp url-connection-sample.jar -H:IncludeResources=\\Qindex.html\\E URLConnectionSample
/urlconnectionsample
connection: com.oracle.svm.core.jdk.resources.ResourceURLConnection:resource:/index.html
connection type: null
Steps to reproduce the issue
- Create
index.htmlresource file:
<html>
<ul>
<li>List Item One</li>
<li>List Item Two</li>
</ul>
</html>
- Create and compile the URLConnectionSample.java
javac URLConnectionSample.java
import java.net.URL;
import java.net.URLConnection;
public class URLConnectionSample {
public static void main(String[] args) throws Exception {
String path = "/index.html";
URL url = URLConnectionSample.class.getResource(path);
URLConnection connection = url.openConnection();
String type = connection.getContentType();
System.out.printf("connection: %s%n", connection);
System.out.printf("connection type: %s%n", type);
}
}
- Run the
URLConnectionSamplewith java:
java URLConnectionSample
connection: sun.net.www.protocol.file.FileURLConnection:file:/home/samples/url/index.html
connection type: text/html
The connection type is text/html
-
Create the native image providing
index.htmlas a resourse:
native-image -H:IncludeResources=\\Qindex.html\\E URLConnectionSample -
Run the native image:
./urlconnectionsample
connection: com.oracle.svm.core.jdk.resources.ResourceURLConnection:resource:/index.html
connection type: null
The connection type is null
Describe GraalVM and your environment:
- GraalVM version: the latest snapshot
graalvm-community-java17-linux-amd64-dev.tar.gzfrom GraalVM CE 23.1.0-dev-20230408_0311 - JDK: openjdk version "17.0.7" 2023-04-18
- OS: Ubuntu 20.04.2 LTS
- Architecture: x86_64