You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/06/28 18:11:48 UTC

[GitHub] [beam] kileys commented on a diff in pull request #17819: [BEAM-10496] Eliminate some null errors from sdks/java/core

kileys commented on code in PR #17819:
URL: https://github.com/apache/beam/pull/17819#discussion_r908731594


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/values/PValues.java:
##########
@@ -99,16 +97,19 @@ public static Map<TupleTag<?>, PCollection<?>> fullyExpand(
                     PCollection.class.getSimpleName(),
                     valueComponent.getValue()));
           }
+          @Nullable

Review Comment:
   How come the other ones doesn't need the @Nullable?



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/values/TypeDescriptor.java:
##########
@@ -180,7 +178,7 @@ public Class<? super T> getRawType() {
 
   /** Returns the component type if this type is an array type, otherwise returns {@code null}. */

Review Comment:
   Can this return null?



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/util/Preconditions.java:
##########
@@ -472,4 +472,63 @@ public class Preconditions {
     }
     return reference;
   }
+
+  /**
+   * Ensures that a piece of state passed as a parameter to the calling method is not null.
+   *
+   * @param obj an object reference
+   * @param errorMessageTemplate a template for the exception message should the check fail. The
+   *     message is formed by replacing each {@code %s} placeholder in the template with an
+   *     argument. These are matched by position - the first {@code %s} gets {@code
+   *     errorMessageArgs[0]}, etc. Unmatched arguments will be appended to the formatted message in
+   *     square braces. Unmatched placeholders will be left as-is.
+   * @param errorMessageArgs the arguments to be substituted into the message template. Arguments
+   *     are converted to strings using {@link String#valueOf(Object)}.
+   * @return the non-null reference that was validated
+   * @throws IllegalStateException if {@code obj} is null
+   */
+  @CanIgnoreReturnValue
+  @EnsuresNonNull("#1")
+  public static <T extends @NonNull Object> T checkStateNotNull(
+      @Nullable T obj,
+      @Nullable String errorMessageTemplate,
+      @Nullable Object... errorMessageArgs) {
+    if (obj == null) {
+      throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, errorMessageArgs));
+    }
+    return obj;
+  }
+
+  /**
+   * Ensures that a piece of state is not null.
+   *
+   * <p>See {@link #checkStateNotNull(Object, String, Object...)} for details.
+   */
+  @CanIgnoreReturnValue
+  @EnsuresNonNull("#1")
+  public static <T extends @NonNull Object> T checkStateNotNull(
+      @Nullable T obj, @Nullable String errorMessageTemplate, @Nullable Object p1) {
+    if (obj == null) {
+      throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1));
+    }
+    return obj;
+  }
+
+  /**
+   * Ensures that an object reference passed as a parameter to the calling method is not null.
+   *
+   * <p>See {@link #checkArgumentNotNull(Object, String, Object...)} for details.
+   */
+  @CanIgnoreReturnValue
+  @EnsuresNonNull("#1")
+  public static <T extends @NonNull Object> T checkStateNotNull(
+      @Nullable T obj,
+      @Nullable String errorMessageTemplate,
+      @Nullable Object p1,
+      @Nullable Object p2) {
+    if (obj == null) {
+      throw new IllegalStateException(lenientFormat(errorMessageTemplate, p1));

Review Comment:
   p2 not used



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org