Class JrtfsCodeBase

java.lang.Object
edu.umd.cs.findbugs.classfile.impl.AbstractScannableCodeBase
edu.umd.cs.findbugs.classfile.impl.JrtfsCodeBase
All Implemented Interfaces:
ICodeBase, IScannableCodeBase, AutoCloseable

public final class JrtfsCodeBase extends AbstractScannableCodeBase
Code base supporting Java 9 new jimage packed modules
  • Field Details

    • PRIME

      private static final int PRIME
      See Also:
    • fs

      private FileSystem fs
    • fileName

      private final String fileName
    • root

      private Path root
    • packageToModuleMap

      private Map<String,Object> packageToModuleMap
      Key is package name in bytecode notation (e.g. 'java/lang').

      Values are either plain Strings for single-module packages, or sets of Strings for packages spread over multiple modules

  • Constructor Details

  • Method Details

    • openJrtFileSystem

      private static FileSystem openJrtFileSystem(String jrtFsJar) throws IOException
      Opens the module image of the JDK the given jrt-fs.jar belongs to, which is not necessarily the JDK running SpotBugs.

      Selecting a foreign image requires the java.home environment entry used by jdk.internal.jrtfs.JrtFileSystemProvider. Without it, the jrt provider installed in the running JVM answers the request with the running JVM's own image.

      Passing a class loader over the given jrt-fs.jar does not help: since Java 9, java.base installs a provider for the jrt scheme, and FileSystems.newFileSystem(URI, Map, ClassLoader) falls back to the loader only when no installed provider matches the scheme.

      Parameters:
      jrtFsJar - path of a jrt-fs.jar, usually <javaHome>/lib/jrt-fs.jar
      Returns:
      file system for the module image of that JDK, or of the running JVM if the jar is not in the layout expected by the provider
      Throws:
      IOException
    • javaHomeOf

      private static @Nullable Path javaHomeOf(String jrtFsJar)
      Maps <javaHome>/lib/jrt-fs.jar back to <javaHome>.
      Returns:
      the JDK home owning the given jar, or null if the jar is not in the layout expected by the jrt file system provider
    • createPackageToModuleMap

      public Map<String,Object> createPackageToModuleMap(FileSystem fs) throws IOException
      Throws:
      IOException
    • lookupResource

      public @Nullable ICodeBaseEntry lookupResource(String resourceName)
      Description copied from interface: ICodeBase
      Look up a resource in this code base.
      Parameters:
      resourceName - name of the resource to look up
      Returns:
      ICodeBaseEntry representing the resource or null if the resource cannot be found in this code base
    • createEntry

      private @Nullable ICodeBaseEntry createEntry(String resourceName, String moduleName)
    • getPackage

      private static String getPackage(String resourceName)
    • getPathName

      public String getPathName()
      Description copied from interface: ICodeBase
      Get the filesystem pathname of this codebase.
      Returns:
      the filesystem pathname of this codebase, or null if this codebase is not accessible via the filesystem
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • close

      public void close()
      Description copied from interface: ICodeBase
      This method should be called when done using the code base.
    • iterator

      public ICodeBaseIterator iterator() throws InterruptedException
      Description copied from interface: IScannableCodeBase
      Get an iterator over the resources in the this code base.
      Returns:
      ICodeBaseIterator over the resources in the code base
      Throws:
      InterruptedException
    • fileName

      static @NonNull String fileName(Path p)
    • isClassFile

      static boolean isClassFile(Path p)