ARTEMIS-1951 Fix NPE on updateQueue with NULL user

This commit is contained in:
Francesco Nigro 2018-07-02 09:18:39 +02:00 committed by Justin Bertram
parent 8d78972673
commit 60c586a64c
3 changed files with 76 additions and 2 deletions

View File

@ -512,6 +512,11 @@ public class PostOfficeImpl implements PostOffice, NotificationListener, Binding
changed = true;
queue.setExclusive(exclusive);
}
if (logger.isDebugEnabled()) {
if (user == null && queue.getUser() != null) {
logger.debug("Ignoring updating Queue to a NULL user");
}
}
if (user != null && !user.equals(queue.getUser())) {
changed = true;
queue.setUser(user);

View File

@ -2970,7 +2970,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
Boolean purgeOnNoConsumers,
Boolean exclusive,
String user) throws Exception {
final QueueBinding queueBinding = this.postOffice.updateQueue(new SimpleString(name), routingType, maxConsumers, purgeOnNoConsumers, exclusive, new SimpleString(user));
final QueueBinding queueBinding = this.postOffice.updateQueue(new SimpleString(name), routingType, maxConsumers, purgeOnNoConsumers, exclusive, SimpleString.toSimpleString(user));
if (queueBinding != null) {
final Queue queue = queueBinding.getQueue();
return queue;

View File

@ -21,7 +21,6 @@ import javax.jms.Connection;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;
@ -39,6 +38,76 @@ import org.junit.Test;
public class UpdateQueueTest extends ActiveMQTestBase {
@Test
public void testUpdateQueueWithNullUser() throws Exception {
ActiveMQServer server = createServer(true, true);
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
server.start();
SimpleString ADDRESS = SimpleString.toSimpleString("queue.0");
final SimpleString user = new SimpleString("newUser");
Queue queue = server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, user, null, true, false);
long originalID = queue.getID();
Assert.assertEquals(user, queue.getUser());
Connection conn = factory.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = session.createProducer(session.createQueue(ADDRESS.toString()));
for (int i = 0; i < 100; i++) {
prod.send(session.createTextMessage("message " + i));
}
server.updateQueue(ADDRESS.toString(), RoutingType.ANYCAST, 1, false, false, null);
conn.close();
factory.close();
server.stop();
server.start();
validateBindingRecords(server, JournalRecordIds.QUEUE_BINDING_RECORD, 2);
queue = server.locateQueue(ADDRESS);
Assert.assertNotNull("queue not found", queue);
Assert.assertEquals("newUser", user, queue.getUser());
factory = new ActiveMQConnectionFactory();
conn = factory.createConnection();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(ADDRESS.toString()));
conn.start();
for (int i = 0; i < 100; i++) {
Assert.assertNotNull(consumer.receive(5000));
}
Assert.assertNull(consumer.receiveNoWait());
Assert.assertEquals(1, queue.getMaxConsumers());
conn.close();
Assert.assertEquals(originalID, server.locateQueue(ADDRESS).getID());
// stopping, restarting to make sure the system will not create an extra record without an udpate
server.stop();
server.start();
validateBindingRecords(server, JournalRecordIds.QUEUE_BINDING_RECORD, 2);
server.stop();
}
@Test
public void testUpdateQueue() throws Exception {
ActiveMQServer server = createServer(true, true);