ARTEMIS-3394 ClassCastException when queue & divert have same name

This commit is contained in:
Justin Bertram 2021-07-21 09:26:43 -05:00 committed by Clebert Suconic
parent 5ebaebdfa3
commit 55533ae099
3 changed files with 34 additions and 4 deletions

View File

@ -501,4 +501,7 @@ public interface ActiveMQMessageBundle {
@Message(id = 229234, value = "Invalid slow consumer threshold measurement unit {0}", format = Message.Format.MESSAGE_FORMAT)
IllegalArgumentException invalidSlowConsumerThresholdMeasurementUnit(String val);
@Message(id = 229235, value = "Incompatible binding with name {0} already exists: {1}", format = Message.Format.MESSAGE_FORMAT)
ActiveMQIllegalStateException bindingAlreadyExists(String name, String binding);
}

View File

@ -3742,12 +3742,16 @@ public class ActiveMQServerImpl implements ActiveMQServer {
throw ActiveMQMessageBundle.BUNDLE.invalidQueueName(queueConfiguration.getName());
}
final QueueBinding binding = (QueueBinding) postOffice.getBinding(queueConfiguration.getName());
if (binding != null) {
final Binding rawBinding = postOffice.getBinding(queueConfiguration.getName());
if (rawBinding != null) {
if (rawBinding.getType() != BindingType.LOCAL_QUEUE) {
throw ActiveMQMessageBundle.BUNDLE.bindingAlreadyExists(queueConfiguration.getName().toString(), rawBinding.toManagementString());
}
final QueueBinding queueBinding = (QueueBinding) rawBinding;
if (ignoreIfExists) {
return binding.getQueue();
return queueBinding.getQueue();
} else {
throw ActiveMQMessageBundle.BUNDLE.queueAlreadyExists(queueConfiguration.getName(), binding.getAddress());
throw ActiveMQMessageBundle.BUNDLE.queueAlreadyExists(queueConfiguration.getName(), queueBinding.getAddress());
}
}

View File

@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
import org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException;
import org.apache.activemq.artemis.api.core.Message;
import org.apache.activemq.artemis.api.core.QueueConfiguration;
@ -57,6 +58,7 @@ import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.core.settings.impl.DeletionPolicy;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.CFUtil;
import org.apache.activemq.artemis.tests.util.RandomUtil;
import org.apache.activemq.command.ActiveMQTopic;
import org.junit.Assert;
import org.junit.Test;
@ -179,6 +181,27 @@ public class DivertTest extends ActiveMQTestBase {
Assert.assertNull(consumer2.receiveImmediate());
}
@Test
public void testDivertAndQueueWithSameName() throws Exception {
final String name = RandomUtil.randomString();
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig()
.addDivertConfiguration(new DivertConfiguration()
.setName(name)
.setRoutingName(RandomUtil.randomString())
.setAddress(RandomUtil.randomString())
.setForwardingAddress(RandomUtil.randomString())), false));
server.start();
try {
server.createQueue(new QueueConfiguration(name));
fail();
} catch (ActiveMQIllegalStateException e) {
// expected
}
}
@Test
public void testCrossProtocol() throws Exception {
final String testForConvert = "testConvert";