Remove redundant null checks

This commit is contained in:
Ville Skyttä 2016-03-05 11:29:34 +02:00 committed by Clebert Suconic
parent 8cbcc809a4
commit 31404f8a38
21 changed files with 36 additions and 72 deletions

View File

@ -809,9 +809,7 @@ public final class ServerLocatorImpl implements ServerLocatorInternal, Discovery
// how the sendSubscription happens.
// in case this ever changes.
if (topology != null && !factory.waitForTopology(callTimeout, TimeUnit.MILLISECONDS)) {
if (factory != null) {
factory.cleanup();
}
factory.cleanup();
throw ActiveMQClientMessageBundle.BUNDLE.connectionTimedOutOnReceiveTopology(discoveryGroup);
}

View File

@ -81,7 +81,7 @@ public class SSLSupport {
private static TrustManager[] loadTrustManager(final String trustStoreProvider,
final String trustStorePath,
final String trustStorePassword) throws Exception {
if (trustStorePath == null && (trustStoreProvider == null || (trustStoreProvider != null && !"PKCS11".equals(trustStoreProvider.toUpperCase())))) {
if (trustStorePath == null && (trustStoreProvider == null || !"PKCS11".equals(trustStoreProvider.toUpperCase()))) {
return null;
}
else {
@ -120,7 +120,7 @@ public class SSLSupport {
private static KeyManager[] loadKeyManagers(final String keyStoreProvider,
final String keystorePath,
final String keystorePassword) throws Exception {
if (keystorePath == null && (keyStoreProvider == null || (keyStoreProvider != null && !"PKCS11".equals(keyStoreProvider.toUpperCase())))) {
if (keystorePath == null && (keyStoreProvider == null || !"PKCS11".equals(keyStoreProvider.toUpperCase()))) {
return null;
}
else {

View File

@ -49,12 +49,10 @@ public class CallbackCache<Callback extends SubmitInfo> {
if (retValue == null) {
throw new NullPointerException("You should initialize the pool before using it");
}
if (retValue != null) {
available--;
get++;
if (get >= size) {
get = 0;
}
available--;
get++;
if (get >= size) {
get = 0;
}
return retValue;
}

View File

@ -109,8 +109,7 @@ public class Jms {
public static boolean isHttpMessage(Message message) {
try {
Boolean aBoolean = message.getBooleanProperty(HttpMessageHelper.POSTED_AS_HTTP_MESSAGE);
return aBoolean != null && aBoolean.booleanValue() == true;
return message.getBooleanProperty(HttpMessageHelper.POSTED_AS_HTTP_MESSAGE);
}
catch (JMSException e) {
return false;

View File

@ -1236,7 +1236,7 @@ final class PageSubscriptionImpl implements PageSubscription {
else if (ignored) {
positionIgnored(message.getPosition());
}
} while (message != null && !match);
} while (!match);
if (message != null) {
lastOperation = lastPosition;

View File

@ -2943,12 +2943,10 @@ public class QueueImpl implements Queue {
props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
if (connection != null) {
props.putSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(connection.getRemoteAddress()));
props.putSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(connection.getRemoteAddress()));
if (connection.getID() != null) {
props.putSimpleStringProperty(ManagementHelper.HDR_CONNECTION_NAME, SimpleString.toSimpleString(connection.getID().toString()));
}
if (connection.getID() != null) {
props.putSimpleStringProperty(ManagementHelper.HDR_CONNECTION_NAME, SimpleString.toSimpleString(connection.getID().toString()));
}
props.putLongProperty(ManagementHelper.HDR_CONSUMER_NAME, serverConsumer.getID());

View File

@ -682,9 +682,7 @@ public class ServerConsumerImpl implements ServerConsumer, ReadyListener {
if (ref == null) {
ActiveMQIllegalStateException ils = ActiveMQMessageBundle.BUNDLE.consumerNoReference(id, messageID, messageQueue.getName());
if (tx != null) {
tx.markAsRollbackOnly(ils);
}
tx.markAsRollbackOnly(ils);
throw ils;
}
@ -752,9 +750,7 @@ public class ServerConsumerImpl implements ServerConsumer, ReadyListener {
if (ref == null) {
ActiveMQIllegalStateException ils = new ActiveMQIllegalStateException("Cannot find ref to ack " + messageID);
if (tx != null) {
tx.markAsRollbackOnly(ils);
}
tx.markAsRollbackOnly(ils);
throw ils;
}

View File

@ -392,13 +392,14 @@ public class ManagementServiceImpl implements ManagementService {
catch (Exception e) {
ActiveMQServerLogger.LOGGER.managementOperationError(e, operation, resourceName);
reply.putBooleanProperty(ManagementHelper.HDR_OPERATION_SUCCEEDED, false);
String exceptionMessage = e.getMessage();
String exceptionMessage;
if (e instanceof InvocationTargetException) {
exceptionMessage = ((InvocationTargetException) e).getTargetException().getMessage();
}
if (e != null) {
ManagementHelper.storeResult(reply, exceptionMessage);
else {
exceptionMessage = e.getMessage();
}
ManagementHelper.storeResult(reply, exceptionMessage);
}
}
else {
@ -415,13 +416,14 @@ public class ManagementServiceImpl implements ManagementService {
catch (Exception e) {
ActiveMQServerLogger.LOGGER.managementAttributeError(e, attribute, resourceName);
reply.putBooleanProperty(ManagementHelper.HDR_OPERATION_SUCCEEDED, false);
String exceptionMessage = e.getMessage();
String exceptionMessage;
if (e instanceof InvocationTargetException) {
exceptionMessage = ((InvocationTargetException) e).getTargetException().getMessage();
}
if (e != null) {
ManagementHelper.storeResult(reply, exceptionMessage);
else {
exceptionMessage = e.getMessage();
}
ManagementHelper.storeResult(reply, exceptionMessage);
}
}
}

View File

@ -52,7 +52,7 @@ public class ActiveMQSecurityManagerImpl implements ActiveMQSecurityManager {
User user = configuration.getUser(username);
return user != null && user.isValid(username, password);
}
else if (username == null && password == null) {
else if (password == null) {
return configuration.getDefaultUser() != null;
}
else { // the only possible case here is user == null, password != null

View File

@ -246,9 +246,7 @@ public class LDAPLoginModule implements LoginModule {
}
}
catch (URISyntaxException e) {
if (context != null) {
close(context);
}
close(context);
FailedLoginException ex = new FailedLoginException("Error parsing absolute name as URI.");
ex.initCause(e);
throw ex;
@ -289,9 +287,7 @@ public class LDAPLoginModule implements LoginModule {
throw ex;
}
catch (NamingException e) {
if (context != null) {
close(context);
}
close(context);
FailedLoginException ex = new FailedLoginException("Error contacting LDAP");
ex.initCause(e);
throw ex;

View File

@ -102,9 +102,7 @@ public class JMSBridgeExample {
}
finally {
// Step 12. Be sure to close the resources!
if (jmsBridge != null) {
jmsBridge.stop();
}
jmsBridge.stop();
if (sourceContext != null) {
sourceContext.close();
}

View File

@ -60,7 +60,6 @@ public class SecurityExample {
}
// Step 5. bill tries to make a connection using wrong password
billConnection = null;
try {
billConnection = createConnection("bill", "activemq1", cf);
result = false;

View File

@ -118,7 +118,7 @@ public class JmsRollbackRedeliveryTest {
MessageConsumer consumer = session.createConsumer(destination);
TextMessage msg = (TextMessage) consumer.receive(6000000);
if (msg != null) {
if (msg != null && rolledback.put(msg.getText(), Boolean.TRUE) != null) {
if (rolledback.put(msg.getText(), Boolean.TRUE) != null) {
LOG.info("Received message " + msg.getText() + " (" + received.getAndIncrement() + ")" + msg.getJMSMessageID());
assertTrue(msg.getJMSRedelivered());
assertEquals(2, msg.getLongProperty("JMSXDeliveryCount"));
@ -155,7 +155,7 @@ public class JmsRollbackRedeliveryTest {
while (received.get() < nbMessages) {
TextMessage msg = (TextMessage) consumer.receive(6000000);
if (msg != null) {
if (msg != null && rolledback.put(msg.getText(), Boolean.TRUE) != null) {
if (rolledback.put(msg.getText(), Boolean.TRUE) != null) {
LOG.info("Received message " + msg.getText() + " (" + received.getAndIncrement() + ")" + msg.getJMSMessageID());
assertTrue(msg.getJMSRedelivered());
session.commit();
@ -190,7 +190,7 @@ public class JmsRollbackRedeliveryTest {
MessageConsumer consumer = session.createConsumer(destination);
TextMessage msg = (TextMessage) consumer.receive(6000000);
if (msg != null) {
if (msg != null && rolledback.put(msg.getText(), Boolean.TRUE) != null) {
if (rolledback.put(msg.getText(), Boolean.TRUE) != null) {
LOG.info("Received message " + msg.getText() + " (" + received.getAndIncrement() + ")" + msg.getJMSMessageID());
assertTrue(msg.getJMSRedelivered());
session.commit();

View File

@ -75,9 +75,7 @@ public class AMQ4671Test {
}
}
finally {
if (connection != null) {
connection.close();
}
connection.close();
}
}
}

View File

@ -319,12 +319,10 @@ public class AMQ4952Test {
// network to consumerBroker
if (networkToPorts != null && networkToPorts.length > 0) {
if (networkToPorts.length > 0) {
StringBuilder builder = new StringBuilder("static:(failover:(tcp://localhost:2006)?maxReconnectAttempts=0)?useExponentialBackOff=false");
NetworkConnector nc = broker.addNetworkConnector(builder.toString());
if (networkProps != null) {
IntrospectionSupport.setProperties(nc, networkProps);
}
IntrospectionSupport.setProperties(nc, networkProps);
nc.setStaticallyIncludedDestinations(Arrays.<ActiveMQDestination>asList(new ActiveMQQueue[]{QUEUE_NAME}));
}

View File

@ -121,9 +121,7 @@ public class RedeliveryPluginHeaderTest extends TestCase {
}
finally {
if (connection != null) {
connection.close();
}
connection.close();
if (broker != null) {
broker.stop();

View File

@ -398,9 +398,7 @@ public class ConfigTest {
LOG.info("Success");
}
finally {
if (broker != null) {
broker.stop();
}
broker.stop();
}
}

View File

@ -39,9 +39,6 @@ public class ActiveMQInitialContextFactoryTest extends JNDITestSupport {
InitialContext context = new InitialContext();
// make sure context is not null
assertTrue("Created context", context != null);
Object topicDestination = context.lookup("MyTopic");
// check if MyTopic is an ActiveMQTopic

View File

@ -37,7 +37,6 @@ public class InitialContextTest extends TestCase {
public void testInitialContext() throws Exception {
InitialContext context = new InitialContext();
assertTrue("Created context", context != null);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
@ -49,7 +48,6 @@ public class InitialContextTest extends TestCase {
public void testInitialContextHasXA() throws Exception {
InitialContext context = new InitialContext();
assertTrue("Created context", context != null);
ActiveMQXAConnectionFactory connectionFactory = (ActiveMQXAConnectionFactory) context.lookup("XAConnectionFactory");
@ -66,7 +64,6 @@ public class InitialContextTest extends TestCase {
properties.put(Context.PROVIDER_URL, expected);
InitialContext context = new InitialContext(properties);
assertTrue("Created context", context != null);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
@ -85,7 +82,6 @@ public class InitialContextTest extends TestCase {
properties.put("redeliveryPolicy.backOffMultiplier", "32");
InitialContext context = new InitialContext(properties);
assertTrue("Created context", context != null);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");

View File

@ -187,7 +187,6 @@ public class DivertTest extends ActiveMQTestBase {
}
int count2 = 0;
message = null;
while ((message = consumer2.receiveImmediate()) != null) {
message.acknowledge();
count2++;

View File

@ -370,9 +370,7 @@ public class JMSServerControlTest extends ManagementTestBase {
Assert.assertNotNull(cons.receive(5000));
}
finally {
if (connection != null) {
connection.close();
}
connection.close();
}
}
@ -415,9 +413,7 @@ public class JMSServerControlTest extends ManagementTestBase {
Assert.assertNotNull(cons.receive(5000));
}
finally {
if (connection != null) {
connection.close();
}
connection.close();
}
}