diff --git a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java index 9cd5171f125b..dc47f5aa67d4 100644 --- a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java +++ b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java @@ -1481,7 +1481,10 @@ public String get(StringBytes b) { @Override public void close() throws IOException { - if (daos != null) { + // marshal() already flushes in its own finally block, so skip the redundant flush. + // Flushing again after a marshal failure would re-throw the same exception from the broken + // stream, causing "Self-suppression not permitted" in the caller's try-with-resources. + if (daos != null && !alreadyMarshalled) { daos.flushBuffer(); } }