From 405f8fe0b47fcfafcdb4853c325a42feb0614ed5 Mon Sep 17 00:00:00 2001 From: Andrey Turbanov Date: Tue, 24 Oct 2023 07:13:38 +0300 Subject: [PATCH] org.jline.util.PumpReader signed byte problem (#879) Backport of https://bugs.openjdk.org/browse/JDK-8312475 --- terminal/src/main/java/org/jline/utils/PumpReader.java | 2 +- .../src/test/java/org/jline/utils/PumpReaderTest.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/terminal/src/main/java/org/jline/utils/PumpReader.java b/terminal/src/main/java/org/jline/utils/PumpReader.java index 34bc4fc3b..bc1d4ed02 100644 --- a/terminal/src/main/java/org/jline/utils/PumpReader.java +++ b/terminal/src/main/java/org/jline/utils/PumpReader.java @@ -413,7 +413,7 @@ public int read() throws IOException { return EOF; } - return buffer.get(); + return buffer.get() & 0xFF; } private boolean readUsingBuffer() throws IOException { diff --git a/terminal/src/test/java/org/jline/utils/PumpReaderTest.java b/terminal/src/test/java/org/jline/utils/PumpReaderTest.java index 42c76a11e..84a668bb5 100644 --- a/terminal/src/test/java/org/jline/utils/PumpReaderTest.java +++ b/terminal/src/test/java/org/jline/utils/PumpReaderTest.java @@ -101,10 +101,10 @@ public void testSplitSurrogatePair() throws IOException { InputStream inputStream = pump.createInputStream(StandardCharsets.UTF_8); byte[] expectedEncoded = "\uD83D\uDE0A".getBytes(StandardCharsets.UTF_8); assertEquals(4, expectedEncoded.length); // verify that test is correctly implemented - assertEquals(expectedEncoded[0], inputStream.read()); - assertEquals(expectedEncoded[1], inputStream.read()); - assertEquals(expectedEncoded[2], inputStream.read()); - assertEquals(expectedEncoded[3], inputStream.read()); + assertEquals(expectedEncoded[0] & 0xff, inputStream.read()); + assertEquals(expectedEncoded[1] & 0xff, inputStream.read()); + assertEquals(expectedEncoded[2] & 0xff, inputStream.read()); + assertEquals(expectedEncoded[3] & 0xff, inputStream.read()); assertEquals(-1, inputStream.read()); }