JDK-8152276 : Clarify behaviour when a Jar Index is found to be invalid
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 9
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2016-03-21
  • Updated: 2017-05-17
  • Resolved: 2016-04-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b116Fixed
Related Reports
Relates :  
Description
In the context of JDK-8152190 it was noticed that [sun.misc.]InvalidJarIndexException
is mentioned in the Jar File Specification [1], but it is an internal type. There is only one
static code reference to InvalidJarIndexException in the JDK source, and that is in the
URLClassPath implementation, where it creates a new instance of the exception to be
thrown.

The Jar Spec says:
   "Once the class loader finds a INDEX.LIST file in a particular jar file, it always trusts
    the information listed in it. If a mapping is found for a particular class, but the class
    loader fails to find it by following the link, an InvalidJarIndexException is thrown.
    When this occurs, the application developer should rerun the jar tool on the
    extension to get the right information into the index file."

InvalidJarIndexException is thrown when an index is corrupt. For example: a.jar
contains an index which has an entry for the package foo.bar in b.jar, but b.jar does
not contain foo/bar.  The InvalidJarIndexException is a useful piece of information that
the deployment of the jar files is "bad".  Arguably, this is really an Error. It indicates a
serious problem with the deployment that a reasonable application should not try to
handle.

Note: is it possible for class or resource loading to fail with other unchecked exceptions,
such as InternalError. 

InvalidJarIndexException should be reviewed. Possibly: 1) either move it up to
java.util.jar as part of the Java SE Specification, or 2) alternatively drop it from the Jar
File Specification, or something else.

This appears to be a long standing spec issue from when support for Jar Indexing was
originally added.

[1] http://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Overview
Comments
Suggestion: 1) Update the Jar File Specification as follows: "If a mapping is found for a particular class, but the class loader fails to find it by following the link, ** an unspecified Error or RuntimeException ** is thrown." 2) Update the implementation to throw an Error. No user code should every catch or try to handle this Error.
25-03-2016

InvalidJarIndexException can be seen from user code. Here is one example, from an attempt to load a class, 'new B()', from a class in one jar file, that has an index and for the class' package: sun.misc.InvalidJarIndexException: Invalid index at sun.misc.URLClassPath$JarLoader.getResource(java.base@9-internal/URLClassPath.java:933) at sun.misc.URLClassPath$JarLoader.getResource(java.base@9-internal/URLClassPath.java:843) at sun.misc.URLClassPath.getResource(java.base@9-internal/URLClassPath.java:217) at jdk.internal.loader.BuiltinClassLoader$3.run(java.base@9-internal/BuiltinClassLoader.java:465) at jdk.internal.loader.BuiltinClassLoader$3.run(java.base@9-internal/BuiltinClassLoader.java:462) at java.security.AccessController.doPrivileged(java.base@9-internal/Native Method) at jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(java.base@9-internal/BuiltinClassLoader.java:461) at jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(java.base@9-internal/BuiltinClassLoader.java:408) at jdk.internal.loader.BuiltinClassLoader.loadClass(java.base@9-internal/BuiltinClassLoader.java:366) at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.base@9-internal/ClassLoaders.java:185) at java.lang.ClassLoader.loadClass(java.base@9-internal/ClassLoader.java:419) at Basic.main(Basic.java:16) Note: this sun.misc.InvalidJarIndexException is Serializable. Is this a supported interface? Can anyone really rely on it?
24-03-2016