From 6cb74cbc0e574b677e41f9fee5bbed2d8b7d9789 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Mon, 20 Nov 2023 00:41:40 -0800 Subject: [PATCH] Use constants for system properties --- src/com/sun/jna/Native.java | 2 +- src/com/sun/jna/Structure.java | 2 +- test/com/sun/jna/DirectTest.java | 5 +++-- test/com/sun/jna/MemoryTest.java | 2 +- test/com/sun/jna/NativeTest.java | 4 ++-- test/com/sun/jna/StructureTest.java | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/com/sun/jna/Native.java b/src/com/sun/jna/Native.java index d895c970a..3b67f34a5 100644 --- a/src/com/sun/jna/Native.java +++ b/src/com/sun/jna/Native.java @@ -221,7 +221,7 @@ static boolean isCompatibleVersion(String expectedVersion, String nativeVersion) loadNativeDispatchLibrary(); if (! isCompatibleVersion(VERSION_NATIVE, getNativeVersion())) { - String LS = System.getProperty("line.separator"); + String LS = System.lineSeparator(); throw new Error(LS + LS + "There is an incompatible JNA native library installed on this system" + LS + "Expected: " + VERSION_NATIVE + LS diff --git a/src/com/sun/jna/Structure.java b/src/com/sun/jna/Structure.java index 78e903af2..57866df46 100644 --- a/src/com/sun/jna/Structure.java +++ b/src/com/sun/jna/Structure.java @@ -1563,7 +1563,7 @@ private String format(Class type) { private String toString(int indent, boolean showContents, boolean dumpMemory) { ensureAllocated(); - String LS = System.getProperty("line.separator"); + String LS = System.lineSeparator(); String name = format(getClass()) + "(" + getPointer() + ")"; if (!(getPointer() instanceof Memory)) { name += " (" + size() + " bytes)"; diff --git a/test/com/sun/jna/DirectTest.java b/test/com/sun/jna/DirectTest.java index e20ffe7e6..1d4449f89 100644 --- a/test/com/sun/jna/DirectTest.java +++ b/test/com/sun/jna/DirectTest.java @@ -29,6 +29,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.charset.Charset; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -202,7 +203,7 @@ public void testGetOptionsForDirectMappingWithMemberInitializer() { }; final TypeMapper mapper = new DefaultTypeMapper(); final int alignment = Structure.ALIGN_NONE; - final String encoding = System.getProperty("file.encoding"); + final String encoding = Charset.defaultCharset().displayName(); Map options = new HashMap<>(); options.put(Library.OPTION_TYPE_MAPPER, mapper); options.put(Library.OPTION_STRUCTURE_ALIGNMENT, alignment); @@ -223,7 +224,7 @@ public void testGetOptionsForDirectMappingWithMemberInitializer() { public static class DirectMappingStatic { final static TypeMapper TEST_MAPPER = new DefaultTypeMapper(); final static int TEST_ALIGNMENT = Structure.ALIGN_DEFAULT; - final static String TEST_ENCODING = System.getProperty("file.encoding"); + final static String TEST_ENCODING = Charset.defaultCharset().displayName(); final static Map TEST_OPTIONS = new HashMap<>() { private static final long serialVersionUID = 1L; // we're not serializing it diff --git a/test/com/sun/jna/MemoryTest.java b/test/com/sun/jna/MemoryTest.java index 1e695cce7..5cbbafff0 100644 --- a/test/com/sun/jna/MemoryTest.java +++ b/test/com/sun/jna/MemoryTest.java @@ -172,7 +172,7 @@ public void testDump() { m.setByte(i, (byte) i); } - String ls = System.getProperty("line.separator"); + String ls = System.lineSeparator(); assertEquals("memory dump" + ls + "[00010203]" + ls + diff --git a/test/com/sun/jna/NativeTest.java b/test/com/sun/jna/NativeTest.java index ae99d6262..a77d812f8 100644 --- a/test/com/sun/jna/NativeTest.java +++ b/test/com/sun/jna/NativeTest.java @@ -85,7 +85,7 @@ public void testLongStringGeneration() { } public void testCustomStringEncoding() throws Exception { - final String ENCODING = System.getProperty("file.encoding"); + final String ENCODING = Charset.defaultCharset().displayName(); // Keep stuff within the extended ASCII range so we work with more // limited native encodings String UNICODE = "Un \u00e9l\u00e9ment gr\u00e2ce \u00e0 l'index"; @@ -477,7 +477,7 @@ public void testGetBytesWithCharset() throws Exception { public void testGetBytesBadEncoding() throws Exception { byte[] buf = Native.getBytes(getName(), "unsupported"); assertEquals("Incorrect fallback bytes with bad encoding", - getName(), new String(buf, System.getProperty("file.encoding"))); + getName(), new String(buf, Charset.defaultCharset().displayName())); } public void testFindDirectMappedClassFailure() { diff --git a/test/com/sun/jna/StructureTest.java b/test/com/sun/jna/StructureTest.java index 0a6002a8d..93918ea95 100644 --- a/test/com/sun/jna/StructureTest.java +++ b/test/com/sun/jna/StructureTest.java @@ -1429,7 +1429,7 @@ protected List getFieldOrder() { } } TestStructure s = new TestStructure(); - final String LS = System.getProperty("line.separator"); + final String LS = System.lineSeparator(); System.setProperty("jna.dump_memory", "true"); final String EXPECTED = "(?m).*" + s.size() + " bytes.*\\{" + LS + " int intField@0x0=0x0000" + LS