Fix Broken Stream Close in writeRawValue (#60625) (#60644)

Small oversight in #56078 that only showed up during backporting where a stream copy was turned from a non-closing to a closing one. Enhanced part of a test in this PR to make it show up in master also even though we practically never use this method with stream targets that actually close.
This commit is contained in:
Armin Braun 2020-08-04 13:39:52 +02:00 committed by GitHub
parent 222665a48e
commit 859ad761bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -75,6 +75,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
@ -947,11 +948,18 @@ public abstract class BaseXContentTestCase extends ESTestCase {
assertNull(parser.nextToken());
}
os = new ByteArrayOutputStream();
final AtomicBoolean closed = new AtomicBoolean(false);
os = new ByteArrayOutputStream() {
@Override
public void close() {
closed.set(true);
}
};
try (XContentGenerator generator = xcontentType().xContent().createGenerator(os)) {
generator.writeStartObject();
generator.writeFieldName("test");
generator.writeRawValue(new BytesArray(rawData).streamInput(), source.type());
assertFalse("Generator should not have closed the output stream", closed.get());
generator.writeEndObject();
}