Fix error when writing empty String to DataBuffer
Prior to this commit, `DataBuffer.write` would throw an `IllegalStateException` when called with an empty `String`, since the `CharsetEncoder` would be flushed on an incorrent state. This commit skips entirely the encoding phase for empty `String`. Fixes #22262
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -179,6 +179,16 @@ public class DataBufferTests extends AbstractDataBufferAllocatingTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeEmptyString() {
|
||||
DataBuffer buffer = createDataBuffer(1);
|
||||
buffer.write("", StandardCharsets.UTF_8);
|
||||
|
||||
assertEquals(0, buffer.readableByteCount());
|
||||
|
||||
release(buffer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeUtf8String() {
|
||||
DataBuffer buffer = createDataBuffer(6);
|
||||
|
||||
Reference in New Issue
Block a user