You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by GitBox <gi...@apache.org> on 2020/07/16 01:12:06 UTC

[GitHub] [hadoop] amahussein commented on a change in pull request #2134: HADOOP-17123. remove guava Preconditions from Hadoop-common module

amahussein commented on a change in pull request #2134:
URL: https://github.com/apache/hadoop/pull/2134#discussion_r455451890



##########
File path: hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/noguava/Preconditions.java
##########
@@ -0,0 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.util.noguava;
+
+import java.util.Collection;
+import java.util.Objects;
+import javax.annotation.Nullable;
+
+public final class Preconditions {
+  private static final String VALIDATE_STATE_EX_MESSAGE =
+      "The validated state is false";
+  private static final String VALIDATE_IS_NOT_NULL_EX_MESSAGE =
+      "The validated object is null";
+  private static final String VALIDATE_RANGE_INDEX_ARRAY_EX_MESSAGE =
+      "The validated array size: %d, index is out of range: %d";
+  private static final String VALIDATE_INDEX_ARRAY_EX_MESSAGE =
+      "The validated array index is invalid: %d";
+  private static final String VALIDATE_SIZE_ARRAY_EX_MESSAGE =
+      "The validated array size is invalid: %d";
+  private static final String VALIDATE_IS_TRUE_EX_MESSAGE =
+      "The validated expression is false";
+
+  private Preconditions() {
+    super();
+  }
+
+  public static void checkIsTrue(final boolean expression, final String message,

Review comment:
       > This is going to be a big piece of work. not just the coding, but the merging and backporting.
   > 
   > * we are going to have to backport the noguava package back many versions of releases, so that then cherrypicking is easy. That doesn't need any other changes to go...it should be a separate patch
   > * I'm not sure about "noguava" as a name. "unguava"?
   > * package must be scoped private/unstable
   > * we need separate checks for state and arg, as different exceptions are raised.
   > 
   > Also, if we are going to do this, can we have one overload which takes a `Supplier<String> messageSupplier` as Objects.requireNonNull() does. Gives us room to play in future
   > 
   > Finally, big thing to consider: we need tests for the methods actually doing what we expect. That's raising exceptions and forming the correct strings.
   
   Thanks Steve for the feedback. I created a new PR #2143 that has `unguava.Validate#checkNotNull` implementation.




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org