diff options
author | Henrik Nord <[email protected]> | 2015-12-07 16:07:18 +0100 |
---|---|---|
committer | Henrik Nord <[email protected]> | 2015-12-07 16:07:18 +0100 |
commit | 494afc417880374d11971b73e8aab3d2321eee2d (patch) | |
tree | a3f053d32c145e22d6a7d6d295fe1f983f29eebe /lib/jinterface | |
parent | 8081c6d2ac8f69bfa3ef718dfb8f9a1abe6ea908 (diff) | |
parent | 9be3ffd7bbb7fbf386fe7857b3ff9c9803e91cc7 (diff) | |
download | otp-494afc417880374d11971b73e8aab3d2321eee2d.tar.gz otp-494afc417880374d11971b73e8aab3d2321eee2d.tar.bz2 otp-494afc417880374d11971b73e8aab3d2321eee2d.zip |
Merge branch 'maint'
Diffstat (limited to 'lib/jinterface')
3 files changed, 34 insertions, 14 deletions
diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangMap.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangMap.java index 0fd7d3ce37..30126db3fd 100644 --- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangMap.java +++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangMap.java @@ -19,7 +19,7 @@ */ package com.ericsson.otp.erlang; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -37,13 +37,22 @@ public class OtpErlangMap extends OtpErlangObject { // don't change this! private static final long serialVersionUID = -6410770117696198497L; - private HashMap<OtpErlangObject, OtpErlangObject> map; + private OtpMap map; + + private static class OtpMap + extends LinkedHashMap<OtpErlangObject, OtpErlangObject> { + private static final long serialVersionUID = -2666505810905455082L; + + public OtpMap() { + super(); + } + } /** * Create an empty map. */ public OtpErlangMap() { - map = new HashMap<OtpErlangObject, OtpErlangObject>(); + map = new OtpMap(); } /** @@ -93,7 +102,7 @@ public class OtpErlangMap extends OtpErlangObject { throw new java.lang.IllegalArgumentException( "Map keys and values must have same arity"); } - map = new HashMap<OtpErlangObject, OtpErlangObject>(vcount); + map = new OtpMap(); OtpErlangObject key, val; for (int i = 0; i < vcount; i++) { if ((key = keys[kstart + i]) == null) { @@ -125,7 +134,7 @@ public class OtpErlangMap extends OtpErlangObject { final int arity = buf.read_map_head(); if (arity > 0) { - map = new HashMap<OtpErlangObject, OtpErlangObject>(arity); + map = new OtpMap(); for (int i = 0; i < arity; i++) { OtpErlangObject key, val; key = buf.read_any(); @@ -133,7 +142,7 @@ public class OtpErlangMap extends OtpErlangObject { put(key, val); } } else { - map = new HashMap<OtpErlangObject, OtpErlangObject>(); + map = new OtpMap(); } } @@ -350,7 +359,7 @@ public class OtpErlangMap extends OtpErlangObject { @SuppressWarnings("unchecked") public Object clone() { final OtpErlangMap newMap = (OtpErlangMap) super.clone(); - newMap.map = (HashMap<OtpErlangObject, OtpErlangObject>) map.clone(); + newMap.map = (OtpMap) map.clone(); return newMap; } } diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java index 2830a7842e..4faae2a157 100644 --- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java +++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java @@ -922,8 +922,22 @@ public class OtpOutputStream extends ByteArrayOutputStream { oos.writeTo(dos); dos.close(); // note: closes this, too! } catch (final IllegalArgumentException e) { - // discard further un-compressed data - // -> if not called, there may be memory leaks! + /* + * Discard further un-compressed data (if not called, there may + * be memory leaks). + * + * After calling java.util.zip.Deflater.end(), the deflater + * should not be used anymore, not even the close() method of + * dos. Calling dos.close() before def.end() is prevented since + * an unfinished DeflaterOutputStream will try to deflate its + * unprocessed data to the (fixed) byte array which is prevented + * by ensureCapacity() and would also unnecessarily process + * further data that is discarded anyway. + * + * Since we are re-using the byte array of this object below, we + * must not call close() in e.g. a finally block either (with or + * without a call to def.end()). + */ def.end(); // could not make the value smaller than originally // -> reset to starting count, write uncompressed @@ -942,11 +956,6 @@ public class OtpOutputStream extends ByteArrayOutputStream { "Intermediate stream failed for Erlang object " + o); } finally { fixedSize = Integer.MAX_VALUE; - try { - dos.close(); - } catch (final IOException e) { - // ignore - } } } } diff --git a/lib/jinterface/test/nc_SUITE.erl b/lib/jinterface/test/nc_SUITE.erl index 9679b90a0d..c5f3198c21 100644 --- a/lib/jinterface/test/nc_SUITE.erl +++ b/lib/jinterface/test/nc_SUITE.erl @@ -215,6 +215,7 @@ decompress_roundtrip(Config) when is_list(Config) -> 0.0, math:sqrt(2), <<1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,31:5>>, + "{}", RandomBin1k, RandomBin1M, RandomBin10M, @@ -244,6 +245,7 @@ compress_roundtrip(Config) when is_list(Config) -> 0.0, math:sqrt(2), <<1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,31:5>>, + "{}", RandomBin1k, RandomBin1M, RandomBin10M, |