Skip to content

Commit 8ff1dec

Browse files
Fix Broken Stream Close in writeRawValue
Small oversight in elastic#56078 that only showed up during backporting.
1 parent ae01606 commit 8ff1dec

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

libs/x-content/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public void writeRawValue(InputStream stream, XContentType xContentType) throws
364364
generator.writeRaw(':');
365365
}
366366
flush();
367-
Streams.copy(stream, os);
367+
Streams.copy(stream, os, false);
368368
writeEndRaw();
369369
}
370370
}

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(closed.get());
955963
generator.writeEndObject();
956964
}
957965

0 commit comments

Comments
 (0)