--- old/src/java.base/share/classes/java/nio/file/Files.java 2018-06-25 21:32:56.402338674 -0700 +++ new/src/java.base/share/classes/java/nio/file/Files.java 2018-06-25 21:32:55.970291730 -0700 @@ -43,7 +43,9 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetEncoder; +import java.nio.charset.MalformedInputException; import java.nio.charset.StandardCharsets; +import java.nio.charset.UnmappableCharacterException; import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.DosFileAttributes; // javadoc @@ -3282,6 +3284,10 @@ try { return JLA.newStringNoRepl(ba, cs); } catch (IllegalArgumentException e) { + Throwable cause = e.getCause(); + if (cause != null && cause instanceof MalformedInputException) { + throw (MalformedInputException)cause; + } throw new IOException(e); } } @@ -3638,6 +3644,10 @@ byte[] bytes = JLA.getBytesNoRepl(String.valueOf(csq), cs); write(path, bytes, options); } catch (IllegalArgumentException e) { + Throwable cause = e.getCause(); + if (cause != null && cause instanceof UnmappableCharacterException) { + throw (UnmappableCharacterException)cause; + } throw new IOException(e); }