diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml
index 5f2b34a..e83fb4f 100644
--- a/.github/workflows/build-and-release.yml
+++ b/.github/workflows/build-and-release.yml
@@ -144,7 +144,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
- java-version: '17'
+ java-version: '21'
cache: 'maven'
- name: Build with Maven
diff --git a/README.md b/README.md
index 6860ba0..3136220 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,7 @@ Support the project with XDAG donations:
### **1. Requirements**
-- **JDK**: v17 or later
+- **JDK**: v21 or later
- **Maven**: v3.9.9 or later
- **CMake**: v3.5 or later
- **GCC/Compiler**: GCC v4.8 or later (v7+ recommended for best performance)
@@ -115,7 +115,7 @@ To include `xdagj-native-randomx` in your project, add the following dependency
io.xdagxdagj-native-randomx
- 0.2.3
+ 0.2.4
```
diff --git a/pom.xml b/pom.xml
index e7908c7..87f4ab3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
io.xdagxdagj-native-randomx
- 0.2.3
+ 0.2.4xdagj-native-randomxA Java RandomX Library For XDAGJ
@@ -17,8 +17,8 @@
UTF-8UTF-8
- 17
- 17
+ 21
+ 213.17.0
@@ -81,6 +81,14 @@
${maven.compiler.source}${maven.compiler.target}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+
+
+
@@ -91,6 +99,7 @@
truetrue
+ --enable-preview
@@ -151,6 +160,9 @@
org.apache.maven.pluginsmaven-javadoc-plugin${maven-javadoc-plugin.version}
+
+ ${maven.compiler.source}
+ attach-javadocs
diff --git a/src/main/java/io/xdag/crypto/randomx/Example.java b/src/main/java/io/xdag/crypto/randomx/Example.java
index 7dfda1b..1354b32 100644
--- a/src/main/java/io/xdag/crypto/randomx/Example.java
+++ b/src/main/java/io/xdag/crypto/randomx/Example.java
@@ -33,6 +33,15 @@
*/
public class Example {
+ /**
+ * Default constructor for the Example class.
+ * This constructor is intentionally empty as this class primarily serves as a demonstration
+ * with static methods or through its main method.
+ */
+ public Example() {
+ // Default constructor
+ }
+
/**
* Main method demonstrating the RandomX hashing process.
* Shows initialization of RandomX components and hash calculation.
diff --git a/src/main/java/io/xdag/crypto/randomx/RandomXFlag.java b/src/main/java/io/xdag/crypto/randomx/RandomXFlag.java
index 8802e55..ff58507 100644
--- a/src/main/java/io/xdag/crypto/randomx/RandomXFlag.java
+++ b/src/main/java/io/xdag/crypto/randomx/RandomXFlag.java
@@ -117,7 +117,7 @@ public enum RandomXFlag {
* Each bit in the input value corresponds to a specific flag.
*
* @param flags The combined integer value of multiple flags
- * @return A set of RandomXFlag enums corresponding to the enabled bits
+ * @return A set of RandomXFlag enums corresponding to the enabled bits.
*/
public static Set fromValue(int flags) {
EnumSet result = EnumSet.noneOf(RandomXFlag.class);
diff --git a/src/main/java/io/xdag/crypto/randomx/RandomXLibraryLoader.java b/src/main/java/io/xdag/crypto/randomx/RandomXLibraryLoader.java
index 5c051d9..1f31152 100644
--- a/src/main/java/io/xdag/crypto/randomx/RandomXLibraryLoader.java
+++ b/src/main/java/io/xdag/crypto/randomx/RandomXLibraryLoader.java
@@ -40,7 +40,7 @@
final class RandomXLibraryLoader {
private static boolean isLoaded = false;
- private static String loadedLibraryPath = null; // Store the path of the loaded library for logging
+ private static Path loadedLibraryPath = null; // Store the path of the loaded library
// Private constructor to prevent instantiation
private RandomXLibraryLoader() {}
@@ -53,16 +53,19 @@ private RandomXLibraryLoader() {}
*
* @throws UnsatisfiedLinkError if the library cannot be loaded for any reason.
* @throws Exception for other unexpected errors during loading.
+ * @return Path to the loaded native library file, or null if already loaded or failed before critical point.
*/
- public static synchronized void load() throws Exception {
+ public static synchronized Path load() throws Exception {
if (isLoaded) {
log.info("Native library already loaded from: {}", loadedLibraryPath);
- return;
+ return loadedLibraryPath; // Return cached path
}
+ Path tempLibFilePath = null;
try {
- File tempFile = extractAndLoadNativeLibrary();
- loadedLibraryPath = tempFile.getAbsolutePath();
+ File tempFile = extractAndLoadNativeLibrary(); // This method now returns File
+ tempLibFilePath = tempFile.toPath();
+ loadedLibraryPath = tempLibFilePath; // Cache the path
String tempLibDir = tempFile.getParent();
if (tempLibDir != null) {
@@ -79,10 +82,12 @@ public static synchronized void load() throws Exception {
isLoaded = true;
log.info("RandomX native library loaded successfully via RandomXLibraryLoader from: {}", loadedLibraryPath);
+ return loadedLibraryPath;
} catch (UnsatisfiedLinkError ule) { // Catch specifically from System.load()
log.error("Failed to load native library (UnsatisfiedLinkError from System.load()): {}: {}",
- (loadedLibraryPath != null ? loadedLibraryPath : ""), ule.getMessage(), ule);
+ (loadedLibraryPath != null ? loadedLibraryPath : (tempLibFilePath != null ? tempLibFilePath : "")),
+ ule.getMessage(), ule);
logLibraryPaths(); // Log paths for diagnostics
throw ule; // Re-throw to be handled by RandomXNative's static block
} catch (Exception e) {
diff --git a/src/main/java/io/xdag/crypto/randomx/RandomXNative.java b/src/main/java/io/xdag/crypto/randomx/RandomXNative.java
index 0596f19..09912f5 100644
--- a/src/main/java/io/xdag/crypto/randomx/RandomXNative.java
+++ b/src/main/java/io/xdag/crypto/randomx/RandomXNative.java
@@ -33,6 +33,14 @@
* This class registers the native methods after the library is successfully loaded.
*/
public class RandomXNative {
+ /**
+ * Private constructor to prevent instantiation.
+ * This class provides static JNA mappings and should not be instantiated.
+ */
+ private RandomXNative() {
+ throw new UnsupportedOperationException("This is a JNA mapping class and cannot be instantiated");
+ }
+
static {
try {
// Step 1: Initialize the library using the loader.
diff --git a/src/main/java/io/xdag/crypto/randomx/RandomXTemplate.java b/src/main/java/io/xdag/crypto/randomx/RandomXTemplate.java
index 509b8ab..6a77aae 100644
--- a/src/main/java/io/xdag/crypto/randomx/RandomXTemplate.java
+++ b/src/main/java/io/xdag/crypto/randomx/RandomXTemplate.java
@@ -38,6 +38,19 @@
@ToString
@Slf4j
public class RandomXTemplate implements AutoCloseable {
+ /**
+ * Private constructor to be used by the Lombok generated builder.
+ * Direct instantiation is discouraged; use the builder pattern.
+ */
+ private RandomXTemplate(boolean miningMode, Set flags, RandomXCache cache, RandomXDataset dataset, RandomXVM vm, byte[] currentKey) {
+ this.miningMode = miningMode;
+ this.flags = flags;
+ this.cache = cache;
+ this.dataset = dataset;
+ this.vm = vm;
+ this.currentKey = currentKey;
+ }
+
/** Flag indicating if the template is in mining mode */
@Getter
private final boolean miningMode;
diff --git a/src/main/java/io/xdag/crypto/randomx/RandomXUtils.java b/src/main/java/io/xdag/crypto/randomx/RandomXUtils.java
index 8298ff7..3e488db 100644
--- a/src/main/java/io/xdag/crypto/randomx/RandomXUtils.java
+++ b/src/main/java/io/xdag/crypto/randomx/RandomXUtils.java
@@ -33,6 +33,13 @@
*/
public final class RandomXUtils {
+ /**
+ * Private constructor to prevent instantiation of this utility class.
+ */
+ private RandomXUtils() {
+ throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
+ }
+
/**
* The size of a RandomX hash in bytes (usually 32 bytes).
*/