Fix determinism checker for non-valid unicode strings
Fixes: b/293388944
Change-Id: Ifa0c8b9d158829fdfaa6a4e24d9d52ff85e7e009
diff --git a/src/main/java/com/android/tools/r8/utils/DeterminismChecker.java b/src/main/java/com/android/tools/r8/utils/DeterminismChecker.java
index a8fbdbf..e5c2c66 100644
--- a/src/main/java/com/android/tools/r8/utils/DeterminismChecker.java
+++ b/src/main/java/com/android/tools/r8/utils/DeterminismChecker.java
@@ -120,12 +120,6 @@
if (!callback.onLine(header)) {
return;
}
- // TODO(b/293388944): The comparison is not valid for Strings containing some non
- // ASCII characters such as taiwanese characters.
- if (method.getHolderType().toString().equals("sun.nio.cs.EUC_TWMapping")
- || method.getHolderType().toString().equals("sun.nio.cs.GB18030")) {
- return;
- }
if (method.hasCode()) {
List<String> lines = StringUtils.splitLines(method.getCode().toString());
for (String line : lines) {
@@ -159,12 +153,16 @@
public boolean onLine(String unescapedLine) throws IOException {
String line = escape(unescapedLine);
String dumpLine = reader.readLine();
- boolean equals = dumpLine.equals(line);
- if (!equals) {
- throw new AssertionError(
- "\nMismatch for line: " + line + "\n" + " and dump-line: " + dumpLine);
+ if (!dumpLine.equals(line)) {
+ // The line might contain a non unicode points. If so, the dump line will have mapped those
+ // to ? when writing. Decode the string and retry equals.
+ String decoded = new String(line.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);
+ if (!decoded.equals(dumpLine)) {
+ throw new AssertionError(
+ "\nMismatch for line: " + decoded + "\n" + " and dump-line: " + dumpLine);
+ }
}
- return equals;
+ return true;
}
@Override