Class path: an ordered list of JAR files, zip files, and directories, each of which contains Java class files. A class loader transforms the fully package qualified name of a Java class into a file name and then searches for a class file with that name in a class path.
When more than one entry in a class path contains a class file with the same name, the class loader returns the file in the first path entry. Other class files with the same name are unavailable.
If a class loader fails to find any instance of a class, it asks its parent class loader to find the class. In a running VM there are usually multiple class loaders, each with its own class path, but for our purposes we can treat this as a single class path formed by appending parent class paths to child class paths.
Linkage error: an abnormal condition of a classpath in which a
“class has some dependency on another class; however, the
latter class has incompatibly changed after the compilation of the
former class.”1 The dependency can be
through a class literal, a field access, or a method invocation.
Linkage errors encountered at runtime manifest as a subclass of
LinkageError
such as NoSuchMethodError
, NoClassDefFoundError
,
NoSuchFieldError
, or similar errors.
For example, the name, return type, modifiers, or arguments of a non-private method, field, or class in a dependency has changed in an incompatible way between the version of a class file supplied at compile time and the version available in the runtime class path. A public method may have been removed from a class or an extended class may have been made final.
In cases where binary compatibility and source compatibility are the same, a linkage error is when compilation would fail if the libraries in the class path were all built together from their originating source code.
ImmutableList
to List
would be a linkage
conflict if the calling code references anything in ImmutableList
that is
absent from List
(for example, ImmutableList.reverse()
).
Class reference graph: a possibly cyclic directed graph where each node represents a class and each edge represents a method, field, or class reference from the source class to the target class.
For example, when ‘Class A’ invokes method X on ‘Class B’, the class reference graph holds an edge between the two nodes:
[Class A] --(method X of class B)-> [Class B]
In this case, ‘Class A’ is called the source class of the reference and ‘Class B’ is called the target class.
In general, there can be multiple edges between two nodes when a class references two or more members of another class. Self-loops, references from a class to a member of the same class, are possible and common.
1: Linkage Error (Java SE Platform 8)