Merge branch 'JNI-160' into Release_2.1

pull/14/head
heck 2 years ago
commit ef84158e56

@ -33,18 +33,19 @@ tstylesheet {
import java.util.Date;
import java.util.HashMap;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;
public class «$cname» implements MessageInterface, AutoCloseable, Serializable {
private static final long serialVersionUID = 2119420428331150924L;
private long handle;
private static int instanceCount = 0;
private static AtomicLong instanceCount = new AtomicLong(0);
native long init();
native void release(long handle);
public «$cname»() {
handle = init();
instanceCount++;
instanceCount.getAndIncrement();
}
private native long _«$cname»(
@ -54,7 +55,7 @@ tstylesheet {
public «$cname»(String mime_text) {
byte[] _mime_text = Utils.toUTF8(mime_text);
handle = _«$cname»(_mime_text);
instanceCount++;
instanceCount.getAndIncrement();
}
private native byte[] _encodeMIME() throws pEpException;
@ -65,16 +66,18 @@ tstylesheet {
private «$cname»(long h) {
handle = h;
instanceCount++;
instanceCount.getAndIncrement();
}
public final void close() {
release(handle);
handle = 0;
instanceCount--;
public synchronized final void close() {
if(handle != 0) {
release(handle);
handle = 0;
instanceCount.getAndDecrement();
}
}
public static int getInstanceCount() {
public static synchronized AtomicLong getInstanceCount() {
return instanceCount;
}

@ -99,10 +99,10 @@ class TestAlice {
msg1Enc.close();
msg1Plain.close();
log("cycle nr: " + cycles++ + " / Message.getInstanceCount(): " + Message.getInstanceCount());
assert Message.getInstanceCount() == 0 : "Leaking messages";
assert Message.getInstanceCount().get() == 0 : "Leaking messages";
} else {
log("cycle nr: " + cycles++ + " / Message.getInstanceCount(): " + Message.getInstanceCount());
assert Message.getInstanceCount() > 0 : "We should be leaking messages, actually";
assert Message.getInstanceCount().get() > 0 : "We should be leaking messages, actually";
}
}
}

Loading…
Cancel
Save