This is an automated email from the ASF dual-hosted git repository.

tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new 20d5d4221b ARTEMIS-5533 use Objects.requireNonNull() where sensible
20d5d4221b is described below

commit 20d5d4221b4d32b3b405a242d68781cde7ff313d
Author: Justin Bertram <[email protected]>
AuthorDate: Tue Jun 10 16:26:22 2025 -0500

    ARTEMIS-5533 use Objects.requireNonNull() where sensible
---
 .../core/server/ActiveMQScheduledComponent.java    |  3 +-
 .../artemis/json/impl/JsonArrayBuilderImpl.java    | 12 +++--
 .../artemis/json/impl/JsonObjectBuilderImpl.java   | 12 +++--
 .../activemq/artemis/json/impl/JsonValueImpl.java  | 12 +++--
 .../activemq/artemis/utils/Preconditions.java      | 52 ----------------------
 .../apache/activemq/artemis/utils/Suppliers.java   |  5 +--
 .../utils/collections/ConcurrentLongHashMap.java   | 14 +++---
 .../utils/collections/ConcurrentLongHashSet.java   |  7 ++-
 .../artemis/utils/collections/LinkedListImpl.java  |  4 +-
 .../artemis/utils/collections/TypedProperties.java |  5 +--
 .../activemq/artemis/utils/uri/URIFactory.java     | 32 +++----------
 .../core/client/impl/ServerLocatorImpl.java        |  6 +--
 .../FederationAddressPolicyConfiguration.java      |  5 +--
 .../config/federation/FederationPolicySet.java     |  3 +-
 .../FederationQueuePolicyConfiguration.java        |  3 +-
 .../FederationTransformerConfiguration.java        |  5 +--
 .../artemis/core/message/impl/CoreMessage.java     |  5 +--
 .../wireformat/FederationStreamConnectMessage.java |  4 +-
 .../core/remoting/impl/netty/NettyConnection.java  |  9 ++--
 .../activemq/artemis/core/security/Role.java       |  6 +--
 .../activemq/artemis/reader/BytesMessageUtil.java  |  6 +--
 .../activemq/artemis/reader/StreamMessageUtil.java | 22 ++++-----
 .../artemis/utils/ActiveMQBufferInputStream.java   |  6 +--
 .../artemis/jms/client/ActiveMQMessage.java        | 21 ++++-----
 .../core/io/mapped/MappedSequentialFile.java       | 21 +++------
 .../artemis/core/journal/impl/JournalFileImpl.java | 11 ++---
 .../artemis/core/journal/impl/JournalRecord.java   |  6 +--
 .../artemis/junit/EmbeddedJMSDelegate.java         |  5 +--
 .../artemis/protocol/amqp/broker/AMQPMessage.java  |  6 +--
 .../amqp/connect/mirror/AckManagerProvider.java    |  6 +--
 .../sasl/scram/ScramClientFunctionalityImpl.java   | 16 ++-----
 .../sasl/scram/ScramServerFunctionalityImpl.java   | 15 ++-----
 .../artemis/protocol/amqp/util/NettyReadable.java  | 10 ++---
 .../activemq/artemis/ra/ActiveMQRAMessage.java     | 13 ++----
 .../artemis/core/paging/impl/PagingStoreImpl.java  | 17 +++----
 .../core/persistence/config/PersistedRole.java     | 10 ++---
 .../impl/journal/codec/DuplicateIDEncoding.java    | 11 ++---
 .../codec/PersistentAddressBindingEncoding.java    | 12 ++---
 .../BackupReplicationStartFailedMessage.java       |  8 +---
 .../core/server/cluster/quorum/QuorumManager.java  |  9 +---
 .../core/server/impl/QueueMessageMetrics.java      |  8 ++--
 .../core/server/impl/ServerConsumerImpl.java       |  7 ++-
 .../artemis/core/server/replay/ReplayManager.java  |  5 +--
 .../spi/core/protocol/MessagePersister.java        |  5 +--
 .../spi/core/security/scram/ScramUtils.java        |  7 +--
 .../org/apache/activemq/broker/BrokerService.java  |  5 +--
 .../transport/amqp/client/AmqpFrameValidator.java  |  5 +--
 .../transport/amqp/client/AmqpValidator.java       |  5 +--
 .../integration/cluster/util/BackupSyncDelay.java  |  9 ++--
 .../jms/tests/message/SimpleJMSBytesMessage.java   |  5 +--
 .../jms/tests/message/SimpleJMSMapMessage.java     | 10 +----
 .../jms/tests/message/SimpleJMSStreamMessage.java  | 46 ++++++++-----------
 52 files changed, 173 insertions(+), 379 deletions(-)

diff --git 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQScheduledComponent.java
 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQScheduledComponent.java
index e0438f8a7a..31089a7ad0 100644
--- 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQScheduledComponent.java
+++ 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQScheduledComponent.java
@@ -18,6 +18,7 @@ package org.apache.activemq.artemis.core.server;
 
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.Objects;
 import java.util.concurrent.Executor;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.ScheduledExecutorService;
@@ -227,7 +228,7 @@ public abstract class ActiveMQScheduledComponent implements 
ActiveMQComponent, R
    }
 
    public synchronized ActiveMQScheduledComponent setPeriod(long period, 
TimeUnit unit) {
-      if (unit == null) throw new NullPointerException("unit is required");
+      Objects.requireNonNull(unit, "unit is required");
       if (this.period != period || this.timeUnit != unit) {
          this.period = period;
          this.timeUnit = unit;
diff --git 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonArrayBuilderImpl.java
 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonArrayBuilderImpl.java
index 55423190e5..39d0d6f62d 100644
--- 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonArrayBuilderImpl.java
+++ 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonArrayBuilderImpl.java
@@ -16,16 +16,15 @@
  */
 package org.apache.activemq.artemis.json.impl;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Objects;
+
 import org.apache.activemq.artemis.json.JsonArray;
 import org.apache.activemq.artemis.json.JsonArrayBuilder;
 import org.apache.activemq.artemis.json.JsonObjectBuilder;
 import org.apache.activemq.artemis.json.JsonValue;
 
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
-
 public class JsonArrayBuilderImpl implements JsonArrayBuilder {
 
    private final javax.json.JsonArrayBuilder rawArrayBuilder;
@@ -35,8 +34,7 @@ public class JsonArrayBuilderImpl implements JsonArrayBuilder 
{
    }
 
    public JsonArrayBuilderImpl(javax.json.JsonArrayBuilder rawArrayBuilder) {
-      checkNotNull(rawArrayBuilder);
-      this.rawArrayBuilder = rawArrayBuilder;
+      this.rawArrayBuilder = Objects.requireNonNull(rawArrayBuilder);
    }
 
    @Override
diff --git 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonObjectBuilderImpl.java
 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonObjectBuilderImpl.java
index c9ffcd6565..feb5182d50 100644
--- 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonObjectBuilderImpl.java
+++ 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonObjectBuilderImpl.java
@@ -16,16 +16,15 @@
  */
 package org.apache.activemq.artemis.json.impl;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Objects;
+
 import org.apache.activemq.artemis.json.JsonArrayBuilder;
 import org.apache.activemq.artemis.json.JsonObject;
 import org.apache.activemq.artemis.json.JsonObjectBuilder;
 import org.apache.activemq.artemis.json.JsonValue;
 
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
-
 public class JsonObjectBuilderImpl implements JsonObjectBuilder {
 
    private final javax.json.JsonObjectBuilder rawObjectBuilder;
@@ -35,8 +34,7 @@ public class JsonObjectBuilderImpl implements 
JsonObjectBuilder {
    }
 
    public JsonObjectBuilderImpl(javax.json.JsonObjectBuilder rawObjectBuilder) 
{
-      checkNotNull(rawObjectBuilder);
-      this.rawObjectBuilder = rawObjectBuilder;
+      this.rawObjectBuilder = Objects.requireNonNull(rawObjectBuilder);
    }
 
    @Override
diff --git 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonValueImpl.java
 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonValueImpl.java
index bb815a0a69..57ad134e56 100644
--- 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonValueImpl.java
+++ 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/json/impl/JsonValueImpl.java
@@ -16,14 +16,13 @@
  */
 package org.apache.activemq.artemis.json.impl;
 
-import org.apache.activemq.artemis.json.JsonArray;
-import org.apache.activemq.artemis.json.JsonObject;
-import org.apache.activemq.artemis.json.JsonValue;
-
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
+import org.apache.activemq.artemis.json.JsonArray;
+import org.apache.activemq.artemis.json.JsonObject;
+import org.apache.activemq.artemis.json.JsonValue;
 
 public class JsonValueImpl implements JsonValue {
 
@@ -78,8 +77,7 @@ public class JsonValueImpl implements JsonValue {
    }
 
    public JsonValueImpl(javax.json.JsonValue rawValue) {
-      checkNotNull(rawValue);
-      this.rawValue = rawValue;
+      this.rawValue = Objects.requireNonNull(rawValue);
    }
 
 
diff --git 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Preconditions.java
 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Preconditions.java
index 5252133fe5..21026186ae 100644
--- 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Preconditions.java
+++ 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Preconditions.java
@@ -18,58 +18,6 @@ package org.apache.activemq.artemis.utils;
 
 public class Preconditions {
 
-   /**
-    * Ensures that an object reference passed as a parameter to the calling 
method is not null.
-    *
-    * @param reference an object reference
-    * @return the non-null reference that was validated
-    * @throws NullPointerException if {@code reference} is null
-    */
-   public static <T> T checkNotNull(T reference) {
-      if (reference == null) {
-         throw new NullPointerException();
-      }
-      return reference;
-   }
-
-   /**
-    * Ensures the truth of an expression involving one or more parameters to 
the calling method.
-    *
-    * @param expression   a boolean expression
-    * @param errorMessage the exception message to use if the check fails; 
will be converted to a string using
-    *                     {@link String#valueOf(Object)}
-    * @throws IllegalArgumentException if {@code expression} is false
-    */
-   public static void checkArgument(boolean expression, Object errorMessage) {
-      if (!expression) {
-         throw new IllegalArgumentException(String.valueOf(errorMessage));
-      }
-   }
-
-   /**
-    * Ensures the truth of an expression involving one or more parameters to 
the calling method.
-    *
-    * @param expression           a boolean expression
-    * @param errorMessageTemplate a template for the exception message should 
the check fail. The message is formed by
-    *                             replacing each {@code %s} placeholder in the 
template with an argument. These are
-    *                             matched by position - the first {@code %s} 
gets {@code errorMessageArgs[0]}, etc.
-    *                             Unmatched arguments will be appended to the 
formatted message in square braces.
-    *                             Unmatched placeholders will be left as-is.
-    * @param errorMessageArgs     the arguments to be substituted into the 
message template. Arguments are converted to
-    *                             strings using {@link String#valueOf(Object)}.
-    * @throws IllegalArgumentException if {@code expression} is false
-    * @throws NullPointerException     if the check fails and either {@code 
errorMessageTemplate} or
-    *                                  {@code errorMessageArgs} is null (don't 
let this happen)
-    */
-   public static void checkArgument(
-         boolean expression,
-         String errorMessageTemplate,
-         Object... errorMessageArgs) {
-      if (!expression) {
-         throw new 
IllegalArgumentException(String.format(errorMessageTemplate, errorMessageArgs));
-      }
-   }
-
    /**
     * Ensures the truth of an expression involving one or more parameters to 
the calling method.
     *
diff --git 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Suppliers.java
 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Suppliers.java
index 023f9d7396..77f383d555 100644
--- 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Suppliers.java
+++ 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Suppliers.java
@@ -20,10 +20,9 @@
 package org.apache.activemq.artemis.utils;
 
 import java.io.Serializable;
+import java.util.Objects;
 import java.util.function.Supplier;
 
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
-
 public class Suppliers {
 
    /**
@@ -40,7 +39,7 @@ public class Suppliers {
    public static <T> Supplier<T> memoize(Supplier<T> delegate) {
       return (delegate instanceof MemoizingSupplier)
             ? delegate
-            : new MemoizingSupplier<T>(checkNotNull(delegate));
+            : new MemoizingSupplier<T>(Objects.requireNonNull(delegate));
    }
 
    private static class MemoizingSupplier<T> implements Supplier<T>, 
Serializable {
diff --git 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/ConcurrentLongHashMap.java
 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/ConcurrentLongHashMap.java
index 6fef04fc7b..831a22da9a 100644
--- 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/ConcurrentLongHashMap.java
+++ 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/ConcurrentLongHashMap.java
@@ -19,12 +19,12 @@ package org.apache.activemq.artemis.utils.collections;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 import java.util.concurrent.locks.StampedLock;
 import java.util.function.LongFunction;
 
-import static org.apache.activemq.artemis.utils.Preconditions.checkArgument;
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
+import org.apache.activemq.artemis.utils.Preconditions;
 
 /**
  * Map from long to an Object.
@@ -57,7 +57,7 @@ public class ConcurrentLongHashMap<V> {
    }
 
    public ConcurrentLongHashMap(int expectedItems, int numSections) {
-      checkArgument(numSections > 0);
+      Preconditions.checkArgument(numSections > 0);
       if (expectedItems < numSections) {
          expectedItems = numSections;
       }
@@ -121,19 +121,19 @@ public class ConcurrentLongHashMap<V> {
    }
 
    public V put(long key, V value) {
-      checkNotNull(value);
+      Objects.requireNonNull(value);
       long h = hash(key);
       return getSection(h).put(key, value, (int) h, false, null);
    }
 
    public V putIfAbsent(long key, V value) {
-      checkNotNull(value);
+      Objects.requireNonNull(value);
       long h = hash(key);
       return getSection(h).put(key, value, (int) h, true, null);
    }
 
    public V computeIfAbsent(long key, LongFunction<V> provider) {
-      checkNotNull(provider);
+      Objects.requireNonNull(provider);
       long h = hash(key);
       return getSection(h).put(key, null, (int) h, true, provider);
    }
@@ -144,7 +144,7 @@ public class ConcurrentLongHashMap<V> {
    }
 
    public boolean remove(long key, Object value) {
-      checkNotNull(value);
+      Objects.requireNonNull(value);
       long h = hash(key);
       return getSection(h).remove(key, value, (int) h) != null;
    }
diff --git 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/ConcurrentLongHashSet.java
 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/ConcurrentLongHashSet.java
index 1cac4cc8e5..59d1c31eb2 100644
--- 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/ConcurrentLongHashSet.java
+++ 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/ConcurrentLongHashSet.java
@@ -16,17 +16,16 @@
  */
 package org.apache.activemq.artemis.utils.collections;
 
+import java.lang.invoke.MethodHandles;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 import java.util.concurrent.locks.StampedLock;
 
+import org.apache.activemq.artemis.utils.Preconditions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import java.lang.invoke.MethodHandles;
-
-import static org.apache.activemq.artemis.utils.Preconditions.checkArgument;
 
 /**
  * Concurrent hash set for primitive longs
@@ -63,7 +62,7 @@ public class ConcurrentLongHashSet {
    }
 
    public ConcurrentLongHashSet(int expectedItems, final int numSections) {
-      checkArgument(numSections > 0);
+      Preconditions.checkArgument(numSections > 0);
       if (expectedItems < numSections) {
          expectedItems = numSections;
       }
diff --git 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/LinkedListImpl.java
 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/LinkedListImpl.java
index 9eadd1be08..b88a6a82ba 100644
--- 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/LinkedListImpl.java
+++ 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/LinkedListImpl.java
@@ -204,9 +204,7 @@ public class LinkedListImpl<E> implements LinkedList<E> {
 
       logger.trace("**** addSorted element {}", e);
 
-      if (comparator == null) {
-         throw new NullPointerException("comparator=null");
-      }
+      Objects.requireNonNull(comparator, "comparator=null");
 
       if (size == 0) {
          logger.trace("adding head as there are no elements {}", e);
diff --git 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/TypedProperties.java
 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/TypedProperties.java
index f3c4bea74c..d8d8c84db9 100644
--- 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/TypedProperties.java
+++ 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/TypedProperties.java
@@ -216,10 +216,7 @@ public class TypedProperties {
    }
 
    public Character getCharProperty(final SimpleString key) throws 
ActiveMQPropertyConversionException {
-      Object value = doGetProperty(key);
-      if (value == null) {
-         throw new NullPointerException("Invalid conversion: " + key);
-      }
+      Object value = Objects.requireNonNull(doGetProperty(key), "Invalid 
conversion: " + key);
 
       if (value instanceof Character character) {
          return character;
diff --git 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URIFactory.java
 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URIFactory.java
index 1e12b81777..7b8ef273db 100644
--- 
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URIFactory.java
+++ 
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URIFactory.java
@@ -20,6 +20,7 @@ package org.apache.activemq.artemis.utils.uri;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Map;
+import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 
 public class URIFactory<T, P> {
@@ -50,23 +51,11 @@ public class URIFactory<T, P> {
    }
 
    public T newObject(URI uri, P param) throws Exception {
-      URISchema<T, P> schemaFactory = schemas.get(uri.getScheme());
-
-      if (schemaFactory == null) {
-         throw new NullPointerException("Schema " + uri.getScheme() + " not 
found");
-      }
-
-      return schemaFactory.newObject(uri, param);
+      return Objects.requireNonNull(schemas.get(uri.getScheme()), "Schema " + 
uri.getScheme() + " not found").newObject(uri, param);
    }
 
    public T newObject(URI uri, Map<String, String> overrides, P param) throws 
Exception {
-      URISchema<T, P> schemaFactory = schemas.get(uri.getScheme());
-
-      if (schemaFactory == null) {
-         throw new NullPointerException("Schema " + uri.getScheme() + " not 
found");
-      }
-
-      return schemaFactory.newObject(uri, overrides, param);
+      return Objects.requireNonNull(schemas.get(uri.getScheme()), "Schema " + 
uri.getScheme() + " not found").newObject(uri, overrides, param);
    }
 
    public T newObject(String uri, P param) throws Exception {
@@ -74,13 +63,7 @@ public class URIFactory<T, P> {
    }
 
    public void populateObject(URI uri, T bean) throws Exception {
-      URISchema<T, P> schemaFactory = schemas.get(uri.getScheme());
-
-      if (schemaFactory == null) {
-         throw new NullPointerException("Schema " + uri.getScheme() + " not 
found");
-      }
-
-      schemaFactory.populateObject(uri, bean);
+      Objects.requireNonNull(schemas.get(uri.getScheme()), "Schema " + 
uri.getScheme() + " not found").populateObject(uri, bean);
    }
 
    public void populateObject(String uri, T bean) throws Exception {
@@ -88,12 +71,7 @@ public class URIFactory<T, P> {
    }
 
    public URI createSchema(String scheme, T bean) throws Exception {
-      URISchema<T, P> schemaFactory = schemas.get(scheme);
-
-      if (schemaFactory == null) {
-         throw new NullPointerException("Schema " + scheme + " not found");
-      }
-      return schemaFactory.newURI(bean);
+      return Objects.requireNonNull(schemas.get(scheme), "Schema " + scheme + 
" not found").newURI(bean);
    }
 
    /**
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java
index 0c0960d3be..d770b0883a 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java
@@ -28,6 +28,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
@@ -524,10 +525,7 @@ public final class ServerLocatorImpl implements 
ServerLocatorInternal, Discovery
 
    @Override
    public ClientProtocolManager newProtocolManager() {
-      if (threadPool == null) {
-         throw new NullPointerException("No Thread Pool");
-      }
-      return getProtocolManagerFactory().newProtocolManager().setExecutor(new 
OrderedExecutor(threadPool));
+      return getProtocolManagerFactory().newProtocolManager().setExecutor(new 
OrderedExecutor(Objects.requireNonNull(threadPool, "No Thread Pool")));
    }
 
    @Override
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationAddressPolicyConfiguration.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationAddressPolicyConfiguration.java
index 16f2c13e3f..554bd71e9c 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationAddressPolicyConfiguration.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationAddressPolicyConfiguration.java
@@ -22,7 +22,6 @@ import java.util.Objects;
 import java.util.Set;
 
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
-import org.apache.activemq.artemis.utils.Preconditions;
 
 public class FederationAddressPolicyConfiguration implements 
FederationPolicy<FederationAddressPolicyConfiguration>, Serializable {
 
@@ -121,7 +120,7 @@ public class FederationAddressPolicyConfiguration 
implements FederationPolicy<Fe
 
    @Override
    public void encode(ActiveMQBuffer buffer) {
-      Preconditions.checkArgument(name != null, "name can not be null");
+      Objects.requireNonNull(name, "name can not be null");
       buffer.writeString(name);
       buffer.writeNullableBoolean(autoDelete);
       buffer.writeNullableLong(autoDeleteDelay);
@@ -209,7 +208,7 @@ public class FederationAddressPolicyConfiguration 
implements FederationPolicy<Fe
       }
 
       public void encode(ActiveMQBuffer buffer) {
-         Preconditions.checkArgument(addressMatch != null, "addressMatch can 
not be null");
+         Objects.requireNonNull(addressMatch, "addressMatch can not be null");
          buffer.writeString(addressMatch);
       }
 
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationPolicySet.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationPolicySet.java
index 918ed9a048..58dea4dc87 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationPolicySet.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationPolicySet.java
@@ -23,7 +23,6 @@ import java.util.Objects;
 import java.util.Set;
 
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
-import org.apache.activemq.artemis.utils.Preconditions;
 
 public class FederationPolicySet implements 
FederationPolicy<FederationPolicySet>, Serializable {
 
@@ -77,7 +76,7 @@ public class FederationPolicySet implements 
FederationPolicy<FederationPolicySet
 
    @Override
    public void encode(ActiveMQBuffer buffer) {
-      Preconditions.checkArgument(name != null, "name can not be null");
+      Objects.requireNonNull(name, "name can not be null");
       buffer.writeString(name);
 
       buffer.writeInt(policyRefs == null ? 0 : policyRefs.size());
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationQueuePolicyConfiguration.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationQueuePolicyConfiguration.java
index 116d405a87..fc74f11efd 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationQueuePolicyConfiguration.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationQueuePolicyConfiguration.java
@@ -22,7 +22,6 @@ import java.util.Objects;
 import java.util.Set;
 
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
-import org.apache.activemq.artemis.utils.Preconditions;
 
 public class FederationQueuePolicyConfiguration implements 
FederationPolicy<FederationQueuePolicyConfiguration>, Serializable {
 
@@ -91,7 +90,7 @@ public class FederationQueuePolicyConfiguration implements 
FederationPolicy<Fede
 
    @Override
    public void encode(ActiveMQBuffer buffer) {
-      Preconditions.checkArgument(name != null, "name can not be null");
+      Objects.requireNonNull(name, "name can not be null");
       buffer.writeString(name);
       buffer.writeBoolean(includeFederated);
       buffer.writeNullableInt(priorityAdjustment);
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationTransformerConfiguration.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationTransformerConfiguration.java
index cef6fd19bc..4b2f4fa104 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationTransformerConfiguration.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/config/federation/FederationTransformerConfiguration.java
@@ -22,7 +22,6 @@ import java.util.Objects;
 
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
 import org.apache.activemq.artemis.core.config.TransformerConfiguration;
-import org.apache.activemq.artemis.utils.Preconditions;
 
 public class FederationTransformerConfiguration implements Serializable {
 
@@ -65,8 +64,8 @@ public class FederationTransformerConfiguration implements 
Serializable {
 
 
    public void encode(ActiveMQBuffer buffer) {
-      Preconditions.checkArgument(name != null, "name can not be null");
-      Preconditions.checkArgument(transformerConfiguration != null, 
"transformerConfiguration can not be null");
+      Objects.requireNonNull(name, "name can not be null");
+      Objects.requireNonNull(transformerConfiguration, 
"transformerConfiguration can not be null");
       buffer.writeString(name);
 
       buffer.writeString(transformerConfiguration.getClassName());
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
index c5d822175f..341245a26a 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
@@ -1190,12 +1190,9 @@ public class CoreMessage extends RefCountMessage 
implements ICoreMessage {
          return properties.containsProperty(key);
       }
       synchronized (this) {
-         final ByteBuf buffer = this.buffer;
+         final ByteBuf buffer = Objects.requireNonNull(this.buffer, "buffer 
cannot be null");
          // acquiring the lock here, although heavy-weight, is the safer way 
to do this,
          // because we cannot trust that a racing thread won't modify buffer
-         if (buffer == null) {
-            throw new NullPointerException("buffer cannot be null");
-         }
          final int propertiesLocation = this.propertiesLocation;
          if (propertiesLocation < 0) {
             throw new IllegalStateException("propertiesLocation = " + 
propertiesLocation);
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/wireformat/FederationStreamConnectMessage.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/wireformat/FederationStreamConnectMessage.java
index 64bf82365f..dd5970769f 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/wireformat/FederationStreamConnectMessage.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/wireformat/FederationStreamConnectMessage.java
@@ -18,6 +18,7 @@ package 
org.apache.activemq.artemis.core.protocol.core.impl.wireformat;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
 import 
org.apache.activemq.artemis.core.config.FederationConfiguration.Credentials;
@@ -26,7 +27,6 @@ import 
org.apache.activemq.artemis.core.config.federation.FederationStreamConfig
 import 
org.apache.activemq.artemis.core.config.federation.FederationTransformerConfiguration;
 import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;
 import org.apache.activemq.artemis.utils.ClassloadingUtil;
-import org.apache.activemq.artemis.utils.Preconditions;
 
 public abstract class FederationStreamConnectMessage <T extends 
FederationStreamConfiguration> extends PacketImpl {
 
@@ -85,7 +85,7 @@ public abstract class FederationStreamConnectMessage <T 
extends FederationStream
 
    @Override
    public void encodeRest(ActiveMQBuffer buffer) {
-      Preconditions.checkNotNull(streamConfiguration);
+      Objects.requireNonNull(streamConfiguration);
 
       super.encodeRest(buffer);
       buffer.writeString(name);
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
index 363767d059..9572c666f2 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
@@ -16,10 +16,12 @@
  */
 package org.apache.activemq.artemis.core.remoting.impl.netty;
 
+import java.lang.invoke.MethodHandles;
 import java.net.SocketAddress;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.LockSupport;
 
@@ -46,9 +48,6 @@ import org.apache.activemq.artemis.utils.Env;
 import org.apache.activemq.artemis.utils.IPV6Util;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import java.lang.invoke.MethodHandles;
-
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
 
 public class NettyConnection implements Connection {
 
@@ -79,11 +78,9 @@ public class NettyConnection implements Connection {
                           final BaseConnectionLifeCycleListener<?> listener,
                           boolean batchingEnabled,
                           boolean directDeliver) {
-      checkNotNull(channel);
-
       this.configuration = configuration;
 
-      this.channel = channel;
+      this.channel = Objects.requireNonNull(channel);
 
       this.listener = listener;
 
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/security/Role.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/security/Role.java
index 2876ec7bdc..ce5e0d30ab 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/security/Role.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/security/Role.java
@@ -18,6 +18,7 @@ package org.apache.activemq.artemis.core.security;
 
 import org.apache.activemq.artemis.json.JsonObject;
 import java.io.Serializable;
+import java.util.Objects;
 
 import org.apache.activemq.artemis.utils.JsonLoader;
 
@@ -123,10 +124,7 @@ public class Role implements Serializable {
                final boolean deleteAddress,
                final boolean view,
                final boolean edit) {
-      if (name == null) {
-         throw new NullPointerException("name is null");
-      }
-      this.name = name;
+      this.name = Objects.requireNonNull(name, "name is null");
       this.send = send;
       this.consume = consume;
       this.createAddress = createAddress;
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/reader/BytesMessageUtil.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/reader/BytesMessageUtil.java
index 0e8d6c8876..e53d53921a 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/reader/BytesMessageUtil.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/reader/BytesMessageUtil.java
@@ -16,6 +16,8 @@
  */
 package org.apache.activemq.artemis.reader;
 
+import java.util.Objects;
+
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
 
 public class BytesMessageUtil extends MessageUtil {
@@ -131,9 +133,7 @@ public class BytesMessageUtil extends MessageUtil {
     * {@return {@code true} if it could send the Object to any known format}
     */
    public static boolean bytesWriteObject(ActiveMQBuffer message, Object 
value) {
-      if (value == null) {
-         throw new NullPointerException("Attempt to write a null value");
-      }
+      Objects.requireNonNull(value, "Attempt to write a null value");
       if (value instanceof String string) {
          bytesWriteUTF(message, string);
       } else if (value instanceof Boolean booleanValue) {
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/reader/StreamMessageUtil.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/reader/StreamMessageUtil.java
index cd20f86d0e..b37bce98cd 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/reader/StreamMessageUtil.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/reader/StreamMessageUtil.java
@@ -16,6 +16,8 @@
  */
 package org.apache.activemq.artemis.reader;
 
+import java.util.Objects;
+
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
 import org.apache.activemq.artemis.api.core.Pair;
 import org.apache.activemq.artemis.utils.DataConstants;
@@ -73,20 +75,14 @@ public class StreamMessageUtil extends MessageUtil {
    }
 
    public static char streamReadChar(ActiveMQBuffer buff) {
-      byte type = buff.readByte();
-      switch (type) {
-         case DataConstants.CHAR:
-            return (char) buff.readShort();
-         case DataConstants.STRING:
-            String str = buff.readNullableString();
-            if (str == null) {
-               throw new NullPointerException("Invalid conversion");
-            } else {
-               throw new IllegalStateException("Invalid conversion");
-            }
-         default:
+      return switch (buff.readByte()) {
+         case DataConstants.CHAR -> (char) buff.readShort();
+         case DataConstants.STRING -> {
+            Objects.requireNonNull(buff.readNullableString(), "Invalid 
conversion");
             throw new IllegalStateException("Invalid conversion");
-      }
+         }
+         default -> throw new IllegalStateException("Invalid conversion");
+      };
 
    }
 
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ActiveMQBufferInputStream.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ActiveMQBufferInputStream.java
index bc525ac536..8db454be42 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ActiveMQBufferInputStream.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ActiveMQBufferInputStream.java
@@ -18,6 +18,7 @@ package org.apache.activemq.artemis.utils;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Objects;
 
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
 
@@ -60,9 +61,8 @@ public class ActiveMQBufferInputStream extends InputStream {
          throw new IOException("read on a closed InputStream");
       }
 
-      if (byteArray == null) {
-         throw new NullPointerException();
-      }
+      Objects.requireNonNull(byteArray);
+
       if (off < 0 || off > byteArray.length || len < 0 || off + len > 
byteArray.length || off + len < 0) {
          throw new IndexOutOfBoundsException();
       }
diff --git 
a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
 
b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
index 5f22d8d033..6131982c59 100644
--- 
a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
+++ 
b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
@@ -16,13 +16,6 @@
  */
 package org.apache.activemq.artemis.jms.client;
 
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
 import javax.jms.DeliveryMode;
 import javax.jms.Destination;
 import javax.jms.IllegalStateException;
@@ -37,17 +30,24 @@ import javax.management.openmbean.CompositeDataSupport;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.OutputStream;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
 
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
 import org.apache.activemq.artemis.api.core.ActiveMQException;
 import 
org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException;
+import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.core.client.ClientMessage;
 import org.apache.activemq.artemis.api.core.client.ClientSession;
 import org.apache.activemq.artemis.api.jms.ActiveMQJMSConstants;
 import org.apache.activemq.artemis.core.client.ActiveMQClientMessageBundle;
 import org.apache.activemq.artemis.core.client.impl.ClientMessageInternal;
-import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;
 import org.apache.activemq.artemis.reader.MessageUtil;
 import org.apache.activemq.artemis.utils.UUID;
@@ -56,7 +56,6 @@ import static 
org.apache.activemq.artemis.jms.client.ActiveMQDestination.QUEUE_Q
 import static 
org.apache.activemq.artemis.jms.client.ActiveMQDestination.TEMP_QUEUE_QUALIFED_PREFIX;
 import static 
org.apache.activemq.artemis.jms.client.ActiveMQDestination.TEMP_TOPIC_QUALIFED_PREFIX;
 import static 
org.apache.activemq.artemis.jms.client.ActiveMQDestination.TOPIC_QUALIFIED_PREFIX;
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
 
 /**
  * ActiveMQ Artemis implementation of a JMS Message.
@@ -220,9 +219,7 @@ public class ActiveMQMessage implements javax.jms.Message {
     * Constructor for when receiving a message from the server
     */
    public ActiveMQMessage(final ClientMessage message, final ClientSession 
session) {
-      checkNotNull(message);
-
-      this.message = message;
+      this.message = Objects.requireNonNull(message);
 
       readOnly = true;
 
diff --git 
a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java
 
b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java
index 56468d9de3..8f124ae070 100644
--- 
a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java
+++ 
b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java
@@ -19,6 +19,7 @@ package org.apache.activemq.artemis.core.io.mapped;
 import java.io.File;
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.util.Objects;
 
 import io.netty.buffer.ByteBuf;
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
@@ -150,10 +151,7 @@ final class MappedSequentialFile implements SequentialFile 
{
 
    @Override
    public void write(ActiveMQBuffer bytes, boolean sync, IOCallback callback) 
throws IOException {
-      if (callback == null) {
-         throw new NullPointerException("callback parameter need to be set");
-      }
-      checkIsOpen(callback);
+      checkIsOpen(Objects.requireNonNull(callback, "callback parameter need to 
be set"));
       try {
          final ByteBuf byteBuf = bytes.byteBuf();
          final int writerIndex = byteBuf.writerIndex();
@@ -192,10 +190,7 @@ final class MappedSequentialFile implements SequentialFile 
{
 
    @Override
    public void write(EncodingSupport bytes, boolean sync, IOCallback callback) 
throws IOException {
-      if (callback == null) {
-         throw new NullPointerException("callback parameter need to be set");
-      }
-      checkIsOpen(callback);
+      checkIsOpen(Objects.requireNonNull(callback, "callback parameter need to 
be set"));
       try {
          this.mappedFile.write(bytes);
          if (factory.isDatasync() && sync) {
@@ -223,10 +218,7 @@ final class MappedSequentialFile implements SequentialFile 
{
    @Override
    public void writeDirect(ByteBuffer bytes, boolean sync, IOCallback 
callback) {
       try {
-         if (callback == null) {
-            throw new NullPointerException("callback parameter need to be 
set");
-         }
-         checkIsOpen(callback);
+         checkIsOpen(Objects.requireNonNull(callback, "callback parameter need 
to be set"));
          final int position = bytes.position();
          final int limit = bytes.limit();
          final int remaining = limit - position;
@@ -294,10 +286,7 @@ final class MappedSequentialFile implements SequentialFile 
{
 
    @Override
    public int read(ByteBuffer bytes, IOCallback callback) throws IOException {
-      if (callback == null) {
-         throw new NullPointerException("callback parameter need to be set");
-      }
-      checkIsOpen(callback);
+      checkIsOpen(Objects.requireNonNull(callback, "callback parameter need to 
be set"));
       try {
          final int position = bytes.position();
          final int limit = bytes.limit();
diff --git 
a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java
 
b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java
index 4b6456943d..32ae1009df 100644
--- 
a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java
+++ 
b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java
@@ -16,18 +16,17 @@
  */
 package org.apache.activemq.artemis.core.journal.impl;
 
+import java.lang.invoke.MethodHandles;
 import java.util.Map.Entry;
+import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 
 import org.apache.activemq.artemis.core.io.SequentialFile;
-import org.slf4j.LoggerFactory;
-import java.lang.invoke.MethodHandles;
 import org.slf4j.Logger;
-
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
+import org.slf4j.LoggerFactory;
 
 public class JournalFileImpl implements JournalFile {
 
@@ -69,9 +68,7 @@ public class JournalFileImpl implements JournalFile {
    private static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
    public JournalFileImpl(final SequentialFile file, final long fileID, final 
int version) {
-      checkNotNull(file);
-
-      this.file = file;
+      this.file = Objects.requireNonNull(file);
 
       this.fileID = fileID;
 
diff --git 
a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalRecord.java
 
b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalRecord.java
index 5a95945c27..bd5e42ec59 100644
--- 
a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalRecord.java
+++ 
b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalRecord.java
@@ -16,7 +16,7 @@
  */
 package org.apache.activemq.artemis.core.journal.impl;
 
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
+import java.util.Objects;
 
 /**
  * This holds the relationship a record has with other files in regard to 
reference counting. Note: This class used to
@@ -37,9 +37,7 @@ public class JournalRecord {
    private ObjIntIntArrayList<JournalFile> fileUpdates;
 
    public JournalRecord(final JournalFile addFile, final int size) {
-      checkNotNull(addFile);
-
-      this.addFile = addFile;
+      this.addFile = Objects.requireNonNull(addFile);
 
       this.size = size;
 
diff --git 
a/artemis-junit/artemis-junit-commons/src/main/java/org/apache/activemq/artemis/junit/EmbeddedJMSDelegate.java
 
b/artemis-junit/artemis-junit-commons/src/main/java/org/apache/activemq/artemis/junit/EmbeddedJMSDelegate.java
index 9767da39a6..1df8e8532a 100644
--- 
a/artemis-junit/artemis-junit-commons/src/main/java/org/apache/activemq/artemis/junit/EmbeddedJMSDelegate.java
+++ 
b/artemis-junit/artemis-junit-commons/src/main/java/org/apache/activemq/artemis/junit/EmbeddedJMSDelegate.java
@@ -22,6 +22,7 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import javax.jms.BytesMessage;
 import javax.jms.Connection;
@@ -565,9 +566,7 @@ public class EmbeddedJMSDelegate implements 
EmbeddedJMSOperations<EmbeddedJMSDel
 
    @Override
    public Message peekMessage(String destinationName) {
-      if (null == jmsServer) {
-         throw new NullPointerException("peekMessage failure  - BrokerService 
is null");
-      }
+      Objects.requireNonNull(jmsServer, "peekMessage failure  - BrokerService 
is null");
 
       if (destinationName == null) {
          throw new IllegalArgumentException("peekMessage failure - destination 
name is required");
diff --git 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java
 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java
index e07c38e60b..aa4dadcedf 100644
--- 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java
+++ 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java
@@ -29,6 +29,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 
 import io.netty.buffer.ByteBuf;
@@ -335,9 +336,8 @@ public abstract class AMQPMessage extends RefCountMessage 
implements org.apache.
     */
    public final MessageImpl getProtonMessage() {
 
-      if (getData() == null) {
-         throw new NullPointerException("Data is not initialized");
-      }
+      Objects.requireNonNull(getData(), "Data is not initialized");
+
       ensureScanning();
 
       MessageImpl protonMessage = null;
diff --git 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/connect/mirror/AckManagerProvider.java
 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/connect/mirror/AckManagerProvider.java
index 8c2b069fba..ed13e673e9 100644
--- 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/connect/mirror/AckManagerProvider.java
+++ 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/connect/mirror/AckManagerProvider.java
@@ -20,6 +20,7 @@ package 
org.apache.activemq.artemis.protocol.amqp.connect.mirror;
 import java.lang.invoke.MethodHandles;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.slf4j.Logger;
@@ -53,9 +54,8 @@ public class AckManagerProvider {
    }
 
    public static AckManager getManager(ActiveMQServer server) {
-      if (server == null) {
-         throw new NullPointerException("server is null");
-      }
+      Objects.requireNonNull(server, "server is null");
+
       synchronized (managerHashMap) {
          AckManager ackManager = managerHashMap.get(server);
          if (ackManager != null) {
diff --git 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/scram/ScramClientFunctionalityImpl.java
 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/scram/ScramClientFunctionalityImpl.java
index 69d0294bdb..ab0505734c 100644
--- 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/scram/ScramClientFunctionalityImpl.java
+++ 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/scram/ScramClientFunctionalityImpl.java
@@ -72,19 +72,9 @@ public class ScramClientFunctionalityImpl implements 
ScramClientFunctionality {
     * @param clientNonce Client nonce to be used
     */
    public ScramClientFunctionalityImpl(String digestName, String hmacName, 
String clientNonce) {
-      if (ScramUtils.isNullOrEmpty(digestName)) {
-         throw new NullPointerException("digestName cannot be null or empty");
-      }
-      if (ScramUtils.isNullOrEmpty(hmacName)) {
-         throw new NullPointerException("hmacName cannot be null or empty");
-      }
-      if (ScramUtils.isNullOrEmpty(clientNonce)) {
-         throw new NullPointerException("clientNonce cannot be null or empty");
-      }
-
-      mDigestName = digestName;
-      mHmacName = hmacName;
-      mClientNonce = clientNonce;
+      mDigestName = ScramUtils.requireNonNullAndNotEmpty(digestName, 
"digestName");
+      mHmacName = ScramUtils.requireNonNullAndNotEmpty(hmacName, "hmacName");
+      mClientNonce = ScramUtils.requireNonNullAndNotEmpty(clientNonce, 
"clientNonce");
    }
 
    /**
diff --git 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/scram/ScramServerFunctionalityImpl.java
 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/scram/ScramServerFunctionalityImpl.java
index 7936586485..e759083209 100644
--- 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/scram/ScramServerFunctionalityImpl.java
+++ 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/sasl/scram/ScramServerFunctionalityImpl.java
@@ -68,18 +68,9 @@ public class ScramServerFunctionalityImpl implements 
ScramServerFunctionality {
     */
    public ScramServerFunctionalityImpl(String digestName, String hmacName,
                                        String serverPartNonce) throws 
NoSuchAlgorithmException {
-      if (ScramUtils.isNullOrEmpty(digestName)) {
-         throw new NullPointerException("digestName cannot be null or empty");
-      }
-      if (ScramUtils.isNullOrEmpty(hmacName)) {
-         throw new NullPointerException("hmacName cannot be null or empty");
-      }
-      if (ScramUtils.isNullOrEmpty(serverPartNonce)) {
-         throw new NullPointerException("serverPartNonce cannot be null or 
empty");
-      }
-      digest = MessageDigest.getInstance(digestName);
-      hmac = Mac.getInstance(hmacName);
-      mServerPartNonce = serverPartNonce;
+      digest = 
MessageDigest.getInstance(ScramUtils.requireNonNullAndNotEmpty(digestName, 
"digestName"));
+      hmac = Mac.getInstance(ScramUtils.requireNonNullAndNotEmpty(hmacName, 
"hmacName"));
+      mServerPartNonce =  
ScramUtils.requireNonNullAndNotEmpty(serverPartNonce, "serverPartNonce");
    }
 
    /**
diff --git 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/NettyReadable.java
 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/NettyReadable.java
index 152197cd79..ba889dd1a1 100644
--- 
a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/NettyReadable.java
+++ 
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/util/NettyReadable.java
@@ -20,14 +20,12 @@ import java.nio.ByteBuffer;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.StandardCharsets;
+import java.util.Objects;
 
+import io.netty.buffer.ByteBuf;
 import org.apache.qpid.proton.codec.ReadableBuffer;
 import org.apache.qpid.proton.codec.WritableBuffer;
 
-import io.netty.buffer.ByteBuf;
-
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
-
 /**
  * {@link ReadableBuffer} implementation that wraps a Netty {@link ByteBuf} to 
allow use of Netty buffers to be used
  * when decoding AMQP messages.
@@ -37,9 +35,7 @@ public class NettyReadable implements ReadableBuffer {
    private final ByteBuf buffer;
 
    public NettyReadable(ByteBuf buffer) {
-      checkNotNull(buffer);
-
-      this.buffer = buffer;
+      this.buffer = Objects.requireNonNull(buffer);
    }
 
    public ByteBuf getByteBuf() {
diff --git 
a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAMessage.java
 
b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAMessage.java
index ee1c1b1953..a7479a5617 100644
--- 
a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAMessage.java
+++ 
b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAMessage.java
@@ -19,14 +19,13 @@ package org.apache.activemq.artemis.ra;
 import javax.jms.Destination;
 import javax.jms.JMSException;
 import javax.jms.Message;
+import java.lang.invoke.MethodHandles;
 import java.util.Arrays;
 import java.util.Enumeration;
+import java.util.Objects;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import java.lang.invoke.MethodHandles;
-
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
 
 /**
  * A wrapper for a {@link Message}.
@@ -40,13 +39,9 @@ public class ActiveMQRAMessage implements Message {
    protected ActiveMQRASession session;
 
    public ActiveMQRAMessage(final Message message, final ActiveMQRASession 
session) {
-      checkNotNull(message);
-      checkNotNull(session);
-
+      this.message = Objects.requireNonNull(message);
+      this.session = Objects.requireNonNull(session);
       logger.trace("constructor({}, {})", message, session);
-
-      this.message = message;
-      this.session = session;
    }
 
    /**
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java
index e0f5e7cd56..6079410c62 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java
@@ -181,12 +181,9 @@ public class PagingStoreImpl implements PagingStore {
                           final AddressSettings addressSettings,
                           final ArtemisExecutor executor,
                           final boolean syncNonTransactional) {
-      if (scheduledExecutor == null) {
-         throw new NullPointerException("scheduledExecutor = null");
-      }
-      if (pagingManager == null) {
-         throw new IllegalStateException("Paging Manager can't be null");
-      }
+      Objects.requireNonNull(scheduledExecutor, "scheduledExecutor = null");
+
+      Objects.requireNonNull(pagingManager, "Paging Manager can't be null");
 
       this.address = address;
 
@@ -219,12 +216,8 @@ public class PagingStoreImpl implements PagingStore {
 
    // This is an extension point for unit tests to replace the creation of the 
PagedTimeWriter
    protected PageTimedWriter createPageTimedWriter(ScheduledExecutorService 
scheduledExecutor, long syncTimeout) {
-      if (scheduledExecutor == null) {
-         throw new NullPointerException("scheduledExecutor");
-      }
-      if (executor == null) {
-         throw new NullPointerException("executor");
-      }
+      Objects.requireNonNull(scheduledExecutor, "scheduledExecutor");
+      Objects.requireNonNull(executor, "executor");
       // Notice that any calls on the PageTimedWriter are going to use the 
paging store's executor.
       // The scheduledExecutor will transfer the call to the paging store 
executor.
       PageTimedWriter localWriter = new PageTimedWriter(pageSize, 
storageManager, this, scheduledExecutor, executor, syncNonTransactional, 
syncTimeout);
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/config/PersistedRole.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/config/PersistedRole.java
index 07d0f08946..6dda88b00e 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/config/PersistedRole.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/config/PersistedRole.java
@@ -18,14 +18,13 @@ package org.apache.activemq.artemis.core.persistence.config;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
 import org.apache.activemq.artemis.core.journal.EncodingSupport;
 import org.apache.activemq.artemis.utils.BufferHelper;
 import org.apache.activemq.artemis.utils.DataConstants;
 
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
-
 public class PersistedRole implements EncodingSupport {
 
    private long storeId;
@@ -38,11 +37,8 @@ public class PersistedRole implements EncodingSupport {
    }
 
    public PersistedRole(String username, List<String> roles) {
-      checkNotNull(username);
-      checkNotNull(roles);
-
-      this.username = username;
-      this.roles = roles;
+      this.username = Objects.requireNonNull(username);
+      this.roles = Objects.requireNonNull(roles);
    }
 
    public void setStoreId(long id) {
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/DuplicateIDEncoding.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/DuplicateIDEncoding.java
index ab2cda98e7..cb3475a4c5 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/DuplicateIDEncoding.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/DuplicateIDEncoding.java
@@ -17,6 +17,7 @@
 package org.apache.activemq.artemis.core.persistence.impl.journal.codec;
 
 import java.nio.ByteBuffer;
+import java.util.Objects;
 
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
 import org.apache.activemq.artemis.api.core.SimpleString;
@@ -25,8 +26,6 @@ import org.apache.activemq.artemis.utils.ByteUtil;
 import org.apache.activemq.artemis.utils.DataConstants;
 import org.apache.activemq.artemis.utils.UUID;
 
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
-
 public class DuplicateIDEncoding implements EncodingSupport {
 
    public SimpleString address;
@@ -34,12 +33,8 @@ public class DuplicateIDEncoding implements EncodingSupport {
    public byte[] duplID;
 
    public DuplicateIDEncoding(final SimpleString address, final byte[] duplID) 
{
-      checkNotNull(address);
-      checkNotNull(duplID);
-
-      this.address = address;
-
-      this.duplID = duplID;
+      this.address = Objects.requireNonNull(address);
+      this.duplID = Objects.requireNonNull(duplID);
    }
 
    public DuplicateIDEncoding() {
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/PersistentAddressBindingEncoding.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/PersistentAddressBindingEncoding.java
index c69eac36d8..f8713330e1 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/PersistentAddressBindingEncoding.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/PersistentAddressBindingEncoding.java
@@ -17,17 +17,16 @@
 package org.apache.activemq.artemis.core.persistence.impl.journal.codec;
 
 import java.util.EnumSet;
+import java.util.Objects;
 
 import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
+import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.core.journal.EncodingSupport;
 import org.apache.activemq.artemis.core.persistence.AddressBindingInfo;
-import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.utils.DataConstants;
 
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
-
 public class PersistentAddressBindingEncoding implements EncodingSupport, 
AddressBindingInfo {
 
    private long id;
@@ -67,11 +66,8 @@ public class PersistentAddressBindingEncoding implements 
EncodingSupport, Addres
                                            final EnumSet<RoutingType> 
routingTypes,
                                            final boolean autoCreated,
                                            final boolean internal) {
-      checkNotNull(name);
-      checkNotNull(routingTypes);
-
-      this.name = name;
-      this.routingTypes = routingTypes;
+      this.name = Objects.requireNonNull(name);
+      this.routingTypes = Objects.requireNonNull(routingTypes);
       this.autoCreated = autoCreated;
       this.internal = internal;
    }
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/wireformat/BackupReplicationStartFailedMessage.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/wireformat/BackupReplicationStartFailedMessage.java
index 31fd0bf85e..c1bccc8b8e 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/wireformat/BackupReplicationStartFailedMessage.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/wireformat/BackupReplicationStartFailedMessage.java
@@ -20,12 +20,11 @@ import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
 import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;
 
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
-
 /**
  * Informs the Backup trying to start replicating of an error.
  */
@@ -59,10 +58,7 @@ public final class BackupReplicationStartFailedMessage 
extends PacketImpl {
 
    public BackupReplicationStartFailedMessage(BackupRegistrationProblem 
registrationProblem) {
       super(BACKUP_REGISTRATION_FAILED);
-
-      checkNotNull(registrationProblem);
-
-      problem = registrationProblem;
+      problem = Objects.requireNonNull(registrationProblem);
    }
 
    public BackupReplicationStartFailedMessage() {
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/quorum/QuorumManager.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/quorum/QuorumManager.java
index ef8a132fda..8b21bbbf8c 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/quorum/QuorumManager.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/quorum/QuorumManager.java
@@ -45,8 +45,6 @@ import 
org.apache.activemq.artemis.core.server.cluster.ClusterController;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;
-
 /**
  * A QourumManager can be used to register a {@link 
org.apache.activemq.artemis.core.server.cluster.quorum.Quorum} to
  * receive notifications about changes to the cluster. A
@@ -94,11 +92,8 @@ public final class QuorumManager implements 
ClusterTopologyListener, ActiveMQCom
    private int maxClusterSize = 0;
 
    public QuorumManager(ExecutorService threadPool, ClusterController 
clusterController) {
-      checkNotNull(threadPool);
-      checkNotNull(clusterController);
-
-      this.clusterController = clusterController;
-      this.executor = threadPool;
+      this.clusterController = Objects.requireNonNull(clusterController);
+      this.executor = Objects.requireNonNull(threadPool);
    }
 
    /**
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueMessageMetrics.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueMessageMetrics.java
index 3bad2004be..0d685fd775 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueMessageMetrics.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueMessageMetrics.java
@@ -16,17 +16,16 @@
  */
 package org.apache.activemq.artemis.core.server.impl;
 
+import java.lang.invoke.MethodHandles;
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 import java.util.concurrent.atomic.AtomicLongFieldUpdater;
 
-import org.apache.activemq.artemis.utils.Preconditions;
-
 import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
 import org.apache.activemq.artemis.core.server.MessageReference;
 import org.apache.activemq.artemis.core.server.Queue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import java.lang.invoke.MethodHandles;
 
 public class QueueMessageMetrics {
 
@@ -77,8 +76,7 @@ public class QueueMessageMetrics {
    private final String name;
 
    public QueueMessageMetrics(final Queue queue, final String name) {
-      Preconditions.checkNotNull(queue);
-      this.queue = queue;
+      this.queue = Objects.requireNonNull(queue);
       this.name = name;
    }
 
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerConsumerImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerConsumerImpl.java
index e7a78a15b8..40fe9d730b 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerConsumerImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerConsumerImpl.java
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
@@ -223,10 +224,8 @@ public class ServerConsumerImpl implements ServerConsumer, 
ReadyListener {
                              final Integer credits,
                              final ActiveMQServer server) throws Exception {
 
-
-      if (session == null || session.getRemotingConnection() == null) {
-         throw new NullPointerException("session = " + session);
-      }
+      Objects.requireNonNull(session, "session = null");
+      Objects.requireNonNull(session.getRemotingConnection(), "session = " + 
session);
 
       if (session != null && session.getRemotingConnection() != null && 
session.getRemotingConnection().isDestroyed()) {
          throw 
ActiveMQMessageBundle.BUNDLE.connectionDestroyed(session.getRemotingConnection().getRemoteAddress());
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/replay/ReplayManager.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/replay/ReplayManager.java
index 06bf6d116f..90af9722d2 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/replay/ReplayManager.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/replay/ReplayManager.java
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
@@ -71,9 +72,7 @@ public class ReplayManager {
    public void replay(Date start, Date end, String sourceAddress, String 
targetAddressParameter, String filterStr) throws Exception {
       logger.debug("Replay start::sourceAddress={}", sourceAddress);
 
-      if (sourceAddress == null) {
-         throw new NullPointerException("sourceAddress");
-      }
+      Objects.requireNonNull(sourceAddress, "sourceAddress");
 
       if (targetAddressParameter == null || 
targetAddressParameter.trim().isEmpty()) {
          targetAddressParameter = sourceAddress;
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/protocol/MessagePersister.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/protocol/MessagePersister.java
index cc379a1ca9..39a83f5580 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/protocol/MessagePersister.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/protocol/MessagePersister.java
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.artemis.spi.core.protocol;
 
+import java.util.Objects;
 import java.util.ServiceLoader;
 
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
@@ -119,9 +120,7 @@ public class MessagePersister implements Persister<Message> 
{
    public Message decode(ActiveMQBuffer buffer, Message record, 
CoreMessageObjectPools pools, StorageManager storageManager) {
       byte protocol = buffer.readByte();
       Persister<Message> persister = getPersister(protocol);
-      if (persister == null) {
-         throw new NullPointerException("couldn't find factory for type=" + 
protocol);
-      }
+      Objects.requireNonNull(persister, "couldn't find factory for type=" + 
protocol);
       Message message = persister.decode(buffer, record, pools);
       if (message instanceof LargeServerMessage largeServerMessage) {
          largeServerMessage.setStorageManager(storageManager);
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/scram/ScramUtils.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/scram/ScramUtils.java
index 1aec01e839..9ec6287885 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/scram/ScramUtils.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/scram/ScramUtils.java
@@ -21,6 +21,7 @@ import java.security.InvalidKeyException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.Base64;
+import java.util.Objects;
 
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
@@ -119,10 +120,10 @@ public class ScramUtils {
     * Checks if string is null or empty
     *
     * @param string String to be tested
-    * @return true if the string is null or empty, false otherwise
+    * @param name name of String to be tested and reported if null or empty
     */
-   public static boolean isNullOrEmpty(String string) {
-      return string == null || string.isEmpty();
+   public static <T> String requireNonNullAndNotEmpty(String string, String 
name) {
+      return Objects.requireNonNull(string == null ? null : (string.isEmpty() 
? null : string), name + " is null or empty");
    }
 
    /**
diff --git 
a/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java
 
b/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java
index 9a08ad7efa..51fb4350ef 100644
--- 
a/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java
+++ 
b/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java
@@ -36,6 +36,7 @@ import java.util.WeakHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.Objects;
 
 import org.apache.activemq.ActiveMQConnectionMetaData;
 import org.apache.activemq.Service;
@@ -217,9 +218,7 @@ public class BrokerService implements Service {
    }
 
    public void setBrokerName(String brokerName) {
-      if (brokerName == null) {
-         throw new NullPointerException("The broker name cannot be null");
-      }
+      Objects.requireNonNull(brokerName, "The broker name cannot be null");
       String str = brokerName.replaceAll("[^a-zA-Z0-9\\.\\_\\-\\:]", "_");
       if (!str.equals(brokerName)) {
          LOG.error("Broker Name: {} contained illegal characters - replaced 
with {}", brokerName, str);
diff --git 
a/tests/artemis-test-support/src/main/java/org/apache/activemq/transport/amqp/client/AmqpFrameValidator.java
 
b/tests/artemis-test-support/src/main/java/org/apache/activemq/transport/amqp/client/AmqpFrameValidator.java
index c496621f05..4e19dafa60 100644
--- 
a/tests/artemis-test-support/src/main/java/org/apache/activemq/transport/amqp/client/AmqpFrameValidator.java
+++ 
b/tests/artemis-test-support/src/main/java/org/apache/activemq/transport/amqp/client/AmqpFrameValidator.java
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.transport.amqp.client;
 
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.qpid.proton.amqp.Binary;
@@ -85,9 +86,7 @@ public class AmqpFrameValidator {
    }
 
    protected final boolean markAsInvalid(String message) {
-      if (message == null) {
-         throw new NullPointerException("Provided error message cannot be 
null!");
-      }
+      Objects.requireNonNull(message, "Provided error message cannot be 
null!");
 
       return errorMessage.compareAndSet(null, message);
    }
diff --git 
a/tests/artemis-test-support/src/main/java/org/apache/activemq/transport/amqp/client/AmqpValidator.java
 
b/tests/artemis-test-support/src/main/java/org/apache/activemq/transport/amqp/client/AmqpValidator.java
index 851d131929..83aa91fb66 100644
--- 
a/tests/artemis-test-support/src/main/java/org/apache/activemq/transport/amqp/client/AmqpValidator.java
+++ 
b/tests/artemis-test-support/src/main/java/org/apache/activemq/transport/amqp/client/AmqpValidator.java
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.transport.amqp.client;
 
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.qpid.proton.engine.Connection;
@@ -97,9 +98,7 @@ public class AmqpValidator {
    }
 
    protected final boolean markAsInvalid(String message) {
-      if (message == null) {
-         throw new NullPointerException("Provided error message cannot be 
null!");
-      }
+      Objects.requireNonNull(message, "Provided error message cannot be 
null!");
 
       return errorMessage.compareAndSet(null, message);
    }
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/util/BackupSyncDelay.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/util/BackupSyncDelay.java
index f63424728a..9c1faed7a1 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/util/BackupSyncDelay.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/util/BackupSyncDelay.java
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.artemis.tests.integration.cluster.util;
 
+import java.util.Objects;
 import java.util.concurrent.locks.Lock;
 
 import org.apache.activemq.artemis.api.core.ActiveMQException;
@@ -98,9 +99,7 @@ public class BackupSyncDelay implements Interceptor {
             } else if (backupActivation instanceof ReplicationBackupActivation 
activation) {
                repEnd = activation.getReplicationEndpoint();
             }
-            if (repEnd == null) {
-               throw new NullPointerException("replication endpoint isn't 
supposed to be null");
-            }
+            Objects.requireNonNull(repEnd, "replication endpoint isn't 
supposed to be null");
             handler.addSubHandler(repEnd);
             Channel repChannel = repEnd.getChannel();
             repChannel.setHandler(handler);
@@ -139,9 +138,7 @@ public class BackupSyncDelay implements Interceptor {
          if (delivered)
             return;
 
-         if (onHold == null) {
-            throw new NullPointerException("Don't have the 'sync is done' 
packet to deliver");
-         }
+         Objects.requireNonNull(onHold, "Don't have the 'sync is done' packet 
to deliver");
          // Use wrapper to avoid sending a response
          ChannelWrapper wrapper = new ChannelWrapper(channel);
          handler.setChannel(wrapper);
diff --git 
a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/SimpleJMSBytesMessage.java
 
b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/SimpleJMSBytesMessage.java
index 17d88f38b7..0890ed7260 100644
--- 
a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/SimpleJMSBytesMessage.java
+++ 
b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/SimpleJMSBytesMessage.java
@@ -28,6 +28,7 @@ import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.EOFException;
 import java.io.IOException;
+import java.util.Objects;
 
 public class SimpleJMSBytesMessage extends SimpleJMSMessage implements 
BytesMessage {
 
@@ -342,9 +343,7 @@ public class SimpleJMSBytesMessage extends SimpleJMSMessage 
implements BytesMess
          throw new MessageNotWriteableException("the message body is 
read-only");
       }
       try {
-         if (value == null) {
-            throw new NullPointerException("Attempt to write a new value");
-         }
+         Objects.requireNonNull(value, "Attempt to write a null value");
          if (value instanceof String string) {
             p.writeUTF(string);
          } else if (value instanceof Boolean booleanValue) {
diff --git 
a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/SimpleJMSMapMessage.java
 
b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/SimpleJMSMapMessage.java
index e449175deb..ebfab72783 100644
--- 
a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/SimpleJMSMapMessage.java
+++ 
b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/SimpleJMSMapMessage.java
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 public class SimpleJMSMapMessage extends SimpleJMSMessage implements 
MapMessage {
 
@@ -260,14 +261,7 @@ public class SimpleJMSMapMessage extends SimpleJMSMessage 
implements MapMessage
 
    @Override
    public char getChar(final String name) throws JMSException {
-      Object value;
-
-      value = content.get(name);
-
-      if (value == null) {
-         throw new NullPointerException("Invalid conversion");
-      }
-
+      Object value = Objects.requireNonNull(content.get(name), "Invalid 
conversion");
       if (value instanceof Character character) {
          return character.charValue();
       } else {
diff --git 
a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/SimpleJMSStreamMessage.java
 
b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/SimpleJMSStreamMessage.java
index f77dc8f519..dd8aa2baa0 100644
--- 
a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/SimpleJMSStreamMessage.java
+++ 
b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/SimpleJMSStreamMessage.java
@@ -24,6 +24,7 @@ import javax.jms.MessageNotWriteableException;
 import javax.jms.StreamMessage;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 public class SimpleJMSStreamMessage extends SimpleJMSMessage implements 
StreamMessage {
 
@@ -61,9 +62,8 @@ public class SimpleJMSStreamMessage extends SimpleJMSMessage 
implements StreamMe
          Object value = content.get(position);
          offset = 0;
 
-         if (value == null) {
-            throw new NullPointerException("Value is null");
-         } else if (value instanceof Boolean booleanValue) {
+         Objects.requireNonNull(value, "Value is null");
+         if (value instanceof Boolean booleanValue) {
             position++;
             return booleanValue.booleanValue();
          } else if (value instanceof String string) {
@@ -88,9 +88,8 @@ public class SimpleJMSStreamMessage extends SimpleJMSMessage 
implements StreamMe
       try {
          Object value = content.get(position);
          offset = 0;
-         if (value == null) {
-            throw new NullPointerException("Value is null");
-         } else if (value instanceof Byte byteValue) {
+         Objects.requireNonNull(value, "Value is null");
+         if (value instanceof Byte byteValue) {
             position++;
             return byteValue.byteValue();
          } else if (value instanceof String string) {
@@ -114,9 +113,8 @@ public class SimpleJMSStreamMessage extends 
SimpleJMSMessage implements StreamMe
          Object value = content.get(position);
          offset = 0;
 
-         if (value == null) {
-            throw new NullPointerException("Value is null");
-         } else if (value instanceof Byte byteValue) {
+         Objects.requireNonNull(value, "Value is null");
+         if (value instanceof Byte byteValue) {
             position++;
             return byteValue.shortValue();
          } else if (value instanceof Short shortValue) {
@@ -143,9 +141,8 @@ public class SimpleJMSStreamMessage extends 
SimpleJMSMessage implements StreamMe
          Object value = content.get(position);
          offset = 0;
 
-         if (value == null) {
-            throw new NullPointerException("Value is null");
-         } else if (value instanceof Character character) {
+         Objects.requireNonNull(value, "Value is null");
+         if (value instanceof Character character) {
             position++;
             return character.charValue();
          } else {
@@ -165,9 +162,8 @@ public class SimpleJMSStreamMessage extends 
SimpleJMSMessage implements StreamMe
          Object value = content.get(position);
          offset = 0;
 
-         if (value == null) {
-            throw new NullPointerException("Value is null");
-         } else if (value instanceof Byte byteValue) {
+         Objects.requireNonNull(value, "Value is null");
+         if (value instanceof Byte byteValue) {
             position++;
             return byteValue.intValue();
          } else if (value instanceof Short shortValue) {
@@ -197,9 +193,8 @@ public class SimpleJMSStreamMessage extends 
SimpleJMSMessage implements StreamMe
          Object value = content.get(position);
          offset = 0;
 
-         if (value == null) {
-            throw new NullPointerException("Value is null");
-         } else if (value instanceof Byte byteValue) {
+         Objects.requireNonNull(value, "Value is null");
+         if (value instanceof Byte byteValue) {
             position++;
             return byteValue.longValue();
          } else if (value instanceof Short shortValue) {
@@ -232,9 +227,8 @@ public class SimpleJMSStreamMessage extends 
SimpleJMSMessage implements StreamMe
          Object value = content.get(position);
          offset = 0;
 
-         if (value == null) {
-            throw new NullPointerException("Value is null");
-         } else if (value instanceof Float floatValue) {
+         Objects.requireNonNull(value, "Value is null");
+         if (value instanceof Float floatValue) {
             position++;
             return floatValue.floatValue();
          } else if (value instanceof String string) {
@@ -258,9 +252,8 @@ public class SimpleJMSStreamMessage extends 
SimpleJMSMessage implements StreamMe
          Object value = content.get(position);
          offset = 0;
 
-         if (value == null) {
-            throw new NullPointerException("Value is null");
-         } else if (value instanceof Float floatValue) {
+         Objects.requireNonNull(value, "Value is null");
+         if (value instanceof Float floatValue) {
             position++;
             return floatValue.doubleValue();
          } else if (value instanceof Double doubleValue) {
@@ -332,9 +325,8 @@ public class SimpleJMSStreamMessage extends 
SimpleJMSMessage implements StreamMe
       }
       try {
          Object myObj = content.get(position);
-         if (myObj == null) {
-            throw new NullPointerException("Value is null");
-         } else if (!(myObj instanceof byte[])) {
+         Objects.requireNonNull(myObj, "Value is null");
+         if (!(myObj instanceof byte[])) {
             throw new MessageFormatException("Invalid conversion");
          }
          byte[] obj = (byte[]) myObj;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to