SpotBugs Report

Project Information

Project: ActiveMQ :: Performance Test Plugin

SpotBugs version: 4.8.3

Code analyzed:



Metrics

2513 lines of code analyzed, in 46 classes, in 8 packages.

Metric Total Density*
High Priority Warnings 6 2.39
Medium Priority Warnings 52 20.69
Total Warnings 58 23.08

(* Defects per Thousand lines of non-commenting source statements)



Contents

Summary

Warning Type Number
Bad practice Warnings 1
Internationalization Warnings 6
Malicious code vulnerability Warnings 31
Multithreaded correctness Warnings 3
Performance Warnings 11
Dodgy code Warnings 6
Total 58

Warnings

Click on a warning row to see full context information.

Bad practice Warnings

Code Warning
RV Exceptional return value of java.io.File.mkdirs() ignored in org.apache.activemq.maven.ServerMojo.execute()

Internationalization Warnings

Code Warning
Dm Found reliance on default encoding in org.apache.activemq.tool.JmsProducerClient.buildText(String, int): new String(byte[])
Dm Found reliance on default encoding in org.apache.activemq.tool.JmsProducerClient.loadJmsMessage(): new java.io.FileReader(File)
Dm Found reliance on default encoding in org.apache.activemq.tool.reports.XmlFilePerfReportWriter.openReportWriter(): new java.io.PrintWriter(OutputStream, boolean)
Dm Found reliance on default encoding in org.apache.activemq.tool.reports.XmlFilePerfReportWriter.writeToXml(): new java.io.PrintWriter(OutputStream)
Dm Found reliance on default encoding in org.apache.activemq.tool.reports.XmlFilePerfReportWriter.writeXmlLogFile(): new java.io.InputStreamReader(InputStream)
Dm Found reliance on default encoding in org.apache.activemq.tool.sampler.plugins.LinuxCpuSamplerPlugin.run(): new java.io.InputStreamReader(InputStream)

Malicious code vulnerability Warnings

Code Warning
DP org.apache.activemq.tool.spi.ClassLoaderSPIConnectionFactory.getContextClassLoader(Properties) creates a java.net.URLClassLoader classloader, which should be performed within a doPrivileged block
EI org.apache.activemq.tool.AbstractJmsClient.getConnection() may expose internal representation by returning AbstractJmsClient.jmsConnection
EI org.apache.activemq.tool.AbstractJmsClient.getSession() may expose internal representation by returning AbstractJmsClient.jmsSession
EI org.apache.activemq.tool.AbstractJmsClientSystem.getTpSampler() may expose internal representation by returning AbstractJmsClientSystem.tpSampler
EI org.apache.activemq.tool.JmsConsumerClient.createJmsConsumer(Destination) may expose internal representation by returning JmsConsumerClient.jmsConsumer
EI org.apache.activemq.tool.JmsConsumerClient.createJmsConsumer(Destination, String, boolean) may expose internal representation by returning JmsConsumerClient.jmsConsumer
EI org.apache.activemq.tool.JmsConsumerClient.getClient() may expose internal representation by returning JmsConsumerClient.client
EI org.apache.activemq.tool.JmsConsumerClient.getJmsConsumer() may expose internal representation by returning JmsConsumerClient.jmsConsumer
EI org.apache.activemq.tool.JmsConsumerSystem.getConsumer() may expose internal representation by returning JmsConsumerSystem.consumer
EI org.apache.activemq.tool.JmsConsumerSystem.getSysTest() may expose internal representation by returning JmsConsumerSystem.sysTest
EI org.apache.activemq.tool.JmsProducerClient.createJmsProducer() may expose internal representation by returning JmsProducerClient.jmsProducer
EI org.apache.activemq.tool.JmsProducerClient.createJmsProducer(Destination) may expose internal representation by returning JmsProducerClient.jmsProducer
EI org.apache.activemq.tool.JmsProducerClient.createJmsTextMessage(int) may expose internal representation by returning JmsProducerClient.jmsTextMessage
EI org.apache.activemq.tool.JmsProducerClient.createJmsTextMessage(String) may expose internal representation by returning JmsProducerClient.jmsTextMessage
EI org.apache.activemq.tool.JmsProducerClient.getClient() may expose internal representation by returning JmsProducerClient.client
EI org.apache.activemq.tool.JmsProducerClient.getJmsProducer() may expose internal representation by returning JmsProducerClient.jmsProducer
EI org.apache.activemq.tool.JmsProducerClient.getJmsTextMessage() may expose internal representation by returning JmsProducerClient.jmsTextMessage
EI org.apache.activemq.tool.JmsProducerSystem.getProducer() may expose internal representation by returning JmsProducerSystem.producer
EI org.apache.activemq.tool.JmsProducerSystem.getSysTest() may expose internal representation by returning JmsProducerSystem.sysTest
EI org.apache.activemq.tool.properties.JmsFactoryProperties.getFactorySettings() may expose internal representation by returning JmsFactoryProperties.factorySettings
EI org.apache.activemq.tool.sampler.AbstractPerformanceSampler.getPerfReportWriter() may expose internal representation by returning AbstractPerformanceSampler.perfReportWriter
EI2 new org.apache.activemq.tool.JmsConsumerClient(JmsConsumerProperties, ConnectionFactory) may expose internal representation by storing an externally mutable object into JmsConsumerClient.client
EI2 org.apache.activemq.tool.JmsConsumerClient.setClient(JmsClientProperties) may expose internal representation by storing an externally mutable object into JmsConsumerClient.client
EI2 org.apache.activemq.tool.JmsConsumerSystem.setConsumer(JmsConsumerProperties) may expose internal representation by storing an externally mutable object into JmsConsumerSystem.consumer
EI2 org.apache.activemq.tool.JmsConsumerSystem.setSysTest(JmsClientSystemProperties) may expose internal representation by storing an externally mutable object into JmsConsumerSystem.sysTest
EI2 new org.apache.activemq.tool.JmsProducerClient(JmsProducerProperties, ConnectionFactory) may expose internal representation by storing an externally mutable object into JmsProducerClient.client
EI2 org.apache.activemq.tool.JmsProducerClient.setClient(JmsClientProperties) may expose internal representation by storing an externally mutable object into JmsProducerClient.client
EI2 org.apache.activemq.tool.JmsProducerSystem.setProducer(JmsProducerProperties) may expose internal representation by storing an externally mutable object into JmsProducerSystem.producer
EI2 org.apache.activemq.tool.JmsProducerSystem.setSysTest(JmsClientSystemProperties) may expose internal representation by storing an externally mutable object into JmsProducerSystem.sysTest
EI2 org.apache.activemq.tool.sampler.AbstractPerformanceSampler.setPerfReportWriter(PerformanceReportWriter) may expose internal representation by storing an externally mutable object into AbstractPerformanceSampler.perfReportWriter
EI2 new org.apache.activemq.tool.sampler.RampDownNotifier(PerformanceSampler) may expose internal representation by storing an externally mutable object into RampDownNotifier.sampler

Multithreaded correctness Warnings

Code Warning
JLM Synchronization performed on java.util.concurrent.atomic.AtomicInteger in org.apache.activemq.tool.JmsConsumerClient.receiveAsyncCountBasedMessages(long)
JLM Synchronization performed on java.util.concurrent.atomic.AtomicInteger in org.apache.activemq.tool.JmsConsumerClient$2.onMessage(Message)
UW Unconditional wait in org.apache.activemq.tool.JmsConsumerClient.receiveAsyncCountBasedMessages(long)

Performance Warnings

Code Warning
Bx org.apache.activemq.tool.properties.ReflectionUtil.configureClass(Object, String, String) invokes inefficient new Character(char) constructor; use Character.valueOf(char) instead
Bx Boxed value is unboxed and then immediately reboxed in org.apache.activemq.tool.sampler.AbstractPerformanceSampler.startSampler(CountDownLatch, ClientRunBasis, long)
Dm org.apache.activemq.tool.properties.JmsConsumerProperties.setMessageSelector(String) invokes inefficient new String(String) constructor
SBSC org.apache.activemq.tool.AbstractJmsClient.createCompositeDestination(byte, String, int) concatenates strings using + in a loop
SBSC org.apache.activemq.tool.AbstractJmsClientSystem.setProviderMetaData(ConnectionMetaData, JmsClientProperties) concatenates strings using + in a loop
SBSC org.apache.activemq.tool.properties.ReflectionUtil.configureClass(Object, String, String) concatenates strings using + in a loop
SBSC org.apache.activemq.tool.reports.XmlFilePerfReportWriter.parsePerfCsvData(String, String) concatenates strings using + in a loop
SBSC org.apache.activemq.tool.sampler.plugins.LinuxCpuSamplerPlugin.convertToCSV(String, String) concatenates strings using + in a loop
WMI org.apache.activemq.tool.reports.XmlFilePerfReportWriter.writeMap(String, Map) makes inefficient use of keySet iterator instead of entrySet iterator
WMI org.apache.activemq.tool.reports.XmlFilePerfReportWriter.writeXmlTestSettings() makes inefficient use of keySet iterator instead of entrySet iterator
WMI org.apache.activemq.tool.reports.plugins.ThroughputReportPlugin.getSummary() makes inefficient use of keySet iterator instead of entrySet iterator

Dodgy code Warnings

Code Warning
BC Unchecked/unconfirmed cast from org.apache.activemq.tool.properties.JmsClientProperties to org.apache.activemq.tool.properties.JmsConsumerProperties in org.apache.activemq.tool.JmsConsumerClient.setClient(JmsClientProperties)
BC Unchecked/unconfirmed cast from org.apache.activemq.tool.properties.JmsClientSystemProperties to org.apache.activemq.tool.properties.JmsConsumerSystemProperties in org.apache.activemq.tool.JmsConsumerSystem.setSysTest(JmsClientSystemProperties)
BC Unchecked/unconfirmed cast from org.apache.activemq.tool.properties.JmsClientProperties to org.apache.activemq.tool.properties.JmsProducerProperties in org.apache.activemq.tool.JmsProducerClient.setClient(JmsClientProperties)
BC Unchecked/unconfirmed cast from org.apache.activemq.tool.properties.JmsClientSystemProperties to org.apache.activemq.tool.properties.JmsProducerSystemProperties in org.apache.activemq.tool.JmsProducerSystem.setSysTest(JmsClientSystemProperties)
NP Load of known null value in org.apache.activemq.tool.sampler.CpuSamplerTask.createPlugin(String)
REC Exception is caught when Exception is not thrown in org.apache.activemq.tool.properties.ReflectionUtil.configureClass(Object, String, String)

Details

BC_UNCONFIRMED_CAST: Unchecked/unconfirmed cast

This cast is unchecked, and not all instances of the type cast from can be cast to the type it is being cast to. Check that your program logic ensures that this cast will not fail.

BX_UNBOXING_IMMEDIATELY_REBOXED: Boxed value is unboxed and then immediately reboxed

A boxed value is unboxed and then immediately reboxed.

DM_NUMBER_CTOR: Method invokes inefficient Number constructor; use static valueOf instead

Using new Integer(int) is guaranteed to always result in a new object whereas Integer.valueOf(int) allows caching of values to be done by the compiler, class library, or JVM. Using of cached values avoids object allocation and the code will be faster.

Values between -128 and 127 are guaranteed to have corresponding cached instances and using valueOf is approximately 3.5 times faster than using constructor. For values outside the constant range the performance of both styles is the same.

Unless the class must be compatible with JVMs predating Java 5, use either autoboxing or the valueOf() method when creating instances of Long, Integer, Short, Character, and Byte.

DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED: Classloaders should only be created inside doPrivileged block

This code creates a classloader, which needs permission if a security manage is installed. If this code might be invoked by code that does not have security permissions, then the classloader creation needs to occur inside a doPrivileged block.

DM_STRING_CTOR: Method invokes inefficient new String(String) constructor

Using the java.lang.String(String) constructor wastes memory because the object so constructed will be functionally indistinguishable from the String passed as a parameter.  Just use the argument String directly.

DM_DEFAULT_ENCODING: Reliance on default encoding

Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behavior to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.

EI_EXPOSE_REP: May expose internal representation by returning reference to mutable object

Returning a reference to a mutable object value stored in one of the object's fields exposes the internal representation of the object.  If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. Returning a new copy of the object is better approach in many situations.

EI_EXPOSE_REP2: May expose internal representation by incorporating reference to mutable object

This code stores a reference to an externally mutable object into the internal representation of the object.  If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. Storing a copy of the object is better approach in many situations.

JLM_JSR166_UTILCONCURRENT_MONITORENTER: Synchronization performed on util.concurrent instance

This method performs synchronization on an object that is an instance of a class from the java.util.concurrent package (or its subclasses). Instances of these classes have their own concurrency control mechanisms that are orthogonal to the synchronization provided by the Java keyword synchronized. For example, synchronizing on an AtomicBoolean will not prevent other threads from modifying the AtomicBoolean.

Such code may be correct, but should be carefully reviewed and documented, and may confuse people who have to maintain the code at a later date.

NP_LOAD_OF_KNOWN_NULL_VALUE: Load of known null value

The variable referenced at this point is known to be null due to an earlier check against null. Although this is valid, it might be a mistake (perhaps you intended to refer to a different variable, or perhaps the earlier check to see if the variable is null should have been a check to see if it was non-null).

REC_CATCH_EXCEPTION: Exception is caught when Exception is not thrown

This method uses a try-catch block that catches Exception objects, but Exception is not thrown within the try block, and RuntimeException is not explicitly caught. It is a common bug pattern to say try { ... } catch (Exception e) { something } as a shorthand for catching a number of types of exception each of whose catch blocks is identical, but this construct also accidentally catches RuntimeException as well, masking potential bugs.

A better approach is to either explicitly catch the specific exceptions that are thrown, or to explicitly catch RuntimeException exception, rethrow it, and then catch all non-Runtime Exceptions, as shown below:

try {
    ...
} catch (RuntimeException e) {
    throw e;
} catch (Exception e) {
    ... deal with all non-runtime exceptions ...
}

RV_RETURN_VALUE_IGNORED_BAD_PRACTICE: Method ignores exceptional return value

This method returns a value that is not checked. The return value should be checked since it can indicate an unusual or unexpected function execution. For example, the File.delete() method returns false if the file could not be successfully deleted (rather than throwing an Exception). If you don't check the result, you won't notice if the method invocation signals unexpected behavior by returning an atypical return value.

SBSC_USE_STRINGBUFFER_CONCATENATION: Method concatenates strings using + in a loop

The method seems to be building a String using concatenation in a loop. In each iteration, the String is converted to a StringBuffer/StringBuilder, appended to, and converted back to a String. This can lead to a cost quadratic in the number of iterations, as the growing string is recopied in each iteration.

Better performance can be obtained by using a StringBuffer (or StringBuilder in Java 5) explicitly.

For example:

// This is bad
String s = "";
for (int i = 0; i < field.length; ++i) {
    s = s + field[i];
}

// This is better
StringBuffer buf = new StringBuffer();
for (int i = 0; i < field.length; ++i) {
    buf.append(field[i]);
}
String s = buf.toString();

UW_UNCOND_WAIT: Unconditional wait

This method contains a call to java.lang.Object.wait() which is not guarded by conditional control flow. The code should verify that condition it intends to wait for is not already satisfied before calling wait; any previous notifications will be ignored.

WMI_WRONG_MAP_ITERATOR: Inefficient use of keySet iterator instead of entrySet iterator

This method accesses the value of a Map entry, using a key that was retrieved from a keySet iterator. It is more efficient to use an iterator on the entrySet of the map, to avoid the Map.get(key) lookup.