A Java binary file references other classes and interfaces and their fields, methods, and constructors symbolically, using the fully-qualified names of the other classes and interfaces (§13.1). For fields and methods, these symbolic references include the name of the class or interface type that declares the field or method as well as the name of the field or method itself, together with appropriate type information.
Before a symbolic reference can be used it must be undergo resolution, wherein a symbolic reference is checked to be correct and, typically, replaced with a direct reference that can be more efficiently processed if the reference is used repeatedly.
If an error occurs during resolution, then an error will be thrown. Most typically, this will be an instance of one of the following subclasses of the class IncompatibleClassChangeError
, but it may also be an instance of some other subclass of IncompatibleClassChangeError
or even an instance of the class IncompatibleClassChangeError
itself. This error may be thrown at any point in the program that uses a symbolic reference to the type, directly or indirectly:
IllegalAccessError
: A symbolic reference has been encountered that specifies a use or assignment of a field, or invocation of a method, or creation of an instance of a class, to which the code containing the reference does not have access because the field or method was declared private
, protected
, or default access (not public
), or because the class was not declared public
. This can occur, for example, if a field that is originally declared public
is changed to be private
after another class that refers to the field has been compiled (§13.4.6).
InstantiationError
: A symbolic reference has been encountered that is used in a class instance creation expression, but an instance cannot be created because the reference turns out to refer to an interface or to an abstract
class. This can occur, for example, if a class that is originally not abstract
is changed to be abstract
after another class that refers to the class in question has been compiled (§13.4.1).
NoSuchFieldError
: A symbolic reference has been encountered that refers to a specific field of a specific class or interface, but the class or interface does not declare a field of that name (it is specifically not sufficient for it simply to be an inherited field of that class or interface). This can occur, for example, if a field declaration was deleted from a class after another class that refers to the field was compiled (§13.4.7).
NoSuchMethodError
: A symbolic reference has been encountered that refers to a specific method of a specific class or interface, but the class or interface does not declare a method of that signature (it is specifically not sufficient for it simply to be an inherited method of that class or interface). This can occur, for example, if a method declaration was deleted from a class after another class that refers to the method was compiled (§13.4.12).
Additionally, an UnsatisfiedLinkError
(a subclass of LinkageError
) may be thrown if a class declares a native
method for which no implementation can be found. The error will occur if the method is used, or earlier depending on what kind of resolution strategy is being used by the virtual machine (§12.3).