-
Bug
-
Resolution: Fixed
-
P3
-
19
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8289064 | 20 | Naoto Sato | P3 | Resolved | Fixed | b04 |
JDK-8291312 | 19.0.2 | Naoto Sato | P3 | Resolved | Fixed | b01 |
JDK-8291144 | 19.0.1 | Naoto Sato | P3 | Resolved | Fixed | b04 |
JDK-8308698 | 17.0.9-oracle | Weibing Xiao | P3 | Resolved | Fixed | b01 |
JDK-8306041 | 17.0.8 | Goetz Lindenmaier | P3 | Resolved | Fixed | b01 |
When using Files.readString(...) with UTF-16, encoding errors are ignored/ replaced, rather than throwing a MalformedInputException. This is the result of a fix of
REGRESSION : Last worked in version 16
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should throw a MalformedInputException, as it does from JDK 11 to JDK 16. Note that when you change UTF_16 to UTF_8, the code does exhibit the expected behavior in all versions from JDK 11 to JDK 19.
ACTUAL -
It does not throw an exception with UTF_16 but silently proceeds with a replacement character (U+FFFD)
---------- BEGIN SOURCE ----------
import java.io.*;
import java.nio.file.*;
import java.nio.charset.*;
class Test {
public static void main(String... arg) throws IOException {
Path p = Files.write(Files.createTempFile("charset", "test"), new byte[] { -50 });
try(Closeable c = () -> Files.delete(p)) {
String s = Files.readString(p, StandardCharsets.UTF_16);
}
}
}
---------- END SOURCE ----------
- backported by
-
JDK-8289064 Files.readString ignores encoding errors for UTF-16
- Resolved
-
JDK-8291144 Files.readString ignores encoding errors for UTF-16
- Resolved
-
JDK-8291312 Files.readString ignores encoding errors for UTF-16
- Resolved
-
JDK-8306041 Files.readString ignores encoding errors for UTF-16
- Resolved
-
JDK-8308698 Files.readString ignores encoding errors for UTF-16
- Resolved
- relates to
-
JDK-8286287 Reading file as UTF-16 causes Error which "shouldn't happen"
- Closed
-
JDK-8259842 Remove Result cache from StringCoding
- Resolved
- links to
-
Commit openjdk/jdk17u-dev/acbac0d1
-
Commit openjdk/jdk19/a716f793
-
Commit openjdk/jdk/2728770e
-
Review openjdk/jdk17u-dev/1230
-
Review openjdk/jdk19/61
-
Review openjdk/jdk/9193