Skip to content

Commit f385eff

Browse files
authored
Merge pull request #117 from TheBlueMatt/2022-08-fix-npe
[TS+Java] Ensure we don't try to add a reference from null.
2 parents c4db25b + 49083f7 commit f385eff

File tree

328 files changed

+1574
-1574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

328 files changed

+1574
-1574
lines changed

java_strings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ def set_null_skip_free(self, var):
704704
return var + ".ptr" + " = 0;"
705705

706706
def add_ref(self, holder, referent):
707-
return holder + ".ptrs_to.add(" + referent + ")"
707+
return "if (" + holder + " != null) { " + holder + ".ptrs_to.add(" + referent + "); }"
708708

709709
def fully_qualified_hu_ty_path(self, ty):
710710
if ty.java_fn_ty_arg.startswith("L") and ty.java_fn_ty_arg.endswith(";"):

src/main/java/org/ldk/structs/APIError.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private IncompatibleShutdownScript(long ptr, bindings.LDKAPIError.IncompatibleSh
134134
super(null, ptr);
135135
long script = obj.script;
136136
org.ldk.structs.ShutdownScript script_hu_conv = null; if (script < 0 || script > 4096) { script_hu_conv = new org.ldk.structs.ShutdownScript(null, script); }
137-
script_hu_conv.ptrs_to.add(this);
137+
if (script_hu_conv != null) { script_hu_conv.ptrs_to.add(this); };
138138
this.script = script_hu_conv;
139139
}
140140
}
@@ -152,7 +152,7 @@ public APIError clone() {
152152
Reference.reachabilityFence(this);
153153
if (ret >= 0 && ret <= 4096) { return null; }
154154
org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
155-
ret_hu_conv.ptrs_to.add(this);
155+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
156156
return ret_hu_conv;
157157
}
158158

@@ -164,7 +164,7 @@ public static APIError apimisuse_error(java.lang.String err) {
164164
Reference.reachabilityFence(err);
165165
if (ret >= 0 && ret <= 4096) { return null; }
166166
org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
167-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
167+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
168168
return ret_hu_conv;
169169
}
170170

@@ -177,7 +177,7 @@ public static APIError fee_rate_too_high(java.lang.String err, int feerate) {
177177
Reference.reachabilityFence(feerate);
178178
if (ret >= 0 && ret <= 4096) { return null; }
179179
org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
180-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
180+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
181181
return ret_hu_conv;
182182
}
183183

@@ -189,7 +189,7 @@ public static APIError route_error(java.lang.String err) {
189189
Reference.reachabilityFence(err);
190190
if (ret >= 0 && ret <= 4096) { return null; }
191191
org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
192-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
192+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
193193
return ret_hu_conv;
194194
}
195195

@@ -201,7 +201,7 @@ public static APIError channel_unavailable(java.lang.String err) {
201201
Reference.reachabilityFence(err);
202202
if (ret >= 0 && ret <= 4096) { return null; }
203203
org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
204-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
204+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
205205
return ret_hu_conv;
206206
}
207207

@@ -212,7 +212,7 @@ public static APIError monitor_update_failed() {
212212
long ret = bindings.APIError_monitor_update_failed();
213213
if (ret >= 0 && ret <= 4096) { return null; }
214214
org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
215-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
215+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
216216
return ret_hu_conv;
217217
}
218218

@@ -224,8 +224,8 @@ public static APIError incompatible_shutdown_script(ShutdownScript script) {
224224
Reference.reachabilityFence(script);
225225
if (ret >= 0 && ret <= 4096) { return null; }
226226
org.ldk.structs.APIError ret_hu_conv = org.ldk.structs.APIError.constr_from_ptr(ret);
227-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
228-
ret_hu_conv.ptrs_to.add(script);
227+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
228+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(script); };
229229
return ret_hu_conv;
230230
}
231231

src/main/java/org/ldk/structs/AcceptChannel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public ChannelTypeFeatures get_channel_type() {
287287
Reference.reachabilityFence(this);
288288
if (ret >= 0 && ret <= 4096) { return null; }
289289
org.ldk.structs.ChannelTypeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTypeFeatures(null, ret); }
290-
ret_hu_conv.ptrs_to.add(this);
290+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
291291
return ret_hu_conv;
292292
}
293293

@@ -304,7 +304,7 @@ public void set_channel_type(@Nullable ChannelTypeFeatures val) {
304304
bindings.AcceptChannel_set_channel_type(this.ptr, val == null ? 0 : val.ptr);
305305
Reference.reachabilityFence(this);
306306
Reference.reachabilityFence(val);
307-
this.ptrs_to.add(val);
307+
if (this != null) { this.ptrs_to.add(val); };
308308
}
309309

310310
long clone_ptr() {
@@ -321,7 +321,7 @@ public AcceptChannel clone() {
321321
Reference.reachabilityFence(this);
322322
if (ret >= 0 && ret <= 4096) { return null; }
323323
org.ldk.structs.AcceptChannel ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.AcceptChannel(null, ret); }
324-
ret_hu_conv.ptrs_to.add(this);
324+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
325325
return ret_hu_conv;
326326
}
327327

src/main/java/org/ldk/structs/AnnouncementSignatures.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static AnnouncementSignatures of(byte[] channel_id_arg, long short_channe
103103
Reference.reachabilityFence(bitcoin_signature_arg);
104104
if (ret >= 0 && ret <= 4096) { return null; }
105105
org.ldk.structs.AnnouncementSignatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.AnnouncementSignatures(null, ret); }
106-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
106+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
107107
return ret_hu_conv;
108108
}
109109

@@ -121,7 +121,7 @@ public AnnouncementSignatures clone() {
121121
Reference.reachabilityFence(this);
122122
if (ret >= 0 && ret <= 4096) { return null; }
123123
org.ldk.structs.AnnouncementSignatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.AnnouncementSignatures(null, ret); }
124-
ret_hu_conv.ptrs_to.add(this);
124+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
125125
return ret_hu_conv;
126126
}
127127

src/main/java/org/ldk/structs/BackgroundProcessor.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ public static BackgroundProcessor start(Persister persister, EventHandler event_
104104
Reference.reachabilityFence(scorer);
105105
if (ret >= 0 && ret <= 4096) { return null; }
106106
org.ldk.structs.BackgroundProcessor ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BackgroundProcessor(null, ret); }
107-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
108-
ret_hu_conv.ptrs_to.add(persister);
109-
ret_hu_conv.ptrs_to.add(event_handler);
110-
ret_hu_conv.ptrs_to.add(chain_monitor);
111-
ret_hu_conv.ptrs_to.add(channel_manager);
112-
ret_hu_conv.ptrs_to.add(peer_manager);
113-
ret_hu_conv.ptrs_to.add(logger);
114-
ret_hu_conv.ptrs_to.add(scorer);
107+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
108+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(persister); };
109+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(event_handler); };
110+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(chain_monitor); };
111+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_manager); };
112+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(peer_manager); };
113+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
114+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(scorer); };
115115
return ret_hu_conv;
116116
}
117117

@@ -131,7 +131,7 @@ public Result_NoneErrorZ join() {
131131
Reference.reachabilityFence(this);
132132
if (ret >= 0 && ret <= 4096) { return null; }
133133
Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret);
134-
this.ptrs_to.add(this);
134+
if (this != null) { this.ptrs_to.add(this); };
135135
// Due to rust's strict-ownership memory model, in some cases we need to "move"
136136
// an object to pass exclusive ownership to the function being called.
137137
// In most cases, we avoid this being visible in GC'd languages by cloning the object
@@ -159,7 +159,7 @@ public Result_NoneErrorZ stop() {
159159
Reference.reachabilityFence(this);
160160
if (ret >= 0 && ret <= 4096) { return null; }
161161
Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret);
162-
this.ptrs_to.add(this);
162+
if (this != null) { this.ptrs_to.add(this); };
163163
// Due to rust's strict-ownership memory model, in some cases we need to "move"
164164
// an object to pass exclusive ownership to the function being called.
165165
// In most cases, we avoid this being visible in GC'd languages by cloning the object

src/main/java/org/ldk/structs/Balance.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public Balance clone() {
138138
Reference.reachabilityFence(this);
139139
if (ret >= 0 && ret <= 4096) { return null; }
140140
org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
141-
ret_hu_conv.ptrs_to.add(this);
141+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
142142
return ret_hu_conv;
143143
}
144144

@@ -150,7 +150,7 @@ public static Balance claimable_on_channel_close(long claimable_amount_satoshis)
150150
Reference.reachabilityFence(claimable_amount_satoshis);
151151
if (ret >= 0 && ret <= 4096) { return null; }
152152
org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
153-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
153+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
154154
return ret_hu_conv;
155155
}
156156

@@ -163,7 +163,7 @@ public static Balance claimable_awaiting_confirmations(long claimable_amount_sat
163163
Reference.reachabilityFence(confirmation_height);
164164
if (ret >= 0 && ret <= 4096) { return null; }
165165
org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
166-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
166+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
167167
return ret_hu_conv;
168168
}
169169

@@ -176,7 +176,7 @@ public static Balance contentious_claimable(long claimable_amount_satoshis, int
176176
Reference.reachabilityFence(timeout_height);
177177
if (ret >= 0 && ret <= 4096) { return null; }
178178
org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
179-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
179+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
180180
return ret_hu_conv;
181181
}
182182

@@ -189,7 +189,7 @@ public static Balance maybe_claimable_htlcawaiting_timeout(long claimable_amount
189189
Reference.reachabilityFence(claimable_height);
190190
if (ret >= 0 && ret <= 4096) { return null; }
191191
org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
192-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
192+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
193193
return ret_hu_conv;
194194
}
195195

src/main/java/org/ldk/structs/BaseSign.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction h
349349
Reference.reachabilityFence(preimages);
350350
if (ret >= 0 && ret <= 4096) { return null; }
351351
Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
352-
this.ptrs_to.add(holder_tx);
352+
if (this != null) { this.ptrs_to.add(holder_tx); };
353353
return ret_hu_conv;
354354
}
355355

@@ -386,7 +386,7 @@ public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitmen
386386
Reference.reachabilityFence(preimages);
387387
if (ret >= 0 && ret <= 4096) { return null; }
388388
Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret);
389-
this.ptrs_to.add(commitment_tx);
389+
if (this != null) { this.ptrs_to.add(commitment_tx); };
390390
return ret_hu_conv;
391391
}
392392

@@ -425,7 +425,7 @@ public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_holder_commitment_and_
425425
Reference.reachabilityFence(commitment_tx);
426426
if (ret >= 0 && ret <= 4096) { return null; }
427427
Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret);
428-
this.ptrs_to.add(commitment_tx);
428+
if (this != null) { this.ptrs_to.add(commitment_tx); };
429429
return ret_hu_conv;
430430
}
431431

@@ -486,7 +486,7 @@ public Result_SignatureNoneZ sign_justice_revoked_htlc(byte[] justice_tx, long i
486486
Reference.reachabilityFence(htlc);
487487
if (ret >= 0 && ret <= 4096) { return null; }
488488
Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
489-
this.ptrs_to.add(htlc);
489+
if (this != null) { this.ptrs_to.add(htlc); };
490490
return ret_hu_conv;
491491
}
492492

@@ -519,7 +519,7 @@ public Result_SignatureNoneZ sign_counterparty_htlc_transaction(byte[] htlc_tx,
519519
Reference.reachabilityFence(htlc);
520520
if (ret >= 0 && ret <= 4096) { return null; }
521521
Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
522-
this.ptrs_to.add(htlc);
522+
if (this != null) { this.ptrs_to.add(htlc); };
523523
return ret_hu_conv;
524524
}
525525

@@ -535,7 +535,7 @@ public Result_SignatureNoneZ sign_closing_transaction(ClosingTransaction closing
535535
Reference.reachabilityFence(closing_tx);
536536
if (ret >= 0 && ret <= 4096) { return null; }
537537
Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
538-
this.ptrs_to.add(closing_tx);
538+
if (this != null) { this.ptrs_to.add(closing_tx); };
539539
return ret_hu_conv;
540540
}
541541

@@ -556,7 +556,7 @@ public Result_C2Tuple_SignatureSignatureZNoneZ sign_channel_announcement(Unsigne
556556
Reference.reachabilityFence(msg);
557557
if (ret >= 0 && ret <= 4096) { return null; }
558558
Result_C2Tuple_SignatureSignatureZNoneZ ret_hu_conv = Result_C2Tuple_SignatureSignatureZNoneZ.constr_from_ptr(ret);
559-
this.ptrs_to.add(msg);
559+
if (this != null) { this.ptrs_to.add(msg); };
560560
return ret_hu_conv;
561561
}
562562

@@ -576,7 +576,7 @@ public void ready_channel(ChannelTransactionParameters channel_parameters) {
576576
bindings.BaseSign_ready_channel(this.ptr, channel_parameters == null ? 0 : channel_parameters.ptr);
577577
Reference.reachabilityFence(this);
578578
Reference.reachabilityFence(channel_parameters);
579-
this.ptrs_to.add(channel_parameters);
579+
if (this != null) { this.ptrs_to.add(channel_parameters); };
580580
}
581581

582582
/**
@@ -588,7 +588,7 @@ public ChannelPublicKeys get_pubkeys() {
588588
Reference.reachabilityFence(this);
589589
if (ret >= 0 && ret <= 4096) { return null; }
590590
org.ldk.structs.ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelPublicKeys(null, ret); }
591-
ret_hu_conv.ptrs_to.add(this);
591+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
592592
return ret_hu_conv;
593593
}
594594

src/main/java/org/ldk/structs/Bech32Error.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public Bech32Error clone() {
119119
Reference.reachabilityFence(this);
120120
if (ret >= 0 && ret <= 4096) { return null; }
121121
org.ldk.structs.Bech32Error ret_hu_conv = org.ldk.structs.Bech32Error.constr_from_ptr(ret);
122-
ret_hu_conv.ptrs_to.add(this);
122+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
123123
return ret_hu_conv;
124124
}
125125

src/main/java/org/ldk/structs/BestBlock.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public BestBlock clone() {
3434
Reference.reachabilityFence(this);
3535
if (ret >= 0 && ret <= 4096) { return null; }
3636
org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
37-
ret_hu_conv.ptrs_to.add(this);
37+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
3838
return ret_hu_conv;
3939
}
4040

@@ -47,7 +47,7 @@ public static BestBlock from_genesis(org.ldk.enums.Network network) {
4747
Reference.reachabilityFence(network);
4848
if (ret >= 0 && ret <= 4096) { return null; }
4949
org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
50-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
50+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
5151
return ret_hu_conv;
5252
}
5353

@@ -60,7 +60,7 @@ public static BestBlock of(byte[] block_hash, int height) {
6060
Reference.reachabilityFence(height);
6161
if (ret >= 0 && ret <= 4096) { return null; }
6262
org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
63-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
63+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
6464
return ret_hu_conv;
6565
}
6666

src/main/java/org/ldk/structs/BigSize.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static BigSize of(long a_arg) {
4646
Reference.reachabilityFence(a_arg);
4747
if (ret >= 0 && ret <= 4096) { return null; }
4848
org.ldk.structs.BigSize ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BigSize(null, ret); }
49-
ret_hu_conv.ptrs_to.add(ret_hu_conv);
49+
if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
5050
return ret_hu_conv;
5151
}
5252

0 commit comments

Comments
 (0)