Top Description Inners Fields Constructors Methods
jdk.internal.module

public final Class ModulePatcher

extends Object
Class Inheritance
Imports
java.io.Closeable, .File, .IOError, .IOException, .InputStream, .UncheckedIOException, java.lang.module.ModuleDescriptor, .ModuleDescriptor.Builder, .ModuleReader, .ModuleReference, java.net.MalformedURLException, .URI, .URL, java.nio.ByteBuffer, java.nio.file.Files, .Path, .Paths, java.util.ArrayList, .HashMap, .HashSet, .List, .Map, .Optional, .Set, java.util.jar.JarEntry, .JarFile, java.util.stream.Stream, jdk.internal.loader.Resource, jdk.internal.access.JavaLangModuleAccess, .SharedSecrets, sun.net.www.ParseUtil

Provides support for patching modules, mostly the boot layer.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ModulePatcher.ExplodedResourceFinder

A ResourceFinder that finds resources on the file system.

private static class
ModulePatcher.JarResourceFinder

A ResourceFinder that finds resources in a JAR file.

public static class
ModulePatcher.PatchedModuleReader

A ModuleReader that reads resources from a patched module.

private static interface
ModulePatcher.ResourceFinder

A resource finder that find resources in a patch location.

Field Summary

Modifier and TypeField and Description
private static final JavaLangModuleAccess
private final Map<String, List<Path>>

Constructor Summary

AccessConstructor and Description
public
ModulePatcher(Map<String, List<String>> input)

Initialize the module patcher with the given map.

Method Summary

Modifier and TypeMethod and Description
public boolean
hasPatches()

Returns true is this module patcher has patches.

private boolean
isHidden(Path file)

Returns true if the given file exists and is a hidden file

pack-priv Set<String>
public ModuleReference
patchIfNeeded(ModuleReference mref)

Returns a module reference that interposes on the given module if needed.

private static String
toPackageName(Path top, Path file)

Derives a package name from the file path of an entry in an exploded patch

private static String
toPackageName(Path file, JarEntry entry)

Derives a package name from the name of an entry in a JAR file.

private static String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

JLMAback to summary
private static final JavaLangModuleAccess JLMA
mapback to summary
private final Map<String, List<Path>> map

Constructor Detail

ModulePatcherback to summary
public ModulePatcher(Map<String, List<String>> input)

Initialize the module patcher with the given map. The map key is the module name, the value is a list of path strings.

Method Detail

hasPatchesback to summary
public boolean hasPatches()

Returns true is this module patcher has patches.

isHiddenback to summary
private boolean isHidden(Path file)

Returns true if the given file exists and is a hidden file

patchedModulesback to summary
pack-priv Set<String> patchedModules()
patchIfNeededback to summary
public ModuleReference patchIfNeeded(ModuleReference mref)

Returns a module reference that interposes on the given module if needed. If there are no patches for the given module then the module reference is simply returned. Otherwise the patches for the module are scanned (to find any new packages) and a new module reference is returned.

Exceptions
UncheckedIOException:
if an I/O error is detected
toPackageNameback to summary
private static String toPackageName(Path top, Path file)

Derives a package name from the file path of an entry in an exploded patch

toPackageNameback to summary
private static String toPackageName(Path file, JarEntry entry)

Derives a package name from the name of an entry in a JAR file.

warnIfModuleInfoback to summary
private static String warnIfModuleInfo(Path file, String e)
jdk.internal.module back to summary

private Class ModulePatcher.ExplodedResourceFinder

extends Object
implements ResourceFinder
Class Inheritance
All Implemented Interfaces
jdk.internal.module.ModulePatcher.ResourceFinder, java.io.Closeable, java.lang.AutoCloseable

A ResourceFinder that finds resources on the file system.

Field Summary

Modifier and TypeField and Description
private final Path

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public Resource
public Stream<String>
private Resource
newResource(String name, Path top, Path file)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dirback to summary
private final Path dir

Constructor Detail

ExplodedResourceFinderback to summary
pack-priv ExplodedResourceFinder(Path dir)

Method Detail

closeback to summary
public void close()

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
findback to summary
public Resource find(String name) throws IOException

Implements jdk.internal.module.ModulePatcher.ResourceFinder.find.

Annotations
@Override
listback to summary
public Stream<String> list() throws IOException

Implements jdk.internal.module.ModulePatcher.ResourceFinder.list.

Annotations
@Override
newResourceback to summary
private Resource newResource(String name, Path top, Path file)
jdk.internal.module back to summary

private Class ModulePatcher.JarResourceFinder

extends Object
implements ResourceFinder
Class Inheritance
All Implemented Interfaces
jdk.internal.module.ModulePatcher.ResourceFinder, java.io.Closeable, java.lang.AutoCloseable

A ResourceFinder that finds resources in a JAR file.

Field Summary

Modifier and TypeField and Description
private final URL
private final JarFile

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public Resource
public Stream<String>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

csURLback to summary
private final URL csURL
jfback to summary
private final JarFile jf

Constructor Detail

JarResourceFinderback to summary
pack-priv JarResourceFinder(Path path) throws IOException

Method Detail

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
findback to summary
public Resource find(String name) throws IOException

Implements jdk.internal.module.ModulePatcher.ResourceFinder.find.

Annotations
@Override
listback to summary
public Stream<String> list() throws IOException

Implements jdk.internal.module.ModulePatcher.ResourceFinder.list.

Annotations
@Override
jdk.internal.module back to summary

public Class ModulePatcher.PatchedModuleReader

extends Object
implements ModuleReader
Class Inheritance
All Implemented Interfaces
java.lang.module.ModuleReader, java.io.Closeable, java.lang.AutoCloseable

A ModuleReader that reads resources from a patched module. This class is public so as to expose the findResource method to the built-in class loaders and avoid locating the resource twice during class loading (once to locate the resource, the second to gets the URL for the CodeSource).

Field Summary

Modifier and TypeField and Description
private volatile ModuleReader
private final URL
private final List<ModulePatcher.ResourceFinder>
private final ModuleReference

Constructor Summary

AccessConstructor and Description
pack-priv
PatchedModuleReader(List<Path> patches, ModuleReference mref)

Creates the ModuleReader to reads resources in a patched module.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.lang.module.ModuleReader.close.

Closes the module reader.

private static void
closeAll(List<ModulePatcher.ResourceFinder> finders)

Closes all resource finders.

private static URL
codeSourceURL(ModuleReference mref)

Returns the code source URL for the given module.

private ModuleReader
delegate()

Returns the ModuleReader to delegate to when the resource is not found in a patch location.

public Optional<URI>
find(String
The name of the resource to open for reading
name
)

Implements java.lang.module.ModuleReader.find.

Finds a resource, returning a URI to the resource in the module.

public Resource
findResource(String name)

Finds a resource of the given name in the patched module.

private Resource
findResourceInPatch(String name)

Finds a resources in the patch locations.

public Stream<String>
list()

Implements java.lang.module.ModuleReader.list.

Lists the contents of the module, returning a stream of elements that are the names of all resources in the module.

public Optional<InputStream>
open(String
The name of the resource to open for reading
name
)

Overrides default java.lang.module.ModuleReader.open.

Opens a resource, returning an input stream to read the resource in the module.

public Optional<ByteBuffer>
read(String
The name of the resource to read
name
)

Overrides default java.lang.module.ModuleReader.read.

Reads a resource, returning a byte buffer with the contents of the resource.

public void
release(ByteBuffer
The byte buffer to release
bb
)

Overrides default java.lang.module.ModuleReader.release.

Releases a byte buffer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegateback to summary
private volatile ModuleReader delegate
delegateCodeSourceURLback to summary
private final URL delegateCodeSourceURL
findersback to summary
private final List<ModulePatcher.ResourceFinder> finders
mrefback to summary
private final ModuleReference mref

Constructor Detail

PatchedModuleReaderback to summary
pack-priv PatchedModuleReader(List<Path> patches, ModuleReference mref)

Creates the ModuleReader to reads resources in a patched module.

Method Detail

closeback to summary
public void close() throws IOException

Implements java.lang.module.ModuleReader.close.

Doc from java.lang.module.ModuleReader.close.

Closes the module reader. Once closed then subsequent calls to locate or read a resource will fail by throwing IOException.

A module reader is not required to be asynchronously closeable. If a thread is reading a resource and another thread invokes the close method, then the second thread may block until the read operation is complete.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Closeable.close.

if an I/O error occurs

closeAllback to summary
private static void closeAll(List<ModulePatcher.ResourceFinder> finders)

Closes all resource finders.

codeSourceURLback to summary
private static URL codeSourceURL(ModuleReference mref)

Returns the code source URL for the given module.

delegateback to summary
private ModuleReader delegate() throws IOException

Returns the ModuleReader to delegate to when the resource is not found in a patch location.

findback to summary
public Optional<URI> find(String name) throws IOException

Implements java.lang.module.ModuleReader.find.

Doc from java.lang.module.ModuleReader.find.

Finds a resource, returning a URI to the resource in the module.

If the module reader can determine that the name locates a directory then the resulting URI will end with a slash ('/').

Parameters
name:String

The name of the resource to open for reading

Returns:Optional<URI>

A URI to the resource; an empty Optional if the resource is not found or a URI cannot be constructed to locate the resource

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs or the module reader is closed
findResourceback to summary
public Resource findResource(String name) throws IOException

Finds a resource of the given name in the patched module.

findResourceInPatchback to summary
private Resource findResourceInPatch(String name) throws IOException

Finds a resources in the patch locations. Returns null if not found or the name is "module-info.class" as that cannot be overridden.

listback to summary
public Stream<String> list() throws IOException

Implements java.lang.module.ModuleReader.list.

Doc from java.lang.module.ModuleReader.list.

Lists the contents of the module, returning a stream of elements that are the names of all resources in the module. Whether the stream of elements includes names corresponding to directories in the module is module reader specific.

In lazy implementations then an IOException may be thrown when using the stream to list the module contents. If this occurs then the IOException will be wrapped in an java.io.UncheckedIOException and thrown from the method that caused the access to be attempted. SecurityException may also be thrown when using the stream to list the module contents and access is denied by the security manager.

The returned stream may contain references to one or more open directories in the module. The directories are closed by closing the stream.

The behavior of the stream when used after the module reader is closed is implementation specific and therefore not specified.

Returns:Stream<String>

A stream of elements that are the names of all resources in the module

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs or the module reader is closed
openback to summary
public Optional<InputStream> open(String name) throws IOException

Overrides default java.lang.module.ModuleReader.open.

Doc from java.lang.module.ModuleReader.open.

Opens a resource, returning an input stream to read the resource in the module.

The behavior of the input stream when used after the module reader is closed is implementation specific and therefore not specified.

Parameters
name:String

The name of the resource to open for reading

Returns:Optional<InputStream>

An input stream to read the resource or an empty Optional if not found

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs or the module reader is closed
readback to summary
public Optional<ByteBuffer> read(String name) throws IOException

Overrides default java.lang.module.ModuleReader.read.

Doc from java.lang.module.ModuleReader.read.

Reads a resource, returning a byte buffer with the contents of the resource. The element at the returned buffer's position is the first byte of the resource, the element at the buffer's limit is the last byte of the resource. Once consumed, the release method must be invoked. Failure to invoke the release method may result in a resource leak.

Parameters
name:String

The name of the resource to read

Returns:Optional<ByteBuffer>

A byte buffer containing the contents of the resource or an empty Optional if not found

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs or the module reader is closed
releaseback to summary
public void release(ByteBuffer bb)

Overrides default java.lang.module.ModuleReader.release.

Doc from java.lang.module.ModuleReader.release.

Releases a byte buffer. This method should be invoked after consuming the contents of the buffer returned by the read method. The behavior of this method when invoked to release a buffer that has already been released, or the behavior when invoked to release a buffer after a ModuleReader is closed is implementation specific and therefore not specified.

Parameters
bb:ByteBuffer

The byte buffer to release

Annotations
@Override
jdk.internal.module back to summary

private Interface ModulePatcher.ResourceFinder

extends Closeable
Known Direct Implementers
jdk.internal.module.ModulePatcher.JarResourceFinder, jdk.internal.module.ModulePatcher.ExplodedResourceFinder

A resource finder that find resources in a patch location.

Method Summary

Modifier and TypeMethod and Description
public Resource
find(String name)

public Stream<String>
list()

Inherited from java.io.Closeable:
close

Method Detail

findback to summary
public Resource find(String name) throws IOException
listback to summary
public Stream<String> list() throws IOException