Enforce modernize in openflowjava-extension-eric 88/105788/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 2 May 2023 17:15:57 +0000 (19:15 +0200)
committerSangwook Ha <sangwook.ha@verizon.com>
Sat, 24 Jun 2023 04:20:34 +0000 (04:20 +0000)
We have a few violations here -- migrate to using Math.toIntExact() and
Objects.requireNonNull(). Flip enforcement on.

Change-Id: I0a581d20b4cfb27489d1d09ac757cf17b22485d7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
extension/openflowjava-extension-eric/pom.xml
extension/openflowjava-extension-eric/src/main/java/org/opendaylight/openflowjava/eric/EricExtensionsRegistrator.java
extension/openflowjava-extension-eric/src/main/java/org/opendaylight/openflowjava/eric/codec/match/EricHeader.java

index 329c6a2a9056a68dbb6f730213cc01c2de42dde1..56d2146e61feb7f5743f3422c049c6adf20dd207 100644 (file)
     <artifactId>openflowjava-extension-eric</artifactId>
     <packaging>bundle</packaging>
 
-    <properties>
-        <!-- FIXME: Remove this -->
-        <odlparent.modernizer.enforce>false</odlparent.modernizer.enforce>
-    </properties>
-
     <dependencies>
         <dependency>
             <groupId>${project.groupId}.openflowjava</groupId>
index c9830e2fc151a79ce6e0bb4b0b2d9f580372cab8..879764134b5ae15ac888ac4bc06b1c449aa89a9c 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.openflowjava.eric;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import org.opendaylight.openflowjava.eric.api.EricExtensionCodecRegistrator;
 import org.opendaylight.openflowjava.eric.codec.match.Icmpv6NDOptionsTypeCodec;
 import org.opendaylight.openflowjava.eric.codec.match.Icmpv6NDReservedCodec;
@@ -15,8 +16,8 @@ import org.opendaylight.openflowjava.eric.codec.match.Icmpv6NDReservedCodec;
 public class EricExtensionsRegistrator implements AutoCloseable {
     private final EricExtensionCodecRegistrator registrator;
 
-    public EricExtensionsRegistrator(EricExtensionCodecRegistrator registrator) {
-        this.registrator = Preconditions.checkNotNull(registrator);
+    public EricExtensionsRegistrator(final EricExtensionCodecRegistrator registrator) {
+        this.registrator = requireNonNull(registrator);
         registrator.registerMatchEntrySerializer(Icmpv6NDReservedCodec.SERIALIZER_KEY,
                 Icmpv6NDReservedCodec.INSTANCE);
         registrator.registerMatchEntrySerializer(Icmpv6NDOptionsTypeCodec.SERIALIZER_KEY,
index c75f0388da9686e531dcad44c291e51be9cf1b6f..69565172ca428a881f2737838c03b143c8af0a37 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.openflowjava.eric.codec.match;
 
-import com.google.common.primitives.Ints;
-
 /**
  * Eric header.
  */
@@ -21,11 +19,11 @@ public class EricHeader {
     private final int length;
 
     public EricHeader(final long header) {
-        this.headerAsLong = header;
-        this.oxmClass = Ints.checkedCast(extractSub(header, 16, 16));
-        this.ericField = Ints.checkedCast(extractSub(header, 7, 9));
-        this.hasMask = extractSub(header, 1, 8) == 1;
-        this.length = Ints.checkedCast(extractSub(header, 8, 0));
+        headerAsLong = header;
+        oxmClass = Math.toIntExact(extractSub(header, 16, 16));
+        ericField = Math.toIntExact(extractSub(header, 7, 9));
+        hasMask = extractSub(header, 1, 8) == 1;
+        length = Math.toIntExact(extractSub(header, 8, 0));
     }
 
     public EricHeader(final int oxmClass, final int ericField, final boolean hasMask, final int length) {
@@ -33,7 +31,7 @@ public class EricHeader {
         this.ericField = ericField;
         this.hasMask = hasMask;
         this.length = length;
-        this.headerAsLong = (long) oxmClass << 16 | ericField << 9 | (hasMask ? 1 : 0) << 8 | length;
+        headerAsLong = (long) oxmClass << 16 | ericField << 9 | (hasMask ? 1 : 0) << 8 | length;
     }
 
     private static long extractSub(final long value, final int nrBits, final int offset) {