Skip to content

Commit 9a3530a

Browse files
committed
fix(client): validate inputs before UnsupportedOperationException in shared consumer methods (#1719)
The shared consumer methods (createSharedConsumer, createSharedDurableConsumer) threw UnsupportedOperationException immediately without validating inputs. Per the JMS spec, parameter validation must happen first: - Session: null topic now throws InvalidDestinationException, invalid selector now throws InvalidSelectorException - JMSContext: null topic now throws InvalidDestinationRuntimeException This fixes the TCK invalidDestinationExceptionTests and invalidSelectorExceptionTopicTests for Session, and the corresponding JMSContext tests.
1 parent ee63e25 commit 9a3530a

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

activemq-client/src/main/java/org/apache/activemq/ActiveMQContext.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import jakarta.jms.Destination;
2626
import jakarta.jms.ExceptionListener;
2727
import jakarta.jms.IllegalStateRuntimeException;
28+
import jakarta.jms.InvalidDestinationRuntimeException;
2829
import jakarta.jms.JMSConsumer;
2930
import jakarta.jms.JMSContext;
3031
import jakarta.jms.JMSException;
@@ -442,21 +443,37 @@ public JMSConsumer createDurableConsumer(Topic topic, String name, String messag
442443

443444
@Override
444445
public JMSConsumer createSharedDurableConsumer(Topic topic, String name) {
446+
checkContextState();
447+
if (topic == null) {
448+
throw new InvalidDestinationRuntimeException("Topic cannot be null");
449+
}
445450
throw new UnsupportedOperationException("createSharedDurableConsumer(topic, name) is not supported");
446451
}
447452

448453
@Override
449454
public JMSConsumer createSharedDurableConsumer(Topic topic, String name, String messageSelector) {
450-
throw new UnsupportedOperationException("createDurableConsumer(topic, name, messageSelector) is not supported");
455+
checkContextState();
456+
if (topic == null) {
457+
throw new InvalidDestinationRuntimeException("Topic cannot be null");
458+
}
459+
throw new UnsupportedOperationException("createSharedDurableConsumer(topic, name, messageSelector) is not supported");
451460
}
452461

453462
@Override
454463
public JMSConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName) {
464+
checkContextState();
465+
if (topic == null) {
466+
throw new InvalidDestinationRuntimeException("Topic cannot be null");
467+
}
455468
throw new UnsupportedOperationException("createSharedConsumer(topic, sharedSubscriptionName) is not supported");
456469
}
457470

458471
@Override
459472
public JMSConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName, String messageSelector) {
473+
checkContextState();
474+
if (topic == null) {
475+
throw new InvalidDestinationRuntimeException("Topic cannot be null");
476+
}
460477
throw new UnsupportedOperationException("createSharedConsumer(topic, sharedSubscriptionName, messageSelector) is not supported");
461478
}
462479

activemq-client/src/main/java/org/apache/activemq/ActiveMQSession.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import jakarta.jms.TopicSubscriber;
5959
import jakarta.jms.TransactionRolledBackException;
6060

61+
import org.apache.activemq.selector.SelectorParser;
6162
import org.apache.activemq.blob.BlobDownloader;
6263
import org.apache.activemq.blob.BlobTransferPolicy;
6364
import org.apache.activemq.blob.BlobUploader;
@@ -1386,11 +1387,22 @@ public Topic createTopic(String topicName) throws JMSException {
13861387

13871388
@Override
13881389
public MessageConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName) throws JMSException {
1390+
checkClosed();
1391+
if (topic == null) {
1392+
throw new InvalidDestinationException("Topic cannot be null");
1393+
}
13891394
throw new UnsupportedOperationException("createSharedConsumer(Topic, sharedSubscriptionName) is not supported");
13901395
}
13911396

13921397
@Override
13931398
public MessageConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName, String messageSelector) throws JMSException {
1399+
checkClosed();
1400+
if (topic == null) {
1401+
throw new InvalidDestinationException("Topic cannot be null");
1402+
}
1403+
if (messageSelector != null && !messageSelector.trim().isEmpty()) {
1404+
SelectorParser.parse(messageSelector);
1405+
}
13941406
throw new UnsupportedOperationException("createSharedConsumer(Topic, sharedSubscriptionName, messageSelector) is not supported");
13951407
}
13961408

@@ -1408,11 +1420,22 @@ public MessageConsumer createDurableConsumer(Topic topic, String name, String me
14081420

14091421
@Override
14101422
public MessageConsumer createSharedDurableConsumer(Topic topic, String name) throws JMSException {
1423+
checkClosed();
1424+
if (topic == null) {
1425+
throw new InvalidDestinationException("Topic cannot be null");
1426+
}
14111427
throw new UnsupportedOperationException("createSharedDurableConsumer(Topic, name) is not supported");
14121428
}
14131429

14141430
@Override
14151431
public MessageConsumer createSharedDurableConsumer(Topic topic, String name, String messageSelector) throws JMSException {
1432+
checkClosed();
1433+
if (topic == null) {
1434+
throw new InvalidDestinationException("Topic cannot be null");
1435+
}
1436+
if (messageSelector != null && !messageSelector.trim().isEmpty()) {
1437+
SelectorParser.parse(messageSelector);
1438+
}
14161439
throw new UnsupportedOperationException("createSharedDurableConsumer(Topic, name, messageSelector) is not supported");
14171440
}
14181441

0 commit comments

Comments
 (0)