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

Classloader.getResource("") find resource when MR JAR on class path

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      OS assumed unimportant but was macOS Monterey 12.6.1
      Openjdk version "11.0.17" 2022-10-18 LTS

      A DESCRIPTION OF THE PROBLEM :
      The behaviour of getResource differs between J8 and J11 (most likely later JREs) when the classpath contains a multi-release jar.

      With J8 or with J11 and no multi release jar.

      Calling ClassLoader.getResource("") will return null as would be expected.

      With J11 and a multi release jar on the classpath

      Calling ClassLoader.getResource("") will return a non-null but invalid resource, equivalent to the multi-release folder for the version of Java running. E.g. e.g. some.jar!/META-INF/versions/11/

      REGRESSION : Last worked in version 8u351

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Using a multi release jar on java 11 make a call to a Classloader instance to the method getResource with the empty string

      classLoader.getResource("");

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      If the behaviour matched Java 8, or without a multi-release jar, then we would expect null should be returned.
      ACTUAL -
      On Java 11with a mutli-release jar an invalid resource will be returned.

      This resource matches the directory for the multi-release jar classes that match the Java version

      e.g. some.jar!/META-INF/versions/11/

      ---------- BEGIN SOURCE ----------
      See attached zip file.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Refrain from fetching empty strings.

      FREQUENCY : always


            bchristi Brent Christian
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: