Fix findbugs violations in liblldp 86/67886/8
authorTom Pantelis <tompantelis@gmail.com>
Sat, 3 Feb 2018 01:43:09 +0000 (20:43 -0500)
committerTom Pantelis <tompantelis@gmail.com>
Wed, 28 Feb 2018 18:45:17 +0000 (13:45 -0500)
- Method call passes null for non-null parameter
- Class defines clone() but doesn't implement Cloneable
- Clone method may return null
- clone method does not call super.clone()
- equals() method does not check for null argument
- Reliance on default encoding
- May expose internal representation by returning reference to mutable object
- Field is a mutable collection which should be package protected - malicious code vulnerability
- Field should be package protected - malicious code vulnerability
- Inefficient use of keySet iterator instead of entrySet iterator
- Boxing/unboxing to parse a primitive - use parseXXX method
- Redundant nullcheck of value known to be non-null

Change-Id: I6d551d31d618a1adfc877ac59f29d02727201df6
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
13 files changed:
applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPUtil.java
applications/topology-lldp-discovery/src/main/java/org/opendaylight/openflowplugin/applications/topology/lldp/utils/LLDPDiscoveryUtils.java
libraries/liblldp/src/main/java/org/opendaylight/openflowplugin/libraries/liblldp/BitBufferHelper.java
libraries/liblldp/src/main/java/org/opendaylight/openflowplugin/libraries/liblldp/ConstructionException.java [deleted file]
libraries/liblldp/src/main/java/org/opendaylight/openflowplugin/libraries/liblldp/DataLinkAddress.java
libraries/liblldp/src/main/java/org/opendaylight/openflowplugin/libraries/liblldp/EtherTypes.java
libraries/liblldp/src/main/java/org/opendaylight/openflowplugin/libraries/liblldp/Ethernet.java
libraries/liblldp/src/main/java/org/opendaylight/openflowplugin/libraries/liblldp/EthernetAddress.java
libraries/liblldp/src/main/java/org/opendaylight/openflowplugin/libraries/liblldp/LLDP.java
libraries/liblldp/src/main/java/org/opendaylight/openflowplugin/libraries/liblldp/LLDPTLV.java
libraries/liblldp/src/main/java/org/opendaylight/openflowplugin/libraries/liblldp/NetUtils.java
libraries/liblldp/src/main/java/org/opendaylight/openflowplugin/libraries/liblldp/Packet.java
libraries/liblldp/src/test/java/org/opendaylight/openflowplugin/libraries/sal/packet/address/EthernetAddressTest.java

index b443809a2081c05394729840392f81595fbb6fa7..869e92618c531589603f4a504781403369a6fd55 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.openflowplugin.applications.lldpspeaker;
 
 import static org.opendaylight.openflowplugin.applications.topology.lldp.utils.LLDPDiscoveryUtils.getValueForLLDPPacketIntegrityEnsuring;
-import static org.opendaylight.openflowplugin.libraries.liblldp.LLDPTLV.CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC;
 
 import java.math.BigInteger;
 import java.security.NoSuchAlgorithmException;
@@ -85,7 +84,7 @@ public final class LLDPUtil {
 
         //Create LLDP CustomSec TLV
         byte[] pureValue = getValueForLLDPPacketIntegrityEnsuring(nodeConnectorId);
-        byte[] customSecValue = LLDPTLV.createCustomTLVValue(CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC, pureValue);
+        byte[] customSecValue = LLDPTLV.createSecSubTypeCustomTLVValue(pureValue);
         LLDPTLV customSecTlv = new LLDPTLV();
         customSecTlv.setType(LLDPTLV.TLVType.Custom.getValue()).setLength((short) customSecValue.length)
             .setValue(customSecValue);
index 054128e52f5ba755d209e7d72f2d57eb6c9f70c9..f7d2e475dcf910865e1b3189993e4ad9ef6bc335 100644 (file)
@@ -25,8 +25,7 @@ import org.opendaylight.mdsal.eos.binding.api.Entity;
 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
 import org.opendaylight.mdsal.eos.common.api.EntityOwnershipState;
 import org.opendaylight.openflowplugin.applications.topology.lldp.LLDPActivator;
-import org.opendaylight.openflowplugin.libraries.liblldp.BitBufferHelper;
-import org.opendaylight.openflowplugin.libraries.liblldp.CustomTLVKey;
+import org.opendaylight.openflowplugin.libraries.liblldp.BufferException;
 import org.opendaylight.openflowplugin.libraries.liblldp.Ethernet;
 import org.opendaylight.openflowplugin.libraries.liblldp.LLDP;
 import org.opendaylight.openflowplugin.libraries.liblldp.LLDPTLV;
@@ -111,8 +110,7 @@ public final class LLDPDiscoveryUtils {
                     throw new Exception("Node id wasn't specified via systemNameId in LLDP packet.");
                 }
 
-                final LLDPTLV nodeConnectorIdLldptlv = lldp.getCustomTLV(new CustomTLVKey(
-                        BitBufferHelper.getInt(LLDPTLV.OFOUI), LLDPTLV.CUSTOM_TLV_SUB_TYPE_NODE_CONNECTOR_ID[0]));
+                final LLDPTLV nodeConnectorIdLldptlv = lldp.getCustomTLV(LLDPTLV.createPortSubTypeCustomTLVKey());
                 if (nodeConnectorIdLldptlv != null) {
                     srcNodeConnectorId = new NodeConnectorId(LLDPTLV.getCustomString(
                             nodeConnectorIdLldptlv.getValue(), nodeConnectorIdLldptlv.getLength()));
@@ -165,9 +163,8 @@ public final class LLDPDiscoveryUtils {
     }
 
     private static boolean checkExtraAuthenticator(LLDP lldp, NodeConnectorId srcNodeConnectorId)
-            throws NoSuchAlgorithmException {
-        final LLDPTLV hashLldptlv = lldp.getCustomTLV(
-                new CustomTLVKey(BitBufferHelper.getInt(LLDPTLV.OFOUI), LLDPTLV.CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC[0]));
+            throws NoSuchAlgorithmException, BufferException {
+        final LLDPTLV hashLldptlv = lldp.getCustomTLV(LLDPTLV.createSecSubTypeCustomTLVKey());
         boolean secAuthenticatorOk = false;
         if (hashLldptlv != null) {
             byte[] rawTlvValue = hashLldptlv.getValue();
index 50484d01039051cf4bceb5c491ef768ebda047c7..07d1e618dbaf43cebd711aee8942cf51832491ce 100644 (file)
@@ -5,13 +5,10 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
-/**
- *
- */
 package org.opendaylight.openflowplugin.libraries.liblldp;
 
 import java.util.Arrays;
+import javax.annotation.Nonnull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -68,13 +65,13 @@ public abstract class BitBufferHelper {
             LOG.error("getShort", new BufferException("Container is too small for the number of requested bits"));
         }
         int startOffset = data.length * NetUtils.NUM_BITS_IN_A_BYTE - numBits;
-        byte[] bits = null;
         try {
-            bits = BitBufferHelper.getBits(data, startOffset, numBits);
+            byte[] bits = BitBufferHelper.getBits(data, startOffset, numBits);
+            return (short) toNumber(bits, numBits);
         } catch (final BufferException e) {
-            LOG.error("", e);
+            LOG.error("getBits failed", e);
         }
-        return (short) toNumber(bits, numBits);
+        return 0;
     }
 
     /**
@@ -101,13 +98,13 @@ public abstract class BitBufferHelper {
             LOG.error("getInt", new BufferException("Container is too small for the number of requested bits"));
         }
         int startOffset = data.length * NetUtils.NUM_BITS_IN_A_BYTE - numBits;
-        byte[] bits = null;
         try {
-            bits = BitBufferHelper.getBits(data, startOffset, numBits);
+            byte[] bits = BitBufferHelper.getBits(data, startOffset, numBits);
+            return (int) toNumber(bits, numBits);
         } catch (final BufferException e) {
-            LOG.error("", e);
+            LOG.error("getBits failed", e);
         }
-        return (int) toNumber(bits, numBits);
+        return 0;
     }
 
     /**
@@ -141,13 +138,13 @@ public abstract class BitBufferHelper {
             }
         }
         int startOffset = data.length * NetUtils.NUM_BITS_IN_A_BYTE - numBits;
-        byte[] bits = null;
         try {
-            bits = BitBufferHelper.getBits(data, startOffset, numBits);
+            byte[] bits = BitBufferHelper.getBits(data, startOffset, numBits);
+            return toNumber(bits, numBits);
         } catch (final BufferException e) {
-            LOG.error("", e);
+            LOG.error("getBits failed", e);
         }
-        return toNumber(bits, numBits);
+        return 0;
     }
 
     /**
@@ -170,6 +167,7 @@ public abstract class BitBufferHelper {
      *             when the startOffset and numBits parameters are not congruent
      *             with the data buffer size
      */
+    @Nonnull
     public static byte[] getBits(final byte[] data, final int startOffset, final int numBits) throws BufferException {
         int startByteOffset = 0;
         int extranumBits = numBits % NetUtils.NUM_BITS_IN_A_BYTE;
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/openflowplugin/libraries/liblldp/ConstructionException.java b/libraries/liblldp/src/main/java/org/opendaylight/openflowplugin/libraries/liblldp/ConstructionException.java
deleted file mode 100644 (file)
index 451e347..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-/**
- * @file   ConstructionException.java
- *
- *
- * @brief  Describe an exception that is raised when a construction
- * for a Node/NodeConnector/Edge or any of the SAL basic object fails
- * because input passed are not valid or compatible
- *
- *
- */
-package org.opendaylight.openflowplugin.libraries.liblldp;
-
-public class ConstructionException extends Exception {
-    private static final long serialVersionUID = 1L;
-
-    public ConstructionException(final String message) {
-        super(message);
-    }
-}
index 65a869178a0d4f3257bb98b488afbde06009071f..dff8feb4ec9aa05ce579f06945a5bc5448885506 100644 (file)
@@ -15,7 +15,7 @@ import javax.xml.bind.annotation.XmlRootElement;
  * Abstract base class for a Datalink Address.
  */
 @XmlRootElement
-public abstract class DataLinkAddress implements Serializable {
+public abstract class DataLinkAddress implements Serializable, Cloneable {
     private static final long serialVersionUID = 1L;
     private String name;
 
@@ -33,14 +33,6 @@ public abstract class DataLinkAddress implements Serializable {
         this.name = name;
     }
 
-    /**
-     * Used to copy the DataLinkAddress in a polymorphic way.
-     *
-     * @return A clone of this DataLinkAddress
-     */
-    @Override
-    public abstract DataLinkAddress clone();
-
     /**
      * Allow to distinguish among different data link addresses.
      *
index 9032ac5a1604e270bc135be3b2e1246df6638147..21ca56a2408f8e2498269746d115105182e83b8e 100644 (file)
@@ -82,7 +82,7 @@ public enum EtherTypes {
 
     public static int getEtherTypeNumberInt(final String name) {
         if (name.matches(REGEX_NUMBER_STRING)) {
-            return Integer.valueOf(name);
+            return Integer.parseInt(name);
         }
         for (EtherTypes type : EtherTypes.values()) {
             if (type.description.equalsIgnoreCase(name)) {
index 75d2db4cadd1106b7cc0d8649462225968aadeb0..3b5302f7756ff04c6a56fcb4a52f0c3a55c649ad 100644 (file)
@@ -24,7 +24,7 @@ public class Ethernet extends Packet {
 
     // TODO: This has to be outside and it should be possible for osgi
     // to add new coming packet classes
-    public static final Map<Short, Class<? extends Packet>> ETHER_TYPE_CLASS_MAP = new HashMap<>();
+    private static final Map<Short, Class<? extends Packet>> ETHER_TYPE_CLASS_MAP = new HashMap<>();
 
     static {
         ETHER_TYPE_CLASS_MAP.put(EtherTypes.LLDP.shortValue(), LLDP.class);
index 01b3a3cf681234079f277209cb0fd43a9f4ca2a0..72433a6d89118d0a85cf16fe20ed168f0b856a6d 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.openflowplugin.libraries.liblldp;
 
 import java.util.Arrays;
+import java.util.Objects;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
@@ -19,8 +20,6 @@ import javax.xml.bind.annotation.XmlTransient;
 @XmlAccessorType(XmlAccessType.NONE)
 public class EthernetAddress extends DataLinkAddress {
     private static final long serialVersionUID = 1L;
-    @XmlTransient
-    private byte[] macAddress;
 
     public static final EthernetAddress BROADCASTMAC = createWellKnownAddress(new byte[] {
         (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff });
@@ -30,12 +29,11 @@ public class EthernetAddress extends DataLinkAddress {
     public static final String ADDRESS_NAME = "Ethernet MAC Address";
     public static final int SIZE = 6;
 
+    @XmlTransient
+    private byte[] macAddress;
+
     private static EthernetAddress createWellKnownAddress(final byte[] mac) {
-        try {
-            return new EthernetAddress(mac);
-        } catch (final ConstructionException ce) {
-            return null;
-        }
+        return new EthernetAddress(mac);
     }
 
     /* Private constructor to satisfy JAXB */
@@ -50,15 +48,13 @@ public class EthernetAddress extends DataLinkAddress {
      *
      * @param macAddress A byte array in big endian format representing the Ethernet MAC Address
      */
-    public EthernetAddress(final byte[] macAddress) throws ConstructionException {
+    public EthernetAddress(final byte[] macAddress) {
         super(ADDRESS_NAME);
 
-        if (macAddress == null) {
-            throw new ConstructionException("Null input parameter passed");
-        }
+        Objects.requireNonNull(macAddress);
 
         if (macAddress.length != SIZE) {
-            throw new ConstructionException(
+            throw new IllegalArgumentException(
                     "Wrong size of passed byte array, expected:" + SIZE
                             + " got:" + macAddress.length);
         }
@@ -69,21 +65,15 @@ public class EthernetAddress extends DataLinkAddress {
     @Override
     public EthernetAddress clone() {
         try {
-            return new EthernetAddress(this.macAddress.clone());
-        } catch (final ConstructionException ce) {
-            return null;
+            EthernetAddress cloned = (EthernetAddress)super.clone();
+            cloned.macAddress = this.macAddress.clone();
+            return cloned;
+        } catch (CloneNotSupportedException e) {
+            // This should never happen
+            throw new AssertionError(e);
         }
     }
 
-    /**
-     * Return the Ethernet Mac address in byte array format.
-     *
-     * @return The Ethernet Mac address in byte array format
-     */
-    public byte[] getValue() {
-        return this.macAddress;
-    }
-
     @Override
     public int hashCode() {
         final int prime = 31;
index e9d7a37bb44363455d86a3488a4d6827f3ec1852..56a02443dc632180b78e4784ce4b9ba880d0d6cf 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.openflowplugin.libraries.liblldp;
 
 import com.google.common.collect.Iterables;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -23,6 +24,7 @@ public class LLDP extends Packet {
     private static final String TTL = "TTL";
     private static final int LLDP_DEFAULT_TLVS = 3;
     private static final LLDPTLV EMPTY_TLV = new LLDPTLV().setLength((short) 0).setType((byte) 0);
+    @SuppressFBWarnings("MS_PKGPROTECT")
     public static final byte[] LLDP_MULTICAST_MAC = { 1, (byte) 0x80, (byte) 0xc2, 0, 0, (byte) 0xe };
 
     private Map<Byte, LLDPTLV> mandatoryTLVs;
index f5af1572e570833b7742fd85766a124c5f0abeae..9af1e74130a68ea84ee578aecbcf86bbeff56ca3 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.openflowplugin.libraries.liblldp;
 
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -29,21 +30,20 @@ public class LLDPTLV extends Packet {
     private static final int LLDPTLV_FIELDS = 3;
 
     /** OpenFlow OUI. */
-    public static final byte[] OFOUI = new byte[] { (byte) 0x00, (byte) 0x26,
-        (byte) 0xe1 };
+    static final byte[] OFOUI = new byte[] { (byte) 0x00, (byte) 0x26, (byte) 0xe1 };
 
     /** Length of Organizationally defined subtype field of TLV in bytes.   */
     private static final byte CUSTOM_TLV_SUB_TYPE_LENGTH = (byte)1;
 
     /** OpenFlow subtype: nodeConnectorId of source. */
-    public static final byte[] CUSTOM_TLV_SUB_TYPE_NODE_CONNECTOR_ID = new byte[] { 0 };
+    private static final byte[] CUSTOM_TLV_SUB_TYPE_NODE_CONNECTOR_ID = new byte[] { 0 };
 
     /** OpenFlow subtype: custom sec = hash code of verification of origin of LLDP. */
-    public static final byte[] CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC = new byte[] { 1 };
+    private static final byte[] CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC = new byte[] { 1 };
 
-    public static final int CUSTOM_TLV_OFFSET = OFOUI.length + CUSTOM_TLV_SUB_TYPE_LENGTH;
-    public static final byte[] CHASSISID_SUB_TYPE = new byte[] { 4 }; // MAC address for the system
-    public static final byte[] PORTID_SUB_TYPE = new byte[] { 7 }; // locally assigned
+    private static final int CUSTOM_TLV_OFFSET = OFOUI.length + CUSTOM_TLV_SUB_TYPE_LENGTH;
+    private static final byte[] CHASSISID_SUB_TYPE = new byte[] { 4 }; // MAC address for the system
+    private static final byte[] PORTID_SUB_TYPE = new byte[] { 7 }; // locally assigned
 
     public enum TLVType {
         Unknown((byte) 0), ChassisID((byte) 1), PortID((byte) 2), TTL((byte) 3), PortDesc(
@@ -211,8 +211,7 @@ public class LLDPTLV extends Packet {
      * @return the SystemName TLV value in byte array
      */
     public static byte[] createSystemNameTLVValue(final String nodeId) {
-        byte[] nid = nodeId.getBytes();
-        return nid;
+        return nodeId.getBytes(StandardCharsets.UTF_8);
     }
 
     /**
@@ -293,6 +292,16 @@ public class LLDPTLV extends Packet {
         return customValue;
     }
 
+    /**
+     * Creates a custom TLV value including OUI of sub type custom sec and custom bytes value.
+     *
+     * @param customValue the custom value
+     * @return the custom TLV value in byte array
+     */
+    public static byte[] createSecSubTypeCustomTLVValue(final byte[] customValue) {
+        return createCustomTLVValue(CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC, customValue);
+    }
+
     /**
      * Retrieves the string from TLV value and returns it in HexString format.
      *
@@ -368,4 +377,12 @@ public class LLDPTLV extends Packet {
         byte[] value = lldptlv.getValue();
         return BitBufferHelper.getByte(ArrayUtils.subarray(value, 3, 4));
     }
+
+    public static CustomTLVKey createPortSubTypeCustomTLVKey() throws BufferException {
+        return new CustomTLVKey(BitBufferHelper.getInt(OFOUI), CUSTOM_TLV_SUB_TYPE_NODE_CONNECTOR_ID[0]);
+    }
+
+    public static CustomTLVKey createSecSubTypeCustomTLVKey() throws BufferException {
+        return new CustomTLVKey(BitBufferHelper.getInt(LLDPTLV.OFOUI), LLDPTLV.CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC[0]);
+    }
 }
index debe526fba78fcc5ae9aa87bf9c87757ca8f21c5..59d135a5ae6a3702ae659fffbbbf0b2839e17abe 100644 (file)
@@ -396,7 +396,7 @@ public abstract class NetUtils {
             return false;
         }
         if (values.length >= 2) {
-            int prefix = Integer.valueOf(values[1]);
+            int prefix = Integer.parseInt(values[1]);
             if (prefix < 0 || prefix > 32) {
                 return false;
             }
@@ -429,7 +429,7 @@ public abstract class NetUtils {
         }
 
         if (values.length >= 2) {
-            int prefix = Integer.valueOf(values[1]);
+            int prefix = Integer.parseInt(values[1]);
             if (prefix < 0 || prefix > 128) {
                 return false;
             }
index 41daa33165cfab17c79d31905eb5fa165f783099..4183cc7c5d4455b293354eb899e80e405aea47bc 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.openflowplugin.libraries.liblldp;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Arrays;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -287,6 +288,7 @@ public abstract class Packet {
      *
      * @return The raw payload if not parsable as an array of bytes, null otherwise
      */
+    @SuppressFBWarnings("EI_EXPOSE_REP")
     public byte[] getRawPayload() {
         return rawPayload;
     }
@@ -326,6 +328,10 @@ public abstract class Packet {
 
     @Override
     public boolean equals(final Object obj) {
+        if (obj == null) {
+            return false;
+        }
+
         if (this == obj) {
             return true;
         }
@@ -339,14 +345,11 @@ public abstract class Packet {
         if (hdrFieldsMap == null || other.hdrFieldsMap == null) {
             return false;
         }
-        if (hdrFieldsMap != null && other.hdrFieldsMap != null) {
-            for (String field : hdrFieldsMap.keySet()) {
-                if (!Arrays.equals(hdrFieldsMap.get(field), other.hdrFieldsMap.get(field))) {
-                    return false;
-                }
+        for (Entry<String, byte[]> entry : hdrFieldsMap.entrySet()) {
+            String field = entry.getKey();
+            if (!Arrays.equals(entry.getValue(), other.hdrFieldsMap.get(field))) {
+                return false;
             }
-        } else {
-            return false;
         }
         return true;
     }
index 6a82a0b106cca6caddc58650aa0037c6c6516bc7..db92198dfc86dcfa4ad2df9cd912f0a337e9fa67 100644 (file)
  */
 package org.opendaylight.openflowplugin.libraries.sal.packet.address;
 
+import static org.junit.Assert.fail;
+
 import org.junit.Assert;
 import org.junit.Test;
-import org.opendaylight.openflowplugin.libraries.liblldp.ConstructionException;
 import org.opendaylight.openflowplugin.libraries.liblldp.EthernetAddress;
 
 public class EthernetAddressTest {
@@ -30,8 +31,8 @@ public class EthernetAddressTest {
             ea1 = new EthernetAddress((byte[]) null);
 
             // Exception is expected if NOT raised test will fail
-            Assert.assertTrue(false);
-        } catch (final ConstructionException e) {
+            fail("Expected NullPointerException");
+        } catch (final NullPointerException e) {
             // expected
         }
 
@@ -40,8 +41,8 @@ public class EthernetAddressTest {
             ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0 });
 
             // Exception is expected if NOT raised test will fail
-            Assert.assertTrue(false);
-        } catch (final ConstructionException e) {
+            fail("Expected IllegalArgumentException");
+        } catch (final IllegalArgumentException e) {
             // expected
         }
 
@@ -51,65 +52,42 @@ public class EthernetAddressTest {
                 (byte) 0x0, (byte) 0x0, (byte) 0x0 });
 
             // Exception is expected if NOT raised test will fail
-            Assert.assertTrue(false);
-        } catch (final ConstructionException e) {
+            fail("Expected IllegalArgumentException");
+        } catch (final IllegalArgumentException e) {
             // expected
         }
     }
 
     @Test
     public void testEquality() {
-        EthernetAddress ea1;
-        EthernetAddress ea2;
-        try {
-            ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
-                (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
-
-            ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
-                (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
-            Assert.assertTrue(ea1.equals(ea2));
-        } catch (final ConstructionException e) {
-            // Exception is NOT expected if raised test will fail
-            Assert.assertTrue(false);
-        }
+        EthernetAddress ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
+            (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
 
-        try {
-            ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
-                (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
-
-            ea2 = ea1.clone();
-            Assert.assertTrue(ea1.equals(ea2));
-        } catch (final ConstructionException e) {
-            // Exception is NOT expected if raised test will fail
-            Assert.assertTrue(false);
-        }
+        EthernetAddress ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
+            (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
+        Assert.assertTrue(ea1.equals(ea2));
+
+        ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
+            (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
+
+        ea2 = ea1.clone();
+        Assert.assertTrue(ea1.equals(ea2));
 
         // Check for well knowns
-        try {
-            ea1 = EthernetAddress.BROADCASTMAC;
-            ea2 = new EthernetAddress(new byte[] { (byte) 0xff, (byte) 0xff,
-                (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff });
-            Assert.assertTrue(ea1.equals(ea2));
-        } catch (final ConstructionException e) {
-            // Exception is NOT expected if raised test will fail
-            Assert.assertTrue(false);
-        }
+
+        ea1 = EthernetAddress.BROADCASTMAC;
+        ea2 = new EthernetAddress(new byte[] { (byte) 0xff, (byte) 0xff,
+            (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff });
+        Assert.assertTrue(ea1.equals(ea2));
     }
 
     @Test
     public void testUnEquality() {
-        EthernetAddress ea1;
-        EthernetAddress ea2;
-        try {
-            ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
-                (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2 });
-
-            ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
-                (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
-            Assert.assertTrue(!ea1.equals(ea2));
-        } catch (final ConstructionException e) {
-            // Exception is NOT expected if raised test will fail
-            Assert.assertTrue(false);
-        }
+        EthernetAddress ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
+            (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2 });
+
+        EthernetAddress ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
+            (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
+        Assert.assertTrue(!ea1.equals(ea2));
     }
 }