JDK-8168647 : A URLClassLoader supplied with a jar: URL does not respect Class-Path headers
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 8
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2016-10-07
  • Updated: 2017-10-26
Description
FULL PRODUCT VERSION :
LANELSON-mac:~ LANELSON$ java -version
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)
LANELSON-mac:~ LANELSON$ 


ADDITIONAL OS VERSION INFORMATION :
LANELSON-mac:test LANELSON$ uname -a
Darwin LANELSON-mac 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64


A DESCRIPTION OF THE PROBLEM :
If you supply a URLClassLoader with only one URL like this:

  jar:file:/some/file.jar!/

...and file.jar is located in a directory with extra.jar, and file.jar's META-INF/MANIFEST.MF resource has a Class-Path header like so:

  Class-Path: extra.jar

...the URLClassLoader will be unable to load classes found in extra.jar--that is, it does not respect file.jar's META-INF/MANIFEST.MF's Class-Path header.

However, if you supply the URLClassLoader with an equivalent URL like this:

  file:/some/file.jar

...while leaving everything else unchanged, the Class-Path header is processed correctly and the URLClassLoader can load classes found in extra.jar.

See http://stackoverflow.com/questions/39906038/does-urlclassloader-traverse-manifest-mf-class-path-headers-properly for a unit test.


REPRODUCIBILITY :
This bug can be reproduced always.


Comments
To reproduce the issue, modify the file path in JI9044356.java and execute the test case with assertions enabled. The issue could be reproduced only on JDK 8u versions: JDK 8u112 - Fail JDK 8u122ea - Fail JDK 9ea+ 137 - Pass Following is the output on JDK 8u versions: >java -ea JI9044356 Exception in thread "main" java.lang.ClassNotFoundException: com.foobar.Jimbo at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at JI9044356.wheresWaldo2(JI9044356.java:46) at JI9044356.main(JI9044356.java:11) Output on JDk 9ea +137: >java -showversion -ea JI9044356 java version "9-ea" Java(TM) SE Runtime Environment (build 9-ea+137) Java HotSpot(TM) 64-Bit Server VM (build 9-ea+137, mixed mode) com.foobar.Jimbo
2016-10-25