Skip to content

Commit 8c58ecb

Browse files
dfa1claude
andcommitted
feat: add a JPMS module descriptor (io.github.dfa1.zstd)
- module-info.java exports the single public package. Lets modular consumers `requires io.github.dfa1.zstd` and scope native access with `--enable-native-access=io.github.dfa1.zstd` instead of ALL-UNNAMED. - Suppress the module-name lint: the `dfa1` component ends in a digit (flagged as possibly version-like), but it mirrors the verified io.github.dfa1 namespace and the package, so keep it. - NativeLibrary now loads the bundled library through the class loader (no leading slash) rather than Class#getResourceAsStream: the library lives in a separate zstd-native-<classifier> module and a named module only finds resources in itself. The classifier directory has a dash, so it is not a package and the resource is not module-encapsulated — the class loader reads it across modules and on the classpath alike. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 0c74b4c commit 8c58ecb

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

zstd/src/main/java/io/github/dfa1/zstd/NativeLibrary.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ static MethodHandle lookup(String name, FunctionDescriptor fd) {
4141
private static String extractBundledLib() {
4242
String classifier = classifier();
4343
String ext = libExtension(classifier);
44-
String resource = "/native/" + classifier + "/libzstd." + ext;
44+
// Load through the class loader (no leading slash), not Class#getResourceAsStream:
45+
// the library lives in a separate zstd-native-<classifier> module, and a named
46+
// module only finds resources in itself. The classifier directory name contains a
47+
// dash, so it is not a valid package and the resource is not module-encapsulated —
48+
// the class loader can read it across modules (and on the classpath alike).
49+
String resource = "native/" + classifier + "/libzstd." + ext;
4550

46-
try (InputStream in = NativeLibrary.class.getResourceAsStream(resource)) {
51+
try (InputStream in = NativeLibrary.class.getClassLoader().getResourceAsStream(resource)) {
4752
if (in == null) {
4853
throw new UnsatisfiedLinkError("No bundled zstd library found for platform " + classifier);
4954
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// Java Foreign Function & Memory (FFM) bindings for Zstandard.
2+
///
3+
/// Exports the single public API package; the native `libzstd` is loaded at
4+
/// runtime from the platform `zstd-native-<classifier>` artifact on the path.
5+
/// Requires `--enable-native-access=io.github.dfa1.zstd` (or `ALL-UNNAMED` on
6+
/// the classpath) since FFM downcalls are a restricted operation.
7+
// The "dfa1" component ends in a digit, which the module-name lint flags as
8+
// possibly version-like. It mirrors the Sonatype-verified io.github.dfa1
9+
// namespace and the package name, so suppress the advisory rather than diverge.
10+
@SuppressWarnings("module")
11+
module io.github.dfa1.zstd {
12+
exports io.github.dfa1.zstd;
13+
}

0 commit comments

Comments
 (0)