From: Matt Corallo Date: Sat, 3 Sep 2022 20:24:10 +0000 (+0000) Subject: [TS+Java] Ensure we don't try to add a reference from `null`. X-Git-Tag: v0.0.110.1.1~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=4568b2bc1e3eb7555d2b5a3450f63698fad9aabc;p=ldk-java [TS+Java] Ensure we don't try to add a reference from `null`. 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. --- diff --git a/java_strings.py b/java_strings.py index 63774b5e..8148d0b5 100644 --- a/java_strings.py +++ b/java_strings.py @@ -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(";"): diff --git a/typescript_strings.py b/typescript_strings.py index 765a93cd..347aac69 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -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;