-
Bug
-
Resolution: Fixed
-
P3
-
9, 10, 11, 12, 13
-
b24
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8225981 | 14 | Chris Hegarty | P3 | Resolved | Fixed | team |
JDK-8252667 | 11.0.10-oracle | Kiran Sidhartha Ravikumar | P3 | Resolved | Fixed | b01 |
JDK-8251144 | 11.0.9 | Aleksey Shipilev | P3 | Resolved | Fixed | b03 |
Spec says: "Return the JAR entry object for this connection, if any. This method returns null if the JAR file URL corresponding to this connection points to a JAR file and not a JAR file entry."
However getJarEntry() throws NullPointerException instead of returning null in below scenario:
public static void main(String[] args) throws Exception {
//please change below url accordingly
URL url = new URL("jar:file:/D:/sample.jar!/");
JarURLConnection jarURLConnection = new CustomJarURLConnection(url);
/**
* Spec says:
*
* Return the JAR entry object for this connection, if any. This
* method returns null if the JAR file URL corresponding to this
* connection points to a JAR file and not a JAR file entry.
*
* As "url" points to a JAR file and not a JAR file entry, hence getJarEntry() must return null.
* However it throws null pointer exception.
*
**/
JarEntry jarEntry = jarURLConnection.getJarEntry();
System.out.println("This should be printed, however above line throws NullPointerException");
}
static class CustomJarURLConnection extends JarURLConnection {
private URL pJarFileURL;
protected CustomJarURLConnection(URL url) throws MalformedURLException {
super(url);
pJarFileURL = url;
}
@Override
public JarFile getJarFile() throws IOException {
return ((JarURLConnection)pJarFileURL.openConnection()).getJarFile();
}
@Override
public void connect() throws IOException {}
}
}
However getJarEntry() throws NullPointerException instead of returning null in below scenario:
public static void main(String[] args) throws Exception {
//please change below url accordingly
URL url = new URL("jar:file:/D:/sample.jar!/");
JarURLConnection jarURLConnection = new CustomJarURLConnection(url);
/**
* Spec says:
*
* Return the JAR entry object for this connection, if any. This
* method returns null if the JAR file URL corresponding to this
* connection points to a JAR file and not a JAR file entry.
*
* As "url" points to a JAR file and not a JAR file entry, hence getJarEntry() must return null.
* However it throws null pointer exception.
*
**/
JarEntry jarEntry = jarURLConnection.getJarEntry();
System.out.println("This should be printed, however above line throws NullPointerException");
}
static class CustomJarURLConnection extends JarURLConnection {
private URL pJarFileURL;
protected CustomJarURLConnection(URL url) throws MalformedURLException {
super(url);
pJarFileURL = url;
}
@Override
public JarFile getJarFile() throws IOException {
return ((JarURLConnection)pJarFileURL.openConnection()).getJarFile();
}
@Override
public void connect() throws IOException {}
}
}
- backported by
-
JDK-8225981 java.net.JarURLConnection::getJarEntry() throws NullPointerException
- Resolved
-
JDK-8251144 java.net.JarURLConnection::getJarEntry() throws NullPointerException
- Resolved
-
JDK-8252667 java.net.JarURLConnection::getJarEntry() throws NullPointerException
- Resolved