From 1ae8893a4029925160548ccdb6756d3821d2b5cb Mon Sep 17 00:00:00 2001 From: Sebb Date: Thu, 30 Nov 2023 11:46:47 +0000 Subject: [PATCH] Revert replacement of "/" by File.separator Resources use "/" on all systems --- .../java/org/apache/commons/crypto/NativeCodeLoader.java | 9 ++++++--- src/main/java/org/apache/commons/crypto/OsInfo.java | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java index 9bb9c0d45..32ea92538 100644 --- a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java +++ b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java @@ -37,6 +37,9 @@ */ final class NativeCodeLoader { + /** The separator to be used in constructing a resource path */ + private static final String RESOURCE_PATH_SEPARATOR = "/"; + private static final String SIMPLE_NAME = NativeCodeLoader.class.getSimpleName(); private static final String NATIVE_LIBNAME = "commons-crypto"; @@ -82,7 +85,7 @@ private static void debug(final String format, final Object... args) { */ private static File extractLibraryFile(final String libFolderForCurrentOS, final String libraryFileName, final String targetFolder) { - final String nativeLibraryFilePath = libFolderForCurrentOS + File.separator + libraryFileName; + final String nativeLibraryFilePath = libFolderForCurrentOS + RESOURCE_PATH_SEPARATOR + libraryFileName; // Attach UUID to the native library file to ensure multiple class loaders // can read the libcommons-crypto multiple times. @@ -171,12 +174,12 @@ private static File findNativeLibrary() { // Load an OS-dependent native library inside a jar file nativeLibraryPath = "/org/apache/commons/crypto/native/" + OsInfo.getNativeLibFolderPathForCurrentOS(); debug("%s nativeLibraryPath = %s", SIMPLE_NAME, nativeLibraryPath); - final String resource = nativeLibraryPath + File.separator + nativeLibraryName; + final String resource = nativeLibraryPath + RESOURCE_PATH_SEPARATOR + nativeLibraryName; boolean hasNativeLib = hasResource(resource); debug("%s resource %s exists = %s", SIMPLE_NAME, resource, hasNativeLib); if (!hasNativeLib) { final String altName = NATIVE_LIBNAME_ALT; - if (OsInfo.getOSName().equals("Mac") && hasResource(nativeLibraryPath + File.separator + altName)) { + if (OsInfo.getOSName().equals("Mac") && hasResource(nativeLibraryPath + RESOURCE_PATH_SEPARATOR + altName)) { // Fix for openjdk7 for Mac nativeLibraryName = altName; hasNativeLib = true; diff --git a/src/main/java/org/apache/commons/crypto/OsInfo.java b/src/main/java/org/apache/commons/crypto/OsInfo.java index a3dc80936..3fcd31901 100644 --- a/src/main/java/org/apache/commons/crypto/OsInfo.java +++ b/src/main/java/org/apache/commons/crypto/OsInfo.java @@ -17,7 +17,6 @@ */ package org.apache.commons.crypto; -import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Locale; @@ -28,6 +27,9 @@ */ final class OsInfo { + /** The separator to be used in constructing a resource path */ + private static final String RESOURCE_PATH_SEPARATOR = "/"; + private final static HashMap archMapping = new HashMap<>(); /** @@ -140,7 +142,7 @@ static String getArchName() { * @return the current OS's native lib folder. */ static String getNativeLibFolderPathForCurrentOS() { - return getOSName() + File.separator + getArchName(); + return getOSName() + RESOURCE_PATH_SEPARATOR + getArchName(); } /**