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
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,36 @@ WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers i
WARNING: Restricted methods will be blocked in a future release unless native access is enabled
```

To remove these warnings, you need to either allow these methods through the command line arguments:
To remove these warnings, you need to allow native access for the module that calls the restricted methods.

### Unnamed modules (classpath)

If you are running jdave on the classpath (no `module-info.java`), use:

```shell
java --enable-native-access=ALL-UNNAMED ...
```

Or enabling them in your JAR-file manifest:
Or in your JAR-file manifest:

```shell
```
Enable-Native-Access: ALL-UNNAMED
```

### Named modules (module path)

If your application uses JPMS modules, specify the jdave module name instead:

```shell
java --enable-native-access=club.minnced.discord.jdave ...
```

Or in your JAR-file manifest:

```
Enable-Native-Access: club.minnced.discord.jdave
```

## Why Java 25?

This library uses the [Foreign Function & Memory (FFM) API](https://docs.oracle.com/en/java/javase/22/core/foreign-function-and-memory-api.html) which has been stabilized in Java 22.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static short getMaxSupportedProtocolVersion() {
}
}

@SuppressWarnings("restricted")
public static void setLogSinkCallback(@NonNull Arena arena, @NonNull LogSinkCallback logSinkCallback) {
LogSinkCallbackMapper upcallMapper = new LogSinkCallbackMapper(logSinkCallback);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import java.lang.invoke.MethodHandle;
import org.jspecify.annotations.NonNull;

@SuppressWarnings("restricted")
public class LibDaveDecryptorBinding {
private LibDaveDecryptorBinding() {}

static final MethodHandle daveDecryptorCreate;
static final MethodHandle daveDecryptorDestroy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import java.lang.invoke.MethodHandle;
import org.jspecify.annotations.NonNull;

@SuppressWarnings("restricted")
public class LibDaveEncryptorBinding {
private LibDaveEncryptorBinding() {}

static final MethodHandle daveEncryptorCreate;
static final MethodHandle daveEncryptorDestroy;
static final MethodHandle daveEncryptorSetKeyRatchet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.jspecify.annotations.NonNull;

public class LibDaveKeyRatchetBinding {
private LibDaveKeyRatchetBinding() {}

private static final MethodHandle destroyKeyRatchet;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import java.lang.foreign.SymbolLookup;
import java.lang.invoke.MethodHandle;

@SuppressWarnings("restricted")
public class LibDaveLookup {
private LibDaveLookup() {}

static final Linker LINKER = Linker.nativeLinker();
static final SymbolLookup SYMBOL_LOOKUP;
public static final MemoryLayout C_SIZE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import java.util.List;
import org.jspecify.annotations.NonNull;

@SuppressWarnings("restricted")
public class LibDaveSessionBinding {
private LibDaveSessionBinding() {}

static final MethodHandle daveSessionCreate;
static final MethodHandle daveSessionDestroy;
static final MethodHandle daveSessionInit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import org.jspecify.annotations.Nullable;

public class NativeUtils {
private NativeUtils() {}

@NonNull
@SuppressWarnings("restricted")
public static String asJavaString(@NonNull MemorySegment nullTerminatedString) {
return nullTerminatedString.reinterpret(1024 * 64).getString(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.jspecify.annotations.NonNull;

public class JDaveSessionFactory implements DaveSessionFactory {
public JDaveSessionFactory() {}

@NonNull
@Override
public DaveSession createDaveSession(@NonNull DaveProtocolCallbacks callbacks, long userId, long channelId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.slf4j.event.Level;

public class DaveLogger {
private DaveLogger() {}

@SuppressWarnings("LoggerInitializedWithForeignClass")
public static final Logger log = LoggerFactory.getLogger(LibDave.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.slf4j.LoggerFactory;

public class NativeLibraryLoader {
private NativeLibraryLoader() {}

public static final String LIBRARY_PATH_PROPERTY = "jdave.library.path";

private static final Logger log = LoggerFactory.getLogger(NativeLibraryLoader.class);
Expand All @@ -41,7 +43,8 @@ public static NativeLibrary getNativeLibrary() {
public static Path createTemporaryFile() {
NativeLibrary nativeLibrary = getNativeLibrary();

try (InputStream library = NativeLibraryLoader.class.getResourceAsStream(nativeLibrary.resourcePath())) {
String resourceName = nativeLibrary.resourcePath().substring(1); // strip leading /
try (InputStream library = NativeLibraryLoader.class.getResourceAsStream(resourceName)) {
if (library == null) {
throw new LibDaveBindingException(
"Could not find resource for current platform. Looked for " + nativeLibrary.resourcePath());
Expand All @@ -63,6 +66,7 @@ public static Path createTemporaryFile() {
}
}

@SuppressWarnings("restricted")
@NonNull
public static SymbolLookup getSymbolLookup() {
String customLibraryPath = getLibraryPath();
Expand Down Expand Up @@ -92,6 +96,7 @@ public static NativeLibrary resolveLibrary(
return new NativeLibrary(os, arch, baseName);
}

@SuppressWarnings("restricted")
@NonNull
private static SymbolLookup getSymbolLookupFromPath(@NonNull String customLibraryPath) {
Path path = Path.of(customLibraryPath).toAbsolutePath();
Expand Down
11 changes: 11 additions & 0 deletions api/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module club.minnced.discord.jdave {
requires static transitive net.dv8tion.jda;
requires static org.jspecify;
requires org.slf4j;

exports club.minnced.discord.jdave;
exports club.minnced.discord.jdave.ffi;
exports club.minnced.discord.jdave.interop;
exports club.minnced.discord.jdave.manager;
exports club.minnced.discord.jdave.utils;
}
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ subprojects {
}

configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}

withJavadocJar()
withSourcesJar()
}

tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release = 25

options.compilerArgs.addAll(listOf("-Xlint:all", "-Xlint:-options", "-Xlint:-restricted"))
options.compilerArgs.addAll(listOf("-Xlint:all", "-Xlint:-options", "-Xlint:-exports", "-Xlint:-requires-transitive-automatic", "-Xlint:-requires-automatic"))
}
}