From 39575d55d0304aed388812885615ffbdfb7f27dc Mon Sep 17 00:00:00 2001 From: Fabio Lima Date: Sun, 7 Jul 2024 03:00:44 -0300 Subject: [PATCH] Improve code quality Remove code flaws detected by PMD. PMD Rules: * NP_LOAD_OF_KNOWN_NULL_VALUE * DCN_NULLPOINTER_EXCEPTION --- .../com/github/f4b6a3/uuid/codec/StandardStringCodec.java | 2 +- src/main/java/com/github/f4b6a3/uuid/util/UuidValidator.java | 2 +- .../com/github/f4b6a3/uuid/util/internal/NetworkUtil.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/f4b6a3/uuid/codec/StandardStringCodec.java b/src/main/java/com/github/f4b6a3/uuid/codec/StandardStringCodec.java index 359d28f0..c85fba6b 100644 --- a/src/main/java/com/github/f4b6a3/uuid/codec/StandardStringCodec.java +++ b/src/main/java/com/github/f4b6a3/uuid/codec/StandardStringCodec.java @@ -167,7 +167,7 @@ public String encode(UUID uuid) { public UUID decode(final String string) { if (string == null) { - throw InvalidUuidException.newInstance(string); + throw InvalidUuidException.newInstance(null); } final String modified = modify(string); diff --git a/src/main/java/com/github/f4b6a3/uuid/util/UuidValidator.java b/src/main/java/com/github/f4b6a3/uuid/util/UuidValidator.java index 325ea03e..ec1966d6 100644 --- a/src/main/java/com/github/f4b6a3/uuid/util/UuidValidator.java +++ b/src/main/java/com/github/f4b6a3/uuid/util/UuidValidator.java @@ -146,7 +146,7 @@ public static boolean isValid(final char[] uuid, int version) { */ public static void validate(final UUID uuid) { if (uuid == null) { - throw InvalidUuidException.newInstance(uuid); + throw InvalidUuidException.newInstance(null); } } diff --git a/src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java b/src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java index 7aaf63ee..a0856d0d 100644 --- a/src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java +++ b/src/main/java/com/github/f4b6a3/uuid/util/internal/NetworkUtil.java @@ -103,7 +103,7 @@ public static synchronized String mac(NetworkInterface nic) { } try { - if (nic != null) { + if (nic != null && nic.getHardwareAddress() != null) { byte[] ha = nic.getHardwareAddress(); String[] hex = new String[ha.length]; for (int i = 0; i < ha.length; i++) { @@ -112,7 +112,7 @@ public static synchronized String mac(NetworkInterface nic) { mac = String.join("-", hex); return mac; } - } catch (SocketException | NullPointerException e) { + } catch (SocketException e) { return null; }