Skip to content

Commit 956ca0e

Browse files
committed
Add @pure annotations to Preconditions
1 parent f4a0f2b commit 956ca0e

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

sdks/java/core/src/main/java/org/apache/beam/sdk/util/Preconditions.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
2525
import org.checkerframework.checker.nullness.qual.NonNull;
2626
import org.checkerframework.checker.nullness.qual.Nullable;
27+
import org.checkerframework.dataflow.qual.Pure;
2728

2829
/**
2930
* Beam-specific variants of {@link
@@ -44,6 +45,7 @@ public class Preconditions {
4445
*/
4546
@CanIgnoreReturnValue
4647
@EnsuresNonNull("#1")
48+
@Pure
4749
public static <T extends @NonNull Object> T checkArgumentNotNull(@Nullable T reference) {
4850
if (reference == null) {
4951
throw new IllegalArgumentException();
@@ -62,6 +64,7 @@ public class Preconditions {
6264
*/
6365
@CanIgnoreReturnValue
6466
@EnsuresNonNull("#1")
67+
@Pure
6568
public static <T extends @NonNull Object> T checkArgumentNotNull(
6669
@Nullable T reference, @Nullable Object errorMessage) {
6770
if (reference == null) {
@@ -86,6 +89,7 @@ public class Preconditions {
8689
*/
8790
@CanIgnoreReturnValue
8891
@EnsuresNonNull("reference")
92+
@Pure
8993
public static <T extends @NonNull Object> T checkArgumentNotNull(
9094
@Nullable T reference,
9195
@Nullable String errorMessageTemplate,
@@ -103,6 +107,7 @@ public class Preconditions {
103107
*/
104108
@CanIgnoreReturnValue
105109
@EnsuresNonNull("#1")
110+
@Pure
106111
public static <T extends @NonNull Object> T checkArgumentNotNull(
107112
@Nullable T obj, @Nullable String errorMessageTemplate, char p1) {
108113
if (obj == null) {
@@ -118,6 +123,7 @@ public class Preconditions {
118123
*/
119124
@CanIgnoreReturnValue
120125
@EnsuresNonNull("#1")
126+
@Pure
121127
public static <T extends @NonNull Object> T checkArgumentNotNull(
122128
@Nullable T obj, @Nullable String errorMessageTemplate, int p1) {
123129
if (obj == null) {
@@ -133,6 +139,7 @@ public class Preconditions {
133139
*/
134140
@CanIgnoreReturnValue
135141
@EnsuresNonNull("#1")
142+
@Pure
136143
public static <T extends @NonNull Object> T checkArgumentNotNull(
137144
@Nullable T obj, @Nullable String errorMessageTemplate, long p1) {
138145
if (obj == null) {
@@ -148,6 +155,7 @@ public class Preconditions {
148155
*/
149156
@CanIgnoreReturnValue
150157
@EnsuresNonNull("#1")
158+
@Pure
151159
public static <T extends @NonNull Object> T checkArgumentNotNull(
152160
@Nullable T obj, @Nullable String errorMessageTemplate, @Nullable Object p1) {
153161
if (obj == null) {
@@ -163,6 +171,7 @@ public class Preconditions {
163171
*/
164172
@CanIgnoreReturnValue
165173
@EnsuresNonNull("#1")
174+
@Pure
166175
public static <T extends @NonNull Object> T checkArgumentNotNull(
167176
@Nullable T obj, @Nullable String errorMessageTemplate, char p1, char p2) {
168177
if (obj == null) {
@@ -178,6 +187,7 @@ public class Preconditions {
178187
*/
179188
@CanIgnoreReturnValue
180189
@EnsuresNonNull("#1")
190+
@Pure
181191
public static <T extends @NonNull Object> T checkArgumentNotNull(
182192
@Nullable T obj, @Nullable String errorMessageTemplate, char p1, int p2) {
183193
if (obj == null) {
@@ -193,6 +203,7 @@ public class Preconditions {
193203
*/
194204
@CanIgnoreReturnValue
195205
@EnsuresNonNull("#1")
206+
@Pure
196207
public static <T extends @NonNull Object> T checkArgumentNotNull(
197208
@Nullable T obj, @Nullable String errorMessageTemplate, char p1, long p2) {
198209
if (obj == null) {
@@ -208,6 +219,7 @@ public class Preconditions {
208219
*/
209220
@CanIgnoreReturnValue
210221
@EnsuresNonNull("#1")
222+
@Pure
211223
public static <T extends @NonNull Object> T checkArgumentNotNull(
212224
@Nullable T obj, @Nullable String errorMessageTemplate, char p1, @Nullable Object p2) {
213225
if (obj == null) {
@@ -223,6 +235,7 @@ public class Preconditions {
223235
*/
224236
@CanIgnoreReturnValue
225237
@EnsuresNonNull("#1")
238+
@Pure
226239
public static <T extends @NonNull Object> T checkArgumentNotNull(
227240
@Nullable T obj, @Nullable String errorMessageTemplate, int p1, char p2) {
228241
if (obj == null) {
@@ -238,6 +251,7 @@ public class Preconditions {
238251
*/
239252
@CanIgnoreReturnValue
240253
@EnsuresNonNull("#1")
254+
@Pure
241255
public static <T extends @NonNull Object> T checkArgumentNotNull(
242256
@Nullable T obj, @Nullable String errorMessageTemplate, int p1, int p2) {
243257
if (obj == null) {
@@ -253,6 +267,7 @@ public class Preconditions {
253267
*/
254268
@CanIgnoreReturnValue
255269
@EnsuresNonNull("#1")
270+
@Pure
256271
public static <T extends @NonNull Object> T checkArgumentNotNull(
257272
@Nullable T obj, @Nullable String errorMessageTemplate, int p1, long p2) {
258273
if (obj == null) {
@@ -268,6 +283,7 @@ public class Preconditions {
268283
*/
269284
@CanIgnoreReturnValue
270285
@EnsuresNonNull("#1")
286+
@Pure
271287
public static <T extends @NonNull Object> T checkArgumentNotNull(
272288
@Nullable T obj, @Nullable String errorMessageTemplate, int p1, @Nullable Object p2) {
273289
if (obj == null) {
@@ -283,6 +299,7 @@ public class Preconditions {
283299
*/
284300
@CanIgnoreReturnValue
285301
@EnsuresNonNull("#1")
302+
@Pure
286303
public static <T extends @NonNull Object> T checkArgumentNotNull(
287304
@Nullable T obj, @Nullable String errorMessageTemplate, long p1, char p2) {
288305
if (obj == null) {
@@ -298,6 +315,7 @@ public class Preconditions {
298315
*/
299316
@CanIgnoreReturnValue
300317
@EnsuresNonNull("#1")
318+
@Pure
301319
public static <T extends @NonNull Object> T checkArgumentNotNull(
302320
@Nullable T obj, @Nullable String errorMessageTemplate, long p1, int p2) {
303321
if (obj == null) {
@@ -313,6 +331,7 @@ public class Preconditions {
313331
*/
314332
@CanIgnoreReturnValue
315333
@EnsuresNonNull("#1")
334+
@Pure
316335
public static <T extends @NonNull Object> T checkArgumentNotNull(
317336
@Nullable T obj, @Nullable String errorMessageTemplate, long p1, long p2) {
318337
if (obj == null) {
@@ -328,6 +347,7 @@ public class Preconditions {
328347
*/
329348
@CanIgnoreReturnValue
330349
@EnsuresNonNull("#1")
350+
@Pure
331351
public static <T extends @NonNull Object> T checkArgumentNotNull(
332352
@Nullable T obj, @Nullable String errorMessageTemplate, long p1, @Nullable Object p2) {
333353
if (obj == null) {
@@ -343,6 +363,7 @@ public class Preconditions {
343363
*/
344364
@CanIgnoreReturnValue
345365
@EnsuresNonNull("#1")
366+
@Pure
346367
public static <T extends @NonNull Object> T checkArgumentNotNull(
347368
@Nullable T obj, @Nullable String errorMessageTemplate, @Nullable Object p1, char p2) {
348369
if (obj == null) {
@@ -358,6 +379,7 @@ public class Preconditions {
358379
*/
359380
@CanIgnoreReturnValue
360381
@EnsuresNonNull("#1")
382+
@Pure
361383
public static <T extends @NonNull Object> T checkArgumentNotNull(
362384
@Nullable T obj, @Nullable String errorMessageTemplate, @Nullable Object p1, int p2) {
363385
if (obj == null) {
@@ -373,6 +395,7 @@ public class Preconditions {
373395
*/
374396
@CanIgnoreReturnValue
375397
@EnsuresNonNull("#1")
398+
@Pure
376399
public static <T extends @NonNull Object> T checkArgumentNotNull(
377400
@Nullable T obj, @Nullable String errorMessageTemplate, @Nullable Object p1, long p2) {
378401
if (obj == null) {
@@ -388,6 +411,7 @@ public class Preconditions {
388411
*/
389412
@CanIgnoreReturnValue
390413
@EnsuresNonNull("#1")
414+
@Pure
391415
public static <T extends @NonNull Object> T checkArgumentNotNull(
392416
@Nullable T obj,
393417
@Nullable String errorMessageTemplate,
@@ -406,6 +430,7 @@ public class Preconditions {
406430
*/
407431
@CanIgnoreReturnValue
408432
@EnsuresNonNull("#1")
433+
@Pure
409434
public static <T extends @NonNull Object> T checkArgumentNotNull(
410435
@Nullable T obj,
411436
@Nullable String errorMessageTemplate,
@@ -425,6 +450,7 @@ public class Preconditions {
425450
*/
426451
@CanIgnoreReturnValue
427452
@EnsuresNonNull("#1")
453+
@Pure
428454
public static <T extends @NonNull Object> T checkArgumentNotNull(
429455
@Nullable T obj,
430456
@Nullable String errorMessageTemplate,
@@ -447,6 +473,7 @@ public class Preconditions {
447473
*/
448474
@CanIgnoreReturnValue
449475
@EnsuresNonNull("#1")
476+
@Pure
450477
public static <T extends @NonNull Object> T checkStateNotNull(@Nullable T obj) {
451478
if (obj == null) {
452479
throw new IllegalStateException();
@@ -465,6 +492,7 @@ public class Preconditions {
465492
*/
466493
@CanIgnoreReturnValue
467494
@EnsuresNonNull("#1")
495+
@Pure
468496
public static <T extends @NonNull Object> T checkStateNotNull(
469497
@Nullable T reference, @Nullable Object errorMessage) {
470498
if (reference == null) {
@@ -489,6 +517,7 @@ public class Preconditions {
489517
*/
490518
@CanIgnoreReturnValue
491519
@EnsuresNonNull("#1")
520+
@Pure
492521
public static <T extends @NonNull Object> T checkStateNotNull(
493522
@Nullable T obj,
494523
@Nullable String errorMessageTemplate,
@@ -506,6 +535,7 @@ public class Preconditions {
506535
*/
507536
@CanIgnoreReturnValue
508537
@EnsuresNonNull("#1")
538+
@Pure
509539
public static <T extends @NonNull Object> T checkStateNotNull(
510540
@Nullable T obj, @Nullable String errorMessageTemplate, @Nullable Object p1) {
511541
if (obj == null) {
@@ -521,6 +551,7 @@ public class Preconditions {
521551
*/
522552
@CanIgnoreReturnValue
523553
@EnsuresNonNull("#1")
554+
@Pure
524555
public static <T extends @NonNull Object> T checkStateNotNull(
525556
@Nullable T obj,
526557
@Nullable String errorMessageTemplate,

0 commit comments

Comments
 (0)