From 38159d52d48dee54554e2a9fc404f3703d39f785 Mon Sep 17 00:00:00 2001 From: Roger Riggs Date: Wed, 7 Oct 2020 18:36:14 +0000 Subject: [PATCH] 8253876: jdk/test/lib/hexdump/ASN1FormatterTest.java fails with "AssertionError: Lines expected [126] but found [202]" Reviewed-by: shade, lancea --- test/lib-test/ProblemList.txt | 3 --- .../jdk/test/lib/hexdump/ASN1FormatterTest.java | 2 +- .../lib/jdk/test/lib/hexdump/ASN1Formatter.java | 17 +++++++++++------ test/lib/jdk/test/lib/hexdump/HexPrinter.java | 4 +++- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/test/lib-test/ProblemList.txt b/test/lib-test/ProblemList.txt index 8732bf87f2c..011466088d3 100644 --- a/test/lib-test/ProblemList.txt +++ b/test/lib-test/ProblemList.txt @@ -37,6 +37,3 @@ # More than one label is allowed but must be on the same line. # ############################################################################# - - -jdk/test/lib/hexdump/ASN1FormatterTest.java 8253876 generic-all diff --git a/test/lib-test/jdk/test/lib/hexdump/ASN1FormatterTest.java b/test/lib-test/jdk/test/lib/hexdump/ASN1FormatterTest.java index 8993f6f54f0..01887fa8baa 100644 --- a/test/lib-test/jdk/test/lib/hexdump/ASN1FormatterTest.java +++ b/test/lib-test/jdk/test/lib/hexdump/ASN1FormatterTest.java @@ -102,7 +102,7 @@ public class ASN1FormatterTest { } @Test - static void testIndefinate() { + static void testIndefinite() { byte[] bytes = {0x24, (byte) 0x80, 4, 2, 'a', 'b', 4, 2, 'c', 'd', 0, 0}; HexPrinter p = HexPrinter.simple() .formatter(ASN1Formatter.formatter(), "; ", 100); diff --git a/test/lib/jdk/test/lib/hexdump/ASN1Formatter.java b/test/lib/jdk/test/lib/hexdump/ASN1Formatter.java index 3a3fff6bb84..fb9486c3f95 100644 --- a/test/lib/jdk/test/lib/hexdump/ASN1Formatter.java +++ b/test/lib/jdk/test/lib/hexdump/ASN1Formatter.java @@ -165,8 +165,12 @@ public class ASN1Formatter implements HexPrinter.Formatter { // multi-byte encoded length int nbytes = len & 0x7f; if (nbytes > 4) { - out.append("***** Tag: " + tagName(tag) + - ", Range of length error: " + len + " bytes" + System.lineSeparator()); + out.append("***** Tag: ") + .append(tagName(tag)) + .append(", Range of length error: ") + .append(Integer.toString(len)) + .append(" bytes"); + out.append(System.lineSeparator()); return available; // return the unread length } len = 0; @@ -185,9 +189,10 @@ public class ASN1Formatter implements HexPrinter.Formatter { out.append(prefix); // start with indent switch (tag) { case TAG_EndOfContent: // End-of-contents octets; len == 0 - out.append("END-OF-CONTENT " + System.lineSeparator()); - // end of indefinite-length constructed, return any remaining - return 0; // unknown, but nothing left + out.append("END-OF-CONTENT"); + out.append(System.lineSeparator()); + // end of indefinite-length constructed, return zero remaining + return 0; case TAG_Integer: case TAG_Enumerated: switch (len) { @@ -319,7 +324,7 @@ public class ASN1Formatter implements HexPrinter.Formatter { } } } - out.append(System.lineSeparator()); // End with EOL + out.append(System.lineSeparator()); } return available; } diff --git a/test/lib/jdk/test/lib/hexdump/HexPrinter.java b/test/lib/jdk/test/lib/hexdump/HexPrinter.java index 4f32f5d3ebb..12f0cfd45b0 100644 --- a/test/lib/jdk/test/lib/hexdump/HexPrinter.java +++ b/test/lib/jdk/test/lib/hexdump/HexPrinter.java @@ -1099,7 +1099,9 @@ public final class HexPrinter { dest.append(info); info = ""; } else { - dest.append(info, 0, nl); + // append up to the newline (ignoring \r if present) + dest.append(info, 0, + (nl > 0 && info.charAt(nl - 1) == '\r') ? nl - 1 : nl); info = info.substring(nl + 1); } }