Shadowing in the Java Module System

Overview

Shadowing in the Java Module System refers to a situation where a class is loaded from the first JAR file on the class path that contains it, rendering all other classes with the same name from other JARs unavailable. This behavior can lead to subtle misbehavior or errors, as the order in which JARs are searched determines which class is ultimately used.

Example of Shadowing

Shadowing typically occurs when different JARs on the class path contain classes with the same fully qualified name. A common scenario is when multiple versions of the same library are present in the class path. In such cases, the class from the first JAR on the class path shadows the classes from other JARs. This can lead to potential misbehavior, as the application may not use the intended version of the class, resulting in unexpected behavior or errors.