From: Matt Corallo Date: Thu, 3 Mar 2022 02:32:15 +0000 (+0000) Subject: [Java] Add a reachabilityFence on underlying trait impl calls X-Git-Tag: v0.0.105.0~1^2~6 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=1f873e8aeb7a8395a7a99d244fba7474a0543278;p=ldk-java [Java] Add a reachabilityFence on underlying trait impl calls Because the implementation instance is implicitly held as a reference in the `held` field, it seems unlikely this could ever matter, hwoever, in the simplified implementation in `PeerTest` (where there is no Human instance to hold a reference to the underlying bindings instance), we do see the implementation being free'd while its still in use. Thus, to ensure we can't hit any such issue in the future, we add one in normal human objects as well. --- diff --git a/java_strings.py b/java_strings.py index cc1a3617..3a8ba6cb 100644 --- a/java_strings.py +++ b/java_strings.py @@ -882,7 +882,8 @@ import javax.annotation.Nullable; else: java_trait_constr = java_trait_constr + arg_info.arg_name - java_trait_constr = java_trait_constr + ");\n" + java_trait_constr += ");\n" + java_trait_constr += "\t\t\t\tReference.reachabilityFence(arg);\n" if fn_line.ret_ty_info.java_ty != "void": if fn_line.ret_ty_info.from_hu_conv is not None: java_trait_constr = java_trait_constr + "\t\t\t\t" + fn_line.ret_ty_info.java_ty + " result = " + fn_line.ret_ty_info.from_hu_conv[0] + ";\n" diff --git a/src/test/java/org/ldk/PeerTest.java b/src/test/java/org/ldk/PeerTest.java index 7dc3f1a3..9b3d2f17 100644 --- a/src/test/java/org/ldk/PeerTest.java +++ b/src/test/java/org/ldk/PeerTest.java @@ -7,6 +7,7 @@ import org.ldk.enums.Network; import org.ldk.enums.Recipient; import org.ldk.impl.bindings; +import java.lang.ref.Reference; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -234,7 +235,8 @@ public class PeerTest { deliver_peer_messages(list, peer1.peer_manager, peer2.peer_manager); ArrayList events = new ArrayList(); - long handler = bindings.LDKEventHandler_new(events::add); + bindings.LDKEventHandler events_adder = events::add; + long handler = bindings.LDKEventHandler_new(events_adder); bindings.EventsProvider_process_pending_events(peer1.chan_manager_events, handler); assert events.size() == 1; @@ -336,6 +338,7 @@ public class PeerTest { bindings.LDKEvent sent_path = bindings.LDKEvent_ref_from_ptr(events.get(0)); assert sent_path instanceof bindings.LDKEvent.PaymentPathSuccessful; bindings.Event_free(events.remove(0)); + Reference.reachabilityFence(events_adder); bindings.EventHandler_free(handler);