Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions zstd/src/main/java/io/github/dfa1/zstd/NativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ static MethodHandle lookup(String name, FunctionDescriptor fd) {
private static String extractBundledLib() {
String classifier = classifier();
String ext = libExtension(classifier);
String resource = "/native/" + classifier + "/libzstd." + ext;
// Load through the class loader (no leading slash), not Class#getResourceAsStream:
// the library lives in a separate zstd-native-<classifier> module, and a named
// module only finds resources in itself. The classifier directory name contains a
// dash, so it is not a valid package and the resource is not module-encapsulated —
// the class loader can read it across modules (and on the classpath alike).
String resource = "native/" + classifier + "/libzstd." + ext;

try (InputStream in = NativeLibrary.class.getResourceAsStream(resource)) {
try (InputStream in = NativeLibrary.class.getClassLoader().getResourceAsStream(resource)) {
if (in == null) {
throw new UnsatisfiedLinkError("No bundled zstd library found for platform " + classifier);
}
Expand Down
13 changes: 13 additions & 0 deletions zstd/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// Java Foreign Function & Memory (FFM) bindings for Zstandard.
///
/// Exports the single public API package; the native `libzstd` is loaded at
/// runtime from the platform `zstd-native-<classifier>` artifact on the path.
/// Requires `--enable-native-access=io.github.dfa1.zstd` (or `ALL-UNNAMED` on
/// the classpath) since FFM downcalls are a restricted operation.
// The "dfa1" component ends in a digit, which the module-name lint flags as
// possibly version-like. It mirrors the Sonatype-verified io.github.dfa1
// namespace and the package name, so suppress the advisory rather than diverge.
@SuppressWarnings("module")
module io.github.dfa1.zstd {
exports io.github.dfa1.zstd;
}
Loading