Skip to content

Commit 859ad76

Browse files
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.
1 parent 222665a commit 859ad76

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

server/src/test/java/org/elasticsearch/common/xcontent/BaseXContentTestCase.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import java.util.Locale;
7676
import java.util.Map;
7777
import java.util.concurrent.TimeUnit;
78+
import java.util.concurrent.atomic.AtomicBoolean;
7879

7980
import static java.util.Collections.emptyMap;
8081
import static java.util.Collections.singletonMap;
@@ -947,11 +948,18 @@ void doTestRawValue(XContent source) throws Exception {
947948
assertNull(parser.nextToken());
948949
}
949950

950-
os = new ByteArrayOutputStream();
951+
final AtomicBoolean closed = new AtomicBoolean(false);
952+
os = new ByteArrayOutputStream() {
953+
@Override
954+
public void close() {
955+
closed.set(true);
956+
}
957+
};
951958
try (XContentGenerator generator = xcontentType().xContent().createGenerator(os)) {
952959
generator.writeStartObject();
953960
generator.writeFieldName("test");
954961
generator.writeRawValue(new BytesArray(rawData).streamInput(), source.type());
962+
assertFalse("Generator should not have closed the output stream", closed.get());
955963
generator.writeEndObject();
956964
}
957965

0 commit comments

Comments
 (0)