SOLR-11012: Fix three (JavaBinCodec not being closed) Resource Leak warnings.

This commit is contained in:
Christine Poerschke 2017-07-17 13:22:36 +01:00
parent abdb7292db
commit e23ac243ef
4 changed files with 19 additions and 11 deletions

View File

@ -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
----------------------

View File

@ -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"));

View File

@ -245,14 +245,16 @@ public class CommandOperation {
}
};
new JavaBinCodec() {
try (final JavaBinCodec jbc = new JavaBinCodec() {
int level = 0;
@Override
protected Map<Object, Object> newMap(int size) {
level++;
return level == 1 ? map : super.newMap(size);
}
}.unmarshal(in);
}) {
jbc.unmarshal(in);
}
return operations;
}

View File

@ -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) {