[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>
Sun, 4 Sep 2022 00:04:26 +0000 (00:04 +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 63774b5e2df556630614e3f5daf06bae8a083e1c..8148d0b5baeff8325257c95e3a930426fe08ddac 100644 (file)
@@ -701,7 +701,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 765a93cda50c1247350c1ce6fc959629c8cc088e..347aac691b1a35da548cc1ad5d30328e6c0415a1 100644 (file)
@@ -341,7 +341,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;