]> git.bitcoin.ninja Git - ldk-java/commitdiff
[TS+Java] Ensure we don't try to add a reference from `null`.
authorMatt Corallo <git@bluematt.me>
Sat, 3 Sep 2022 20:24:10 +0000 (20:24 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 3 Sep 2022 21:41:23 +0000 (21:41 +0000)
At least in `Event::PaymentPathFailed` if we try to map an event
with no `retry` we'll hit a `NullPointerException` as we'll try to
add a reference from the `null` retry back to the `Event` itself.

The simple fix is to simply exhaustively check for `null` before
adding references everywhere.

java_strings.py
typescript_strings.py

index bcfc1f37e4fc8a02e87d9d716020c06fb196a81d..c249c200de73f7c0b3c33a393c922bca21c9785d 100644 (file)
@@ -704,7 +704,7 @@ import javax.annotation.Nullable;
         return var + ".ptr" + " = 0;"
 
     def add_ref(self, holder, referent):
-        return holder + ".ptrs_to.add(" + referent + ")"
+        return "if (" + holder + " != null) { " + holder + ".ptrs_to.add(" + referent + "); }"
 
     def fully_qualified_hu_ty_path(self, ty):
         if ty.java_fn_ty_arg.startswith("L") and ty.java_fn_ty_arg.endswith(";"):
index e4d4c3ebec8f06db3b58e7cc4e92e2bad767bb7b..cc7b236315c6be51e1f593b74f3a04be3916fb4f 100644 (file)
@@ -348,7 +348,7 @@ export class CommonBase {
        // In TypeScript, protected means "any subclass can access parent fields on instances of itself"
        // To work around this, we add accessors for other instances' protected fields here.
        protected static add_ref_from(holder: CommonBase, referent: object) {
-               holder.ptrs_to.push(referent);
+               if (holder !== null) { holder.ptrs_to.push(referent); }
        }
        protected static get_ptr_of(o: CommonBase) {
                return o.ptr;