Apache Lucene open-source search software
SOLR-11012: Fix three (JavaBinCodec not being closed) Resource Leak warnings.
Christine Poerschkee23ac243ef48
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 16bebf764bc..999d87e7757 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -69,6 +69,8 @@ Bug Fixes* SOLR-8984: EnumField's error reporting to now indicate the field name in failure log (Lanny Ripple,Ann Addicks via Ishan Chattopadhyaya)+* SOLR-11012: Fix three (JavaBinCodec not being closed) Resource Leak warnings. (Christine Poerschke)+Optimizations----------------------diff --git a/solr/core/src/test/org/apache/solr/util/TestUtils.java b/solr/core/src/test/org/apache/solr/util/TestUtils.javaindex 0423fbf57ba..2f4cd53f963 100644--- a/solr/core/src/test/org/apache/solr/util/TestUtils.java+++ b/solr/core/src/test/org/apache/solr/util/TestUtils.java@@ -183,12 +183,14 @@ public class TestUtils extends SolrTestCaseJ4 {public void testBinaryCommands() throws IOException {ByteArrayOutputStream baos = new ByteArrayOutputStream();- new JavaBinCodec().marshal((MapWriter) ew -> {- ew.put("set-user", fromJSONString("{x:y}"));- ew.put("set-user", fromJSONString("{x:y,x1:y1}"));- ew.put("single", Arrays.asList(fromJSONString("[{x:y,x1:y1},{x2:y2}]"), fromJSONString( "{x2:y2}")));- ew.put("multi", Arrays.asList(fromJSONString("{x:y,x1:y1}"), fromJSONString( "{x2:y2}")));- }, baos);+ try (final JavaBinCodec jbc = new JavaBinCodec()) {+ jbc.marshal((MapWriter) ew -> {+ ew.put("set-user", fromJSONString("{x:y}"));+ ew.put("set-user", fromJSONString("{x:y,x1:y1}"));+ ew.put("single", Arrays.asList(fromJSONString("[{x:y,x1:y1},{x2:y2}]"), fromJSONString( "{x2:y2}")));+ ew.put("multi", Arrays.asList(fromJSONString("{x:y,x1:y1}"), fromJSONString( "{x2:y2}")));+ }, baos);+ }ContentStream stream = new ContentStreamBase.ByteArrayStream(baos.toByteArray(),null, "application/javabin");List<CommandOperation> commands = CommandOperation.readCommands(Collections.singletonList(stream), new NamedList(), Collections.singleton("single"));diff --git a/solr/solrj/src/java/org/apache/solr/common/util/CommandOperation.java b/solr/solrj/src/java/org/apache/solr/common/util/CommandOperation.javaindex 50002f67534..19ea1991611 100644--- a/solr/solrj/src/java/org/apache/solr/common/util/CommandOperation.java+++ b/solr/solrj/src/java/org/apache/solr/common/util/CommandOperation.java@@ -245,14 +245,16 @@ public class CommandOperation {}};- new JavaBinCodec() {+ try (final JavaBinCodec jbc = new JavaBinCodec() {int level = 0;@Overrideprotected Map<Object, Object> newMap(int size) {level++;return level == 1 ? map : super.newMap(size);}- }.unmarshal(in);+ }) {+ jbc.unmarshal(in);+ }return operations;}diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java b/solr/solrj/src/java/org/apache/solr/common/util/Utils.javaindex 3be565c90ad..0605a3505d1 100644--- a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java+++ b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java@@ -106,9 +106,11 @@ public class Utils {}public static InputStream toJavabin(Object o) throws IOException {- BinaryRequestWriter.BAOS baos = new BinaryRequestWriter.BAOS();- new JavaBinCodec().marshal(o,baos);- return new ByteBufferInputStream(ByteBuffer.wrap(baos.getbuf(),0,baos.size()));+ try (final JavaBinCodec jbc = new JavaBinCodec()) {+ BinaryRequestWriter.BAOS baos = new BinaryRequestWriter.BAOS();+ jbc.marshal(o,baos);+ return new ByteBufferInputStream(ByteBuffer.wrap(baos.getbuf(),0,baos.size()));+ }}public static Collection getDeepCopy(Collection c, int maxDepth, boolean mutable) {