From 3f7f8c0ecddb99da21b60273db9787e7c8509fae Mon Sep 17 00:00:00 2001 From: Domenico Francesco Bruscino Date: Fri, 3 Dec 2021 18:21:39 +0100 Subject: [PATCH] ARTEMIS-3576 Fix toString methods throwing exceptions --- .../json/impl/JsonArrayBuilderImpl.java | 3 + .../json/impl/JsonObjectBuilderImpl.java | 3 + .../artemis/json/impl/JsonValueImpl.java | 3 + .../remoting/impl/netty/NettyConnection.java | 4 + .../artemis/jms/client/ActiveMQMessage.java | 15 +- .../core/journal/impl/JournalFileImpl.java | 4 + .../core/journal/impl/JournalRecord.java | 4 + .../protocol/amqp/broker/AMQPMessage.java | 7 +- .../protocol/amqp/util/NettyReadable.java | 4 + .../ActiveMQRAManagedConnectionFactory.java | 2 +- .../artemis/ra/ActiveMQRAMessage.java | 5 + .../core/paging/cursor/impl/PageReader.java | 4 + .../persistence/config/PersistedRole.java | 15 +- .../journal/codec/DuplicateIDEncoding.java | 7 +- .../PersistentAddressBindingEncoding.java | 5 + .../nullpm/NullStorageLargeServerMessage.java | 2 +- .../BackupReplicationStartFailedMessage.java | 7 +- .../server/cluster/qourum/QuorumManager.java | 5 + .../server/impl/MessageReferenceImpl.java | 15 +- .../artemis/tests/unit/AllClassesTest.java | 139 ++++++++++++++++++ 20 files changed, 235 insertions(+), 18 deletions(-) create mode 100644 tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/AllClassesTest.java 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 89653c0f62..5221657841 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 @@ -25,6 +25,8 @@ 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; @@ -34,6 +36,7 @@ public class JsonArrayBuilderImpl implements JsonArrayBuilder { } public JsonArrayBuilderImpl(javax.json.JsonArrayBuilder rawArrayBuilder) { + checkNotNull(rawArrayBuilder); this.rawArrayBuilder = rawArrayBuilder; } 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 e427219a90..9227e989dd 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 @@ -25,6 +25,8 @@ 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; @@ -34,6 +36,7 @@ public class JsonObjectBuilderImpl implements JsonObjectBuilder { } public JsonObjectBuilderImpl(javax.json.JsonObjectBuilder rawObjectBuilder) { + checkNotNull(rawObjectBuilder); this.rawObjectBuilder = rawObjectBuilder; } 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 3e94b4d45c..a944381b09 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 @@ -24,6 +24,8 @@ import org.apache.activemq.artemis.json.JsonValue; import java.util.HashMap; import java.util.Map; +import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull; + public class JsonValueImpl implements JsonValue { private Map cache = new HashMap<>(); @@ -77,6 +79,7 @@ public class JsonValueImpl implements JsonValue { } public JsonValueImpl(javax.json.JsonValue rawValue) { + checkNotNull(rawValue); this.rawValue = rawValue; } 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 75c092e063..6d4d5d15d8 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 @@ -45,6 +45,8 @@ import org.apache.activemq.artemis.utils.Env; import org.apache.activemq.artemis.utils.IPV6Util; import org.jboss.logging.Logger; +import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull; + public class NettyConnection implements Connection { private static final Logger logger = Logger.getLogger(NettyConnection.class); @@ -74,6 +76,8 @@ public class NettyConnection implements Connection { final BaseConnectionLifeCycleListener listener, boolean batchingEnabled, boolean directDeliver) { + checkNotNull(channel); + this.configuration = configuration; this.channel = channel; 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 0991fbcda9..9ca991844d 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 @@ -54,6 +54,7 @@ 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. @@ -219,6 +220,8 @@ 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; readOnly = true; @@ -853,10 +856,14 @@ public class ActiveMQMessage implements javax.jms.Message { @Override public String toString() { StringBuffer sb = new StringBuffer("ActiveMQMessage["); - sb.append(getJMSMessageID()); - sb.append("]:"); - sb.append(message.isDurable() ? "PERSISTENT" : "NON-PERSISTENT"); - sb.append("/" + message.toString()); + if (message != null) { + sb.append(getJMSMessageID()); + sb.append("]:"); + sb.append(message.isDurable() ? "PERSISTENT" : "NON-PERSISTENT"); + sb.append("/" + message.toString()); + } else { + sb.append("]"); + } return sb.toString(); } 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 2e4a072177..e1055d613e 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 @@ -25,6 +25,8 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import org.apache.activemq.artemis.core.io.SequentialFile; import org.jboss.logging.Logger; +import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull; + public class JournalFileImpl implements JournalFile { private final SequentialFile file; @@ -65,6 +67,8 @@ public class JournalFileImpl implements JournalFile { private static final Logger logger = Logger.getLogger(JournalFileImpl.class); public JournalFileImpl(final SequentialFile file, final long fileID, final int version) { + checkNotNull(file); + this.file = 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 0be90c2015..7a2722e4ad 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,6 +16,8 @@ */ package org.apache.activemq.artemis.core.journal.impl; +import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull; + /** * This holds the relationship a record has with other files in regard to reference counting. * Note: This class used to be called PosFiles @@ -35,6 +37,8 @@ public class JournalRecord { private ObjIntIntArrayList fileUpdates; public JournalRecord(final JournalFile addFile, final int size) { + checkNotNull(addFile); + this.addFile = addFile; this.size = size; 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 79255630f3..ea838b15c3 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 @@ -1779,11 +1779,16 @@ public abstract class AMQPMessage extends RefCountMessage implements org.apache. @Override public String toString() { + MessageDataScanningStatus scanningStatus = getDataScanningStatus(); + Map applicationProperties = scanningStatus == MessageDataScanningStatus.SCANNED ? + getApplicationPropertiesMap(false) : Collections.EMPTY_MAP; + return this.getClass().getSimpleName() + "( [durable=" + isDurable() + ", messageID=" + getMessageID() + ", address=" + getAddress() + ", size=" + getEncodeSize() + - ", applicationProperties=" + getApplicationPropertiesMap(false) + + ", scanningStatus=" + scanningStatus + + ", applicationProperties=" + applicationProperties + ", messageAnnotations=" + getMessageAnnotationsMap(false) + ", properties=" + properties + ", extraProperties = " + getExtraProperties() + 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 2d7bf55f79..b0679b5a68 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 @@ -26,6 +26,8 @@ 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,6 +39,8 @@ public class NettyReadable implements ReadableBuffer { private final ByteBuf buffer; public NettyReadable(ByteBuf buffer) { + checkNotNull(buffer); + this.buffer = buffer; } diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAManagedConnectionFactory.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAManagedConnectionFactory.java index 2154a4aa51..be2671280b 100644 --- a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAManagedConnectionFactory.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAManagedConnectionFactory.java @@ -332,7 +332,7 @@ public final class ActiveMQRAManagedConnectionFactory implements ManagedConnecti } int hash = mcfProperties.hashCode(); - hash += 31 * ra.hashCode(); + hash += 31 * (ra != null ? ra.hashCode() : 0); return hash; } 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 39d9fa95c3..48eff16397 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 @@ -22,6 +22,8 @@ import javax.jms.Message; import java.util.Arrays; import java.util.Enumeration; +import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull; + /** * A wrapper for a message */ @@ -44,6 +46,9 @@ public class ActiveMQRAMessage implements Message { * @param session the session */ public ActiveMQRAMessage(final Message message, final ActiveMQRASession session) { + checkNotNull(message); + checkNotNull(session); + if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("constructor(" + message + ", " + session + ")"); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageReader.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageReader.java index 83ad21e177..5d8e1417f1 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageReader.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageReader.java @@ -24,6 +24,8 @@ import org.apache.activemq.artemis.core.paging.cursor.PagePosition; import org.apache.activemq.artemis.core.paging.impl.Page; import org.jboss.logging.Logger; +import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull; + public class PageReader implements PageCache { private static final Logger logger = Logger.getLogger(PageReader.class); @@ -31,6 +33,8 @@ public class PageReader implements PageCache { private final int numberOfMessages; public PageReader(Page page, int numberOfMessages) { + checkNotNull(page); + this.page = page; this.numberOfMessages = numberOfMessages; } 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 1af8864731..38307e897c 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 @@ -24,6 +24,8 @@ 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; @@ -36,6 +38,9 @@ public class PersistedRole implements EncodingSupport { } public PersistedRole(String username, List roles) { + checkNotNull(username); + checkNotNull(roles); + this.username = username; this.roles = roles; } @@ -95,10 +100,12 @@ public class PersistedRole implements EncodingSupport { result.append("PersistedRole [storeId=").append(storeId); result.append(", username=").append(username); result.append(", roles ["); - for (int i = 0; i < roles.size(); i++) { - result.append(roles.get(i)); - if (i < roles.size() - 1) { - result.append(", "); + if (roles != null) { + for (int i = 0; i < roles.size(); i++) { + result.append(roles.get(i)); + if (i < roles.size() - 1) { + result.append(", "); + } } } result.append("]]"); 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 1dd41ff04e..11b4eeace9 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 @@ -25,6 +25,8 @@ 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; @@ -32,6 +34,9 @@ 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; @@ -78,7 +83,7 @@ public class DuplicateIDEncoding implements EncodingSupport { // The bridge will generate IDs on these terms: // This will make them easier to read - if (address.toString().startsWith("BRIDGE") && duplID.length == 24) { + if (address != null && address.toString().startsWith("BRIDGE") && duplID.length == 24) { try { ByteBuffer buff = ByteBuffer.wrap(duplID); 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 e23c69dc14..fdd74a22d1 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 @@ -25,6 +25,8 @@ 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 { public long id; @@ -59,6 +61,9 @@ public class PersistentAddressBindingEncoding implements EncodingSupport, Addres public PersistentAddressBindingEncoding(final SimpleString name, final EnumSet routingTypes, final boolean autoCreated) { + checkNotNull(name); + checkNotNull(routingTypes); + this.name = name; this.routingTypes = routingTypes; this.autoCreated = autoCreated; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java index 68c7f88882..4f63931847 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java @@ -125,7 +125,7 @@ class NullStorageLargeServerMessage extends CoreMessage implements CoreLargeServ @Override public String toString() { - return "NullStorageLargeServerMessage[messageID=" + messageID + ", durable=" + durable + ", address=" + getAddress() + ",properties=" + properties.toString() + "]"; + return "NullStorageLargeServerMessage[messageID=" + messageID + ", durable=" + durable + ", address=" + getAddress() + ",properties=" + properties + "]"; } @Override 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 fc381c26df..b08e53f941 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 @@ -24,6 +24,8 @@ import java.util.Map; 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. */ @@ -57,6 +59,9 @@ public final class BackupReplicationStartFailedMessage extends PacketImpl { public BackupReplicationStartFailedMessage(BackupRegistrationProblem registrationProblem) { super(BACKUP_REGISTRATION_FAILED); + + checkNotNull(registrationProblem); + problem = registrationProblem; } @@ -104,6 +109,6 @@ public final class BackupReplicationStartFailedMessage extends PacketImpl { @Override protected String getPacketString() { - return super.getPacketString() + ", problem=" + problem.name(); + return super.getPacketString() + ", problem=" + (problem != null ? problem.name() : null); } } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/qourum/QuorumManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/qourum/QuorumManager.java index 11be907282..5da3bcd47c 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/qourum/QuorumManager.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/cluster/qourum/QuorumManager.java @@ -42,6 +42,8 @@ import org.apache.activemq.artemis.core.server.ActiveMQServerLogger; import org.apache.activemq.artemis.core.server.cluster.ClusterControl; import org.apache.activemq.artemis.core.server.cluster.ClusterController; +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.qourum.Quorum} to receive notifications * about changes to the cluster. A {@link org.apache.activemq.artemis.core.server.cluster.qourum.Quorum} can then issue a vote to the @@ -73,6 +75,9 @@ 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; } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/MessageReferenceImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/MessageReferenceImpl.java index bf81e7465c..ca1218069e 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/MessageReferenceImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/MessageReferenceImpl.java @@ -319,11 +319,16 @@ public class MessageReferenceImpl extends LinkedListImpl.Node + * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.tests.unit; + +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.ClassPath; +import org.apache.activemq.artemis.tests.util.RandomUtil; +import org.jboss.logging.Logger; +import org.junit.Assume; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.lang.reflect.Parameter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.List; + +@RunWith(value = Parameterized.class) +public class AllClassesTest { + private static final Logger log = Logger.getLogger(AllClassesTest.class); + + @Parameterized.Parameters(name = "classInfo={0}") + public static Collection getParameters() { + List parameters = new ArrayList<>(); + ClassLoader classLoader = AllClassesTest.class.getClassLoader(); + + try { + ClassPath classPath = ClassPath.from(classLoader); + ImmutableSet classInfos = classPath.getTopLevelClassesRecursive("org.apache.activemq.artemis"); + + for (ClassPath.ClassInfo classInfo : classInfos) { + if (!classInfo.getPackageName().contains("tests")) { + try { + Class loadedClass = classInfo.load(); + if (!loadedClass.isEnum() && !loadedClass.isInterface() && !Modifier.isAbstract(loadedClass.getModifiers())) { + parameters.add(loadedClass); + } + } catch (Throwable loadThrowable) { + log.debug("cannot load " + classInfo.getName() + ": " + loadThrowable); + } + } + } + + parameters.sort(Comparator.comparing(Class::getName)); + + return parameters; + } catch (Exception e) { + log.warn("Exception on loading all classes: " + e); + } + + return parameters; + } + + private Class targetClass; + + public AllClassesTest(Class targetClass) { + this.targetClass = targetClass; + } + + + @Test + public void testToString() { + Object targetInstance = null; + + try { + targetInstance = newInstance(targetClass); + } catch (Throwable t) { + log.debug("Error creating a new instance of " + targetClass.getName() + ": " + t); + } + + Assume.assumeTrue("Cannot create " + targetClass.getName(), targetInstance != null); + + String targetOutput = targetInstance.toString(); + log.debug("targetOutput: " + targetOutput); + } + + private Object newInstance(Class targetClass) { + Constructor[] targetConstructors = targetClass.getDeclaredConstructors(); + Arrays.sort(targetConstructors, (c1, c2) -> c2.getParameterCount() - c1.getParameterCount()); + for (Constructor targetConstructor : targetConstructors) { + List initArgs = new ArrayList<>(); + Parameter[] constructorParameters = targetConstructor.getParameters(); + + for (Parameter constructorParameter : constructorParameters) { + Object initArg; + if (constructorParameter.getType().isAssignableFrom(byte.class)) { + initArg = RandomUtil.randomByte(); + } else if (constructorParameter.getType().isAssignableFrom(byte[].class)) { + initArg = RandomUtil.randomBytes(); + } else if (constructorParameter.getType().isAssignableFrom(boolean.class)) { + initArg = RandomUtil.randomBoolean(); + } else if (constructorParameter.getType().isAssignableFrom(char.class)) { + initArg = RandomUtil.randomChar(); + } else if (constructorParameter.getType().isAssignableFrom(double.class)) { + initArg = RandomUtil.randomDouble(); + } else if (constructorParameter.getType().isAssignableFrom(float.class)) { + initArg = RandomUtil.randomFloat(); + } else if (constructorParameter.getType().isAssignableFrom(int.class)) { + initArg = RandomUtil.randomInt() / 1024; + } else if (constructorParameter.getType().isAssignableFrom(long.class)) { + initArg = RandomUtil.randomLong(); + } else if (constructorParameter.getType().isAssignableFrom(String.class)) { + initArg = RandomUtil.randomString(); + } else { + initArg = null; + } + initArgs.add(initArg); + } + + try { + return targetConstructor.newInstance(initArgs.toArray()); + } catch (Throwable t) { + log.debug("Cannot construct " + targetClass.getName() + ": " + t); + } + } + + return null; + } +}