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.3^2~2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=305052451d456ee72ef4d37547d11c4ad610fbe7;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 bcfc1f37..c249c200 100644 --- a/java_strings.py +++ b/java_strings.py @@ -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(";"): diff --git a/typescript_strings.py b/typescript_strings.py index e4d4c3eb..cc7b2363 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -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;