diff --git a/src/com/sun/jna/Native.java b/src/com/sun/jna/Native.java index a7af91915..0a8976416 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 5c70c15f9..4d2a56d1d 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 4414fac83..bddb45e18 100644 --- a/test/com/sun/jna/DirectTest.java +++ b/test/com/sun/jna/DirectTest.java @@ -28,6 +28,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; @@ -203,7 +204,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); @@ -224,7 +225,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..cad70d6ca 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