Browse Source

Merge branch 'JNI-160' into Release_2.1

android-build
heck 4 months ago
parent
commit
ef84158e56
2 changed files with 14 additions and 11 deletions
  1. +12
    -9
      src/codegen/gen_java_Message.ysl2
  2. +2
    -2
      test/java/foundation/pEp/jniadapter/test/jni135/TestAlice.java

+ 12
- 9
src/codegen/gen_java_Message.ysl2 View File

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


+ 2
- 2
test/java/foundation/pEp/jniadapter/test/jni135/TestAlice.java View File

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