Skip to content

Commit aae6cbf

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 657e5c1 commit aae6cbf

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
@@ -42,9 +42,14 @@ static MethodHandle lookup(String name, FunctionDescriptor fd) {
4242
private static String extractBundledLib() {
4343
String classifier = classifier();
4444
String ext = libExtension(classifier);
45-
String resource = "/native/" + classifier + "/libzstd." + ext;
45+
// Load through the class loader (no leading slash), not Class#getResourceAsStream:
46+
// the library lives in a separate zstd-native-<classifier> module, and a named
47+
// module only finds resources in itself. The classifier directory name contains a
48+
// dash, so it is not a valid package and the resource is not module-encapsulated —
49+
// the class loader can read it across modules (and on the classpath alike).
50+
String resource = "native/" + classifier + "/libzstd." + ext;
4651

47-
try (InputStream in = NativeLibrary.class.getResourceAsStream(resource)) {
52+
try (InputStream in = NativeLibrary.class.getClassLoader().getResourceAsStream(resource)) {
4853
if (in == null) {
4954
throw new UnsatisfiedLinkError("No bundled zstd library found for platform " + classifier);
5055
}
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)