Skip to content
Permalink
Browse files
ARTEMIS-3576 Fix toString methods throwing exceptions
  • Loading branch information
brusdev authored and clebertsuconic committed Dec 3, 2021
1 parent 5730fca commit 3f7f8c0ecddb99da21b60273db9787e7c8509fae
Showing 20 changed files with 235 additions and 18 deletions.
@@ -25,6 +25,8 @@
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 javax.json.JsonArrayBuilder getRawArrayBuilder() {
}

public JsonArrayBuilderImpl(javax.json.JsonArrayBuilder rawArrayBuilder) {
checkNotNull(rawArrayBuilder);
this.rawArrayBuilder = rawArrayBuilder;
}

@@ -25,6 +25,8 @@
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 javax.json.JsonObjectBuilder getRawObjectBuilder() {
}

public JsonObjectBuilderImpl(javax.json.JsonObjectBuilder rawObjectBuilder) {
checkNotNull(rawObjectBuilder);
this.rawObjectBuilder = rawObjectBuilder;
}

@@ -24,6 +24,8 @@
import java.util.HashMap;
import java.util.Map;

import static org.apache.activemq.artemis.utils.Preconditions.checkNotNull;

public class JsonValueImpl implements JsonValue {

private Map<javax.json.JsonValue, JsonValue> cache = new HashMap<>();
@@ -77,6 +79,7 @@ public javax.json.JsonValue getRawValue() {
}

public JsonValueImpl(javax.json.JsonValue rawValue) {
checkNotNull(rawValue);
this.rawValue = rawValue;
}

@@ -45,6 +45,8 @@
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 NettyConnection(final Map<String, Object> configuration,
final BaseConnectionLifeCycleListener<?> listener,
boolean batchingEnabled,
boolean directDeliver) {
checkNotNull(channel);

this.configuration = configuration;

this.channel = channel;
@@ -54,6 +54,7 @@
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 @@ protected ActiveMQMessage(final ClientSession session) {
* 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 boolean waitCompletionOnStream(final long timeWait) throws JMSException {
@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();
}

@@ -25,6 +25,8 @@
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 void setReclaimable(boolean reclaimable) {
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;
@@ -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<JournalFile> fileUpdates;

public JournalRecord(final JournalFile addFile, final int size) {
checkNotNull(addFile);

this.addFile = addFile;

this.size = size;
@@ -1779,11 +1779,16 @@ public final org.apache.activemq.artemis.api.core.Message setLastValueProperty(S

@Override
public String toString() {
MessageDataScanningStatus scanningStatus = getDataScanningStatus();
Map<String, Object> 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() +
@@ -26,6 +26,8 @@

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;
}

@@ -332,7 +332,7 @@ public int hashCode() {
}

int hash = mcfProperties.hashCode();
hash += 31 * ra.hashCode();
hash += 31 * (ra != null ? ra.hashCode() : 0);

return hash;
}
@@ -22,6 +22,8 @@
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 + ")");
}
@@ -24,13 +24,17 @@
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);

private final Page page;
private final int numberOfMessages;

public PageReader(Page page, int numberOfMessages) {
checkNotNull(page);

this.page = page;
this.numberOfMessages = numberOfMessages;
}
@@ -24,6 +24,8 @@
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 PersistedRole() {
}

public PersistedRole(String username, List<String> roles) {
checkNotNull(username);
checkNotNull(roles);

this.username = username;
this.roles = roles;
}
@@ -95,10 +100,12 @@ public String toString() {
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("]]");
@@ -25,13 +25,18 @@
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;

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 String toString() {

// 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);

@@ -25,6 +25,8 @@
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 String toString() {
public PersistentAddressBindingEncoding(final SimpleString name,
final EnumSet<RoutingType> routingTypes,
final boolean autoCreated) {
checkNotNull(name);
checkNotNull(routingTypes);

this.name = name;
this.routingTypes = routingTypes;
this.autoCreated = autoCreated;
@@ -125,7 +125,7 @@ public synchronized int getEncodeSize() {

@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
@@ -24,6 +24,8 @@
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 @@ private static BackupRegistrationProblem getType(int type) {

public BackupReplicationStartFailedMessage(BackupRegistrationProblem registrationProblem) {
super(BACKUP_REGISTRATION_FAILED);

checkNotNull(registrationProblem);

problem = registrationProblem;
}

@@ -104,6 +109,6 @@ public int hashCode() {

@Override
protected String getPacketString() {
return super.getPacketString() + ", problem=" + problem.name();
return super.getPacketString() + ", problem=" + (problem != null ? problem.name() : null);
}
}
@@ -42,6 +42,8 @@
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;
}
@@ -319,11 +319,16 @@ public int getMessageMemoryEstimate() {

@Override
public String toString() {
return "Reference[" + getMessage().getMessageID() +
"]:" +
(getMessage().isDurable() ? "RELIABLE" : "NON-RELIABLE") +
":" +
getMessage();
Message message = getMessage();
if (message != null) {
return "Reference[" + message.getMessageID() +
"]:" +
(message.isDurable() ? "RELIABLE" : "NON-RELIABLE") +
":" +
message;
} else {
return "Reference[]";
}
}

@Override

0 comments on commit 3f7f8c0

Please sign in to comment.