Merge pull request #117 from TheBlueMatt/2022-08-fix-npe
[ldk-java] / src / main / java / org / ldk / structs / Balance.java
index 429335b4cb451bcd878c41160989f4e39def266a..c2106e76cca9839e4e87e36fec9ab0bf37118118 100644 (file)
@@ -4,6 +4,7 @@ import org.ldk.impl.bindings;
 import org.ldk.enums.*;
 import org.ldk.util.*;
 import java.util.Arrays;
+import java.lang.ref.Reference;
 import javax.annotation.Nullable;
 
 
@@ -125,6 +126,7 @@ public class Balance extends CommonBase {
        }
        long clone_ptr() {
                long ret = bindings.Balance_clone_ptr(this.ptr);
+               Reference.reachabilityFence(this);
                return ret;
        }
 
@@ -133,9 +135,10 @@ public class Balance extends CommonBase {
         */
        public Balance clone() {
                long ret = bindings.Balance_clone(this.ptr);
+               Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
-               Balance ret_hu_conv = Balance.constr_from_ptr(ret);
-               ret_hu_conv.ptrs_to.add(this);
+               org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
                return ret_hu_conv;
        }
 
@@ -144,9 +147,10 @@ public class Balance extends CommonBase {
         */
        public static Balance claimable_on_channel_close(long claimable_amount_satoshis) {
                long ret = bindings.Balance_claimable_on_channel_close(claimable_amount_satoshis);
+               Reference.reachabilityFence(claimable_amount_satoshis);
                if (ret >= 0 && ret <= 4096) { return null; }
-               Balance ret_hu_conv = Balance.constr_from_ptr(ret);
-               ret_hu_conv.ptrs_to.add(ret_hu_conv);
+               org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
                return ret_hu_conv;
        }
 
@@ -155,9 +159,11 @@ public class Balance extends CommonBase {
         */
        public static Balance claimable_awaiting_confirmations(long claimable_amount_satoshis, int confirmation_height) {
                long ret = bindings.Balance_claimable_awaiting_confirmations(claimable_amount_satoshis, confirmation_height);
+               Reference.reachabilityFence(claimable_amount_satoshis);
+               Reference.reachabilityFence(confirmation_height);
                if (ret >= 0 && ret <= 4096) { return null; }
-               Balance ret_hu_conv = Balance.constr_from_ptr(ret);
-               ret_hu_conv.ptrs_to.add(ret_hu_conv);
+               org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
                return ret_hu_conv;
        }
 
@@ -166,9 +172,11 @@ public class Balance extends CommonBase {
         */
        public static Balance contentious_claimable(long claimable_amount_satoshis, int timeout_height) {
                long ret = bindings.Balance_contentious_claimable(claimable_amount_satoshis, timeout_height);
+               Reference.reachabilityFence(claimable_amount_satoshis);
+               Reference.reachabilityFence(timeout_height);
                if (ret >= 0 && ret <= 4096) { return null; }
-               Balance ret_hu_conv = Balance.constr_from_ptr(ret);
-               ret_hu_conv.ptrs_to.add(ret_hu_conv);
+               org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
                return ret_hu_conv;
        }
 
@@ -177,9 +185,11 @@ public class Balance extends CommonBase {
         */
        public static Balance maybe_claimable_htlcawaiting_timeout(long claimable_amount_satoshis, int claimable_height) {
                long ret = bindings.Balance_maybe_claimable_htlcawaiting_timeout(claimable_amount_satoshis, claimable_height);
+               Reference.reachabilityFence(claimable_amount_satoshis);
+               Reference.reachabilityFence(claimable_height);
                if (ret >= 0 && ret <= 4096) { return null; }
-               Balance ret_hu_conv = Balance.constr_from_ptr(ret);
-               ret_hu_conv.ptrs_to.add(ret_hu_conv);
+               org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
                return ret_hu_conv;
        }
 
@@ -188,8 +198,14 @@ public class Balance extends CommonBase {
         * This ignores pointers and is_owned flags and looks at the values in fields.
         */
        public boolean eq(Balance b) {
-               boolean ret = bindings.Balance_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
+               boolean ret = bindings.Balance_eq(this.ptr, b == null ? 0 : b.ptr);
+               Reference.reachabilityFence(this);
+               Reference.reachabilityFence(b);
                return ret;
        }
 
+       @Override public boolean equals(Object o) {
+               if (!(o instanceof Balance)) return false;
+               return this.eq((Balance)o);
+       }
 }