activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [2/2] activemq-artemis git commit: ARTEMIS-1801 removing null-unchecked dereferences
Date Thu, 03 May 2018 16:44:13 GMT
ARTEMIS-1801 removing null-unchecked dereferences


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/b67008c4
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/b67008c4
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/b67008c4

Branch: refs/heads/master
Commit: b67008c4caf7df3c0fee8c83a451e43d3dd8cd80
Parents: 63a5233
Author: Stanislav Knot <sknot@redhat.com>
Authored: Wed Apr 11 08:43:07 2018 +0200
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Thu May 3 12:42:42 2018 -0400

----------------------------------------------------------------------
 .../artemis/api/core/ActiveMQExceptionType.java |  4 +++
 .../api/core/ActiveMQNullRefException.java      | 31 ++++++++++++++++++++
 .../artemis/junit/EmbeddedJMSResource.java      |  6 +++-
 .../cursor/impl/PageSubscriptionImpl.java       |  2 +-
 .../core/server/ActiveMQServerLogger.java       |  4 +++
 .../core/server/impl/ActiveMQServerImpl.java    |  2 +-
 .../artemis/core/server/impl/QueueImpl.java     | 10 ++++++-
 7 files changed, 55 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b67008c4/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQExceptionType.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQExceptionType.java
b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQExceptionType.java
index 64518ec..8b083e6 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQExceptionType.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQExceptionType.java
@@ -243,6 +243,10 @@ public enum ActiveMQExceptionType {
       public ActiveMQException createException(String msg) {
          return new ActiveMQDeleteAddressException(msg);
       }
+   },
+   NULL_REF(218) {
+      @Override
+      public ActiveMQException createException(String msg) { return new ActiveMQNullRefException(msg);
}
    };
 
    private static final Map<Integer, ActiveMQExceptionType> TYPE_MAP;

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b67008c4/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQNullRefException.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQNullRefException.java
b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQNullRefException.java
new file mode 100644
index 0000000..082db94
--- /dev/null
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQNullRefException.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.artemis.api.core;
+
+/**
+ * An operation failed because is dereferencing null pointer.
+ */
+public class ActiveMQNullRefException extends ActiveMQException {
+   public ActiveMQNullRefException() {
+      super(ActiveMQExceptionType.NULL_REF);
+   }
+
+   public ActiveMQNullRefException(String msg) {
+      super(ActiveMQExceptionType.NULL_REF, msg);
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b67008c4/artemis-junit/src/main/java/org/apache/activemq/artemis/junit/EmbeddedJMSResource.java
----------------------------------------------------------------------
diff --git a/artemis-junit/src/main/java/org/apache/activemq/artemis/junit/EmbeddedJMSResource.java
b/artemis-junit/src/main/java/org/apache/activemq/artemis/junit/EmbeddedJMSResource.java
index caaa12c..3a2b05d 100644
--- a/artemis-junit/src/main/java/org/apache/activemq/artemis/junit/EmbeddedJMSResource.java
+++ b/artemis-junit/src/main/java/org/apache/activemq/artemis/junit/EmbeddedJMSResource.java
@@ -233,7 +233,11 @@ public class EmbeddedJMSResource extends ExternalResource {
     * be stopped manually to support advanced testing scenarios.
     */
    public void stop() {
-      log.info("Stopping {}: {}", this.getClass().getSimpleName(), this.getServerName());
+      String name = "null";
+      if (jmsServer != null) {
+         name = this.getServerName();
+      }
+      log.info("Stopping {}: {}", this.getClass().getSimpleName(), name);
       if (internalClient != null) {
          internalClient.stop();
          internalClient = null;

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b67008c4/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageSubscriptionImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageSubscriptionImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageSubscriptionImpl.java
index a767c09..e1c9537 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageSubscriptionImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageSubscriptionImpl.java
@@ -209,7 +209,7 @@ final class PageSubscriptionImpl implements PageSubscription {
          return false;
       }
       // if the current page is complete, we must move it out of the way
-      if (pageStore != null && pageStore.getCurrentPage() != null &&
+      if (pageStore.getCurrentPage() != null &&
           pageStore.getCurrentPage().getPageId() == position.getPageNr()) {
          pageStore.forceAnotherPage();
       }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b67008c4/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java
index 6cd69ae..61ae6ca 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java
@@ -1938,4 +1938,8 @@ public interface ActiveMQServerLogger extends BasicLogger {
    @LogMessage(level = Logger.Level.INFO)
    @Message(id = 224092, value = "Despite disabled persistence, page files will be persisted.",
format = Message.Format.MESSAGE_FORMAT)
    void pageWillBePersisted();
+
+   @LogMessage(level = Logger.Level.ERROR)
+   @Message(id = 224093, value = "Reference to message is null", format = Message.Format.MESSAGE_FORMAT)
+   void nullRefMessage();
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b67008c4/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
index b5496a9..3a2e91c 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
@@ -2780,7 +2780,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
          throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(rt, info.getName().toString(),
info.getRoutingTypes());
       }
 
-      final QueueConfig queueConfig = queueConfigBuilder.filter(filter).pagingManager(pagingManager).user(user).durable(durable).temporary(temporary).autoCreated(autoCreated).routingType(addrInfo.getRoutingType()).maxConsumers(maxConsumers).purgeOnNoConsumers(purgeOnNoConsumers).exclusive(exclusive).lastValue(lastValue).build();
+      final QueueConfig queueConfig = queueConfigBuilder.filter(filter).pagingManager(pagingManager).user(user).durable(durable).temporary(temporary).autoCreated(autoCreated).routingType(rt).maxConsumers(maxConsumers).purgeOnNoConsumers(purgeOnNoConsumers).exclusive(exclusive).lastValue(lastValue).build();
 
       callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.beforeCreateQueue(queueConfig)
: null);
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b67008c4/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java
index bf86823..69f73f7 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java
@@ -41,6 +41,7 @@ import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
 import org.apache.activemq.artemis.api.core.ActiveMQException;
+import org.apache.activemq.artemis.api.core.ActiveMQNullRefException;
 import org.apache.activemq.artemis.api.core.Message;
 import org.apache.activemq.artemis.api.core.Pair;
 import org.apache.activemq.artemis.api.core.RoutingType;
@@ -98,6 +99,8 @@ import org.apache.activemq.artemis.utils.critical.CriticalComponentImpl;
 import org.apache.activemq.artemis.utils.critical.EmptyCriticalAnalyzer;
 import org.jboss.logging.Logger;
 
+import static org.apache.activemq.artemis.api.core.ActiveMQExceptionType.NULL_REF;
+
 /**
  * Implementation of a Queue
  * <p>
@@ -2743,6 +2746,11 @@ public class QueueImpl extends CriticalComponentImpl implements Queue
{
    private Message makeCopy(final MessageReference ref,
                             final boolean expiry,
                             final boolean copyOriginalHeaders) throws Exception {
+      if (ref == null) {
+         ActiveMQServerLogger.LOGGER.nullRefMessage();
+         throw new ActiveMQNullRefException("Reference to message is null");
+      }
+
       Message message = ref.getMessage();
       /*
        We copy the message and send that to the dla/expiry queue - this is
@@ -2758,7 +2766,7 @@ public class QueueImpl extends CriticalComponentImpl implements Queue
{
       Message copy = message.copy(newID);
 
       if (copyOriginalHeaders) {
-         copy.referenceOriginalMessage(message, ref != null ? ref.getQueue().getName().toString()
: null);
+         copy.referenceOriginalMessage(message, ref.getQueue().getName().toString());
       }
 
       copy.setExpiration(0);


Mime
View raw message