# HG changeset patch # User attila # Date 1433163696 -7200 # Node ID 993dede76f370ec555430e396a486e34e9ecb7c5 # Parent f822b749821e364cae0b7bd7c8f667d9437e6d83 8066218: UTF-32LE mistakenly detected as UTF-16LE Reviewed-by: lagergren, sundar diff -r f822b749821e -r 993dede76f37 src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java --- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java Thu May 28 16:50:12 2015 -0700 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java Mon Jun 01 15:01:36 2015 +0200 @@ -934,14 +934,16 @@ start = 2; cs = StandardCharsets.UTF_16BE; } else if (bytes.length > 1 && bytes[0] == (byte) 0xFF && bytes[1] == (byte) 0xFE) { - start = 2; - cs = StandardCharsets.UTF_16LE; + if (bytes.length > 3 && bytes[2] == 0 && bytes[3] == 0) { + start = 4; + cs = Charset.forName("UTF-32LE"); + } else { + start = 2; + cs = StandardCharsets.UTF_16LE; + } } else if (bytes.length > 2 && bytes[0] == (byte) 0xEF && bytes[1] == (byte) 0xBB && bytes[2] == (byte) 0xBF) { start = 3; cs = StandardCharsets.UTF_8; - } else if (bytes.length > 3 && bytes[0] == (byte) 0xFF && bytes[1] == (byte) 0xFE && bytes[2] == 0 && bytes[3] == 0) { - start = 4; - cs = Charset.forName("UTF-32LE"); } else if (bytes.length > 3 && bytes[0] == 0 && bytes[1] == 0 && bytes[2] == (byte) 0xFE && bytes[3] == (byte) 0xFF) { start = 4; cs = Charset.forName("UTF-32BE");