Remove CodeHelpers.nonNullValue() 76/89176/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 20 Apr 2020 22:27:29 +0000 (00:27 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 20 Apr 2020 22:54:42 +0000 (00:54 +0200)
This method is used only with augmentations. Remove it and update
callers to use Objects.requireNonNull() instead.

This removes a source of IAEs in favor of more consistent NPE
as well as trims down a few bytes from builder classes.

Change-Id: I57ee77c19230f57b34bf85eb5e31863f17372437
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderTemplate.xtend
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/AbstractAugmentable.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/CodeHelpers.java

index b57296bf5b52a2c475465553787a0f93a80bbddf..673ca581d61adea732f5c090fcb9454eaecab7f4 100644 (file)
@@ -418,7 +418,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
     private def generateAugmentation() '''
         @«SUPPRESS_WARNINGS.importedName»({ "unchecked", "checkstyle:methodTypeParameterName"})
         public <E$$ extends «augmentType.importedName»> E$$ «AUGMENTABLE_AUGMENTATION_NAME»(«CLASS.importedName»<E$$> augmentationType) {
-            return (E$$) «AUGMENTATION_FIELD».get(«CODEHELPERS.importedName».nonNullValue(augmentationType, "augmentationType"));
+            return (E$$) «AUGMENTATION_FIELD».get(«JU_OBJECTS.importedName».requireNonNull(augmentationType));
         }
     '''
 
index ddc04ef00751db763a9e679d100122abcc0619c5..a095e519f51d57b671d8cc6482336118e6401854 100644 (file)
@@ -45,7 +45,7 @@ public abstract class AbstractAugmentable<T extends Augmentable<T>> implements A
     @SuppressWarnings("unchecked")
     @Override
     public final <A extends Augmentation<T>> A augmentation(final Class<A> augmentationType) {
-        return (A) augmentations.get(CodeHelpers.nonNullValue(augmentationType, "augmentationType"));
+        return (A) augmentations.get(requireNonNull(augmentationType));
     }
 
     @Override
index b7d8a8e48e6f0eb35962fef568c1f707d8b9ce34..836092a3d87f2b2ac5e256531551a2c596bbb71f 100644 (file)
@@ -47,28 +47,6 @@ public final class CodeHelpers {
         checkArgument(expression, "expected one of: %s \n%but was: %s", options, value);
     }
 
-    /**
-     * Require an argument being received. This is similar to {@link java.util.Objects#requireNonNull(Object)}, but
-     * throws an IllegalArgumentException.
-     *
-     * <p>
-     * Implementation note: we expect argName to be a string literal or a constant, so that it's non-nullness can be
-     *                      quickly discovered for a call site (where we are going to be inlined).
-     *
-     * @param value Value itself
-     * @param name Symbolic name
-     * @return non-null value
-     * @throws IllegalArgumentException if value is null
-     * @throws NullPointerException if name is null
-     */
-    // FIXME: another advantage is that it is JDT-annotated, but we could live without that. At some point we should
-    //        schedule a big ISE-to-NPE conversion and just use Objects.requireNonNull() instead.
-    public static <T> @NonNull T nonNullValue(@Nullable final T value, final @NonNull String name) {
-        requireNonNull(name);
-        checkArgument(value != null, "%s must not be null", name);
-        return value;
-    }
-
     /**
      * A shortcut for {@code Objects.requireNonNull(value, "Supplied value may not be null")}.
      *