We recently migrated our application to JDK 8 from JDK 7. After this change, we had a problem with the following code fragment.
String output = new String(byteArray, "UTF-8");
The byte array may contain invalid UTF-8 byte sequences. The same byte array when decoding UTF-8 results in two difference strings in Java 7 and Java 8.
According to the response to this SO post , Java 8 "fixes" the error in Java 7 and replaces invalid UTF-8 byte sequences with a replacement string that conforms to the UTF-8 specification.
But we would like to stick with the decryption version of Java 7.
We tried using CharsetDecoder with CodingErrorAction as REPLACE, REPORT, and IGNORE in Java 8. However, we were unable to create the same line as Java 7.
Can we do this using a technique of reasonable complexity?
java java-8 utf-8 regression
Jiraiya
source share