Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force String.toLowerCase() to use Locale.ENGLISH #40

Merged
merged 2 commits into from
Jul 12, 2021
Merged
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
11 changes: 6 additions & 5 deletions src/main/java/org/scijava/nativelib/NativeLibraryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -107,7 +108,7 @@ public static Architecture getArchitecture() {
if (Architecture.UNKNOWN == architecture) {
final Processor processor = getProcessor();
if (Processor.UNKNOWN != processor) {
final String name = System.getProperty("os.name").toLowerCase();
final String name = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
if (name.contains("nix") || name.contains("nux")) {
if (Processor.INTEL_32 == processor) {
architecture = Architecture.LINUX_32;
Expand Down Expand Up @@ -155,7 +156,7 @@ else if (Processor.PPC == processor) {
}
}
LOGGER.debug("architecture is " + architecture + " os.name is " +
System.getProperty("os.name").toLowerCase());
System.getProperty("os.name").toLowerCase(Locale.ENGLISH));
return architecture;
}

Expand All @@ -169,7 +170,7 @@ private static Processor getProcessor() {
int bits;

// Note that this is actually the architecture of the installed JVM.
final String arch = System.getProperty("os.arch").toLowerCase();
final String arch = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);

if (arch.contains("arm")) {
processor = Processor.ARM;
Expand All @@ -192,7 +193,7 @@ else if (arch.contains("86") || arch.contains("amd")) {
processor = (32 == bits) ? Processor.INTEL_32 : Processor.INTEL_64;
}
LOGGER.debug("processor is " + processor + " os.arch is " +
System.getProperty("os.arch").toLowerCase());
System.getProperty("os.arch").toLowerCase(Locale.ENGLISH));
return processor;
}

Expand All @@ -207,7 +208,7 @@ else if (arch.contains("86") || arch.contains("amd")) {
*/
public static String getPlatformLibraryPath(String searchPath) {
if (archStr == null)
archStr = NativeLibraryUtil.getArchitecture().name().toLowerCase();
archStr = NativeLibraryUtil.getArchitecture().name().toLowerCase(Locale.ENGLISH);

// foolproof
String fullSearchPath = (searchPath.equals("") || searchPath.endsWith(DELIM) ?
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/org/scijava/nativelib/NativeLoaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Locale;
import java.util.jar.*;

import org.junit.Rule;
Expand All @@ -62,7 +63,7 @@ private void createJar() throws Exception {

// with a dummy binary in it
File source = new File(String.format("natives/%s/%s",
NativeLibraryUtil.getArchitecture().name().toLowerCase(),
NativeLibraryUtil.getArchitecture().name().toLowerCase(Locale.ENGLISH),
NativeLibraryUtil.getPlatformLibraryName("dummy")));
JarEntry entry = new JarEntry(source.getPath().replace("\\", "/"));
entry.setTime(System.currentTimeMillis());
Expand Down Expand Up @@ -95,9 +96,11 @@ public void testExtracting() throws Exception {
// jar if there is another test.
createJar();
// see if dummy is correctly extracted
Locale originalLocale = Locale.getDefault();
Locale.setDefault(new Locale("tr", "TR"));
JniExtractor jniExtractor = new DefaultJniExtractor(null);
String libPath = String.format("natives/%s",
NativeLibraryUtil.getArchitecture().name().toLowerCase());
NativeLibraryUtil.getArchitecture().name().toLowerCase(Locale.ENGLISH));
File extracted = jniExtractor.extractJni(libPath + "", "dummy");

FileInputStream in = null;
Expand All @@ -108,6 +111,7 @@ public void testExtracting() throws Exception {
assertTrue(new String(buffer).trim().equals("native-lib-loader"));
} finally {
if (in != null) { in.close(); }
Locale.setDefault(originalLocale);
}
}
}