Bug fix: ByteArrayBuilder incorrectly handles empty strings

This commit is contained in:
Oleg Kalnichevski 2022-01-24 13:58:07 +01:00
parent 75e8dc6f9b
commit 235900eb57
2 changed files with 3 additions and 2 deletions

View File

@ -74,8 +74,8 @@ public final class ByteArrayBuilder {
final int capacity = (int) (in.remaining() * encoder.averageBytesPerChar());
ByteBuffer out = ensureFreeCapacity(buffer, capacity);
for (;;) {
CoderResult result = in.hasRemaining() ? encoder.encode(in, out, true) : CoderResult.UNDERFLOW;
while (in.hasRemaining()) {
CoderResult result = encoder.encode(in, out, true);
if (result.isError()) {
result.throwException();
}

View File

@ -96,6 +96,7 @@ public class TestByteArrayBuilder {
buffer.append("bcd");
buffer.append("e");
buffer.append("f");
buffer.append("");
buffer.append((String) null);
buffer.append((char[]) null);