Fix AbstractBaseType nullness handling 66/81466/5
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 9 Apr 2019 07:07:26 +0000 (09:07 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 10 Apr 2019 07:43:56 +0000 (07:43 +0000)
Use requireNonNull() instead of a custom throw, allowing us
to annotate the field as @NonNull, reducing the number of warnings.

Change-Id: I53a64abfed239c3ae76d319479916ca381595324
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/AbstractBaseType.java
binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/mdsal/binding/model/util/generated/type/builder/EnumerationBuilderImplTest.java

index f955acf7fce073f4845fe3976b13df81db445a89..4081790871a7ee8cbdfc40c5c81920fe74f21075 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.mdsal.binding.model.util;
 
+import static java.util.Objects.requireNonNull;
+
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
 import org.opendaylight.mdsal.binding.model.api.Type;
 
@@ -17,12 +20,7 @@ public class AbstractBaseType implements Type {
     /**
      * Name of this <code>Type</code>.
      */
-    private final JavaTypeName identifier;
-
-    @Override
-    public final JavaTypeName getIdentifier() {
-        return this.identifier;
-    }
+    private final @NonNull JavaTypeName identifier;
 
     /**
      * Constructs the instance of this class with a JavaTypeName.
@@ -30,10 +28,12 @@ public class AbstractBaseType implements Type {
      * @param identifier for this <code>Type</code>
      */
     protected AbstractBaseType(final JavaTypeName identifier) {
-        if (identifier == null) {
-            throw new IllegalArgumentException("Identifier for Generated Type cannot be null!");
-        }
-        this.identifier = identifier;
+        this.identifier = requireNonNull(identifier);
+    }
+
+    @Override
+    public final JavaTypeName getIdentifier() {
+        return this.identifier;
     }
 
     @Override
index 181a315e494da935f07a6da1dea707ccfdafd91b..14a612b85fcdcca5ff4e346620d788835e0a15f8 100644 (file)
@@ -58,7 +58,7 @@ public class EnumerationBuilderImplTest {
         enumeration = enumerationBuilder.toInstance(enumerationBuilder);
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = NullPointerException.class)
     public void testAddNullAnnotation() {
         assertNull(enumerationBuilder.addAnnotation(null));
     }