Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8225037

java.net.JarURLConnection::getJarEntry() throws NullPointerException

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9, 10, 11, 12, 13
    • Fix Version/s: 13
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b24

      Backports

        Description

        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 {}
            }
        }

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  chegar Chris Hegarty
                  Reporter:
                  dsingh Durgesh Singh (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: