Bug 915333 - Java client raises javax.jms.JMSException instead of InvalidDestinationException in BasicMessageProducer.send() method
Summary: Java client raises javax.jms.JMSException instead of InvalidDestinationExcept...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise MRG
Classification: Red Hat
Component: qpid-java
Version: 2.3
Hardware: All
OS: All
medium
low
Target Milestone: 3.1
: ---
Assignee: Pavel Moravec
QA Contact: Michal Toth
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-02-25 14:32 UTC by Pavel Moravec
Modified: 2019-06-13 07:52 UTC (History)
8 users (show)

Fixed In Version: qpid-java-0.30-2
Doc Type: Bug Fix
Doc Text:
It was discovered that the javax.jms.JMSException raised when attempting to send a message to an invalid destination in the Java client was too generalized. This causes problems with exception handling in a Java application. The client has been improved to raise a proper InvalidDestinationException for this particular use case, which fixes the issue.
Clone Of:
Environment:
Last Closed: 2015-04-14 13:46:26 UTC
Target Upstream Version:


Attachments (Terms of Use)
reproducer (JUnit test) (1.29 KB, application/gzip)
2013-02-25 14:36 UTC, Pavel Moravec
no flags Details
Trivial patch (2.21 KB, patch)
2013-02-25 15:45 UTC, Pavel Moravec
no flags Details | Diff
Reproducer (stand-alone) (3.45 KB, text/x-java)
2013-08-02 14:45 UTC, Ernie
no flags Details


Links
System ID Priority Status Summary Last Updated
Apache JIRA QPID-5931 None None None Never
Red Hat Product Errata RHEA-2015:0805 normal SHIPPED_LIVE Red Hat Enterprise MRG Messaging 3.1 Release 2015-04-14 17:45:54 UTC

Description Pavel Moravec 2013-02-25 14:32:00 UTC
Description of problem:
Trying to send a message to a temporary address that does not further exists raises javax.jms.JMSException while InvalidDestinationException should be raised instead.


Version-Release number of selected component (if applicable):
qpid-java-*-0.18-7


How reproducible:
100%


Steps to Reproduce:
Run attached JUnit test


Actual results:
JUnit version 4.10
.log4j:WARN No appenders could be found for logger (org.apache.qpid.jndi.PropertiesFileInitialContextFactory).
log4j:WARN Please initialize the log4j system properly.
javax.jms.JMSException: Session for temporary destination has been closed
	at org.apache.qpid.client.BasicMessageProducer.checkTemporaryDestination(BasicMessageProducer.java:550)
	at org.apache.qpid.client.BasicMessageProducer.sendImpl(BasicMessageProducer.java:493)
	at org.apache.qpid.client.BasicMessageProducer.send(BasicMessageProducer.java:309)
	at InvalidDestinationTest.sendToTempQueueWhenItDoesNotExist(InvalidDestinationTest.java:88)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:24)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
	at org.junit.runner.JUnitCore.runMain(JUnitCore.java:98)
	at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:53)
	at org.junit.runner.JUnitCore.main(JUnitCore.java:45)
E
Time: 0.509
There was 1 failure:
1) sendToTempQueueWhenItDoesNotExist(InvalidDestinationTest)
java.lang.AssertionError: Unexpected exception type
	at org.junit.Assert.fail(Assert.java:93)
	at InvalidDestinationTest.sendToTempQueueWhenItDoesNotExist(InvalidDestinationTest.java:97)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:24)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
	at org.junit.runner.JUnitCore.runMain(JUnitCore.java:98)
	at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:53)
	at org.junit.runner.JUnitCore.main(JUnitCore.java:45)

FAILURES!!!
Tests run: 1,  Failures: 1


Expected results:
Test passes.


Additional info:

Comment 1 Pavel Moravec 2013-02-25 14:36:20 UTC
Created attachment 702368 [details]
reproducer (JUnit test)

Comment 2 Pavel Moravec 2013-02-25 15:45:48 UTC
Created attachment 702400 [details]
Trivial patch

Trivial patch based on qpid-java-* 0.18-2 version.

Comment 3 Rajith Attapattu 2013-07-23 15:07:10 UTC
Fixed upstream at http://svn.apache.org/r1506095

Comment 4 Ernie 2013-08-02 14:45:54 UTC
Created attachment 781984 [details]
Reproducer (stand-alone)

Stand-alone reproducer that raises javax.jms.JMSException instead of InvalidDestinationException.

The stack trace shows that BasicMessageProducer.checkTemporaryDestination() is the source of the exception. 

Note: Pavel's patch modified the checkTemporaryDestination() method, but the upstream fix at http://svn.apache.org/r1506095 doesn't. It modifies validateDestination().

Output from this reproducer:
javax.jms.JMSException: Session for temporary destination has been closed
	at org.apache.qpid.client.BasicMessageProducer.checkTemporaryDestination(BasicMessageProducer.java:539)
	at org.apache.qpid.client.BasicMessageProducer.sendImpl(BasicMessageProducer.java:482)
	at org.apache.qpid.client.BasicMessageProducer.send(BasicMessageProducer.java:298)
	at org.apache.qpid.example.InvalidDestination.runTest(InvalidDestination.java:83)
	at org.apache.qpid.example.InvalidDestination.main(InvalidDestination.java:50)
Fail - Unexpected exception type
class javax.jms.JMSException

Comment 5 Ernie 2013-08-02 15:34:05 UTC
Returning to ASSIGNED since the old exception is still being raised from checkTemporaryDestination() as reported in the original bz description.
See comment 4

Tested on rhel 6.4
qpid-java-client-0.22-5.el6.noarch
qpid-java-common-0.22-5.el6.noarch
qpid-java-example-0.22-5.el6.noarch

Comment 6 Pavel Moravec 2013-08-12 08:24:29 UTC
(In reply to Ernie from comment #5)
> Returning to ASSIGNED since the old exception is still being raised from
> checkTemporaryDestination() as reported in the original bz description.
> See comment 4
> 
> Tested on rhel 6.4
> qpid-java-client-0.22-5.el6.noarch
> qpid-java-common-0.22-5.el6.noarch
> qpid-java-example-0.22-5.el6.noarch

/me checking source code and execution path of the reproducer. The reproducer does not invoke validateDestination method where the patch has been applied.

Moreover, even adding a call of the method to the execution path of the reproducer does not change the behaviour. As both tests:

if (!(destination instanceof AMQDestination))
if(!amqDestination.isExchangeExistsChecked())

are evaluated to false and thus no exception can be raised.

IMHO my patch changing exceptions in checkTemporaryDestination from JMSException to InvalidDestinationException is correct. As if temporary destination check fails, "invalid destination" exception should be raised in any case.

Rajith's fix makes sense as well, but it does not fix this BZ.

I re-verified my patch on qpid-java 0.22-5 and it works fine.

Comment 7 Rajith Attapattu 2013-09-24 16:51:56 UTC
This is handled properly in the new client.

Comment 9 Pavel Moravec 2014-07-28 11:32:00 UTC
Confirming it is not fixed in qpid-java-client-0.22-6.

Having a look on it now.

Comment 10 Pavel Moravec 2014-07-28 12:42:44 UTC
Fixed in upstream in r1613984.

Comment 15 Michal Toth 2015-04-14 12:19:04 UTC
Reproduced on rhel6i using
qpid-cpp-server 0.22-51
qpid-java-client-0.22-8.el6.noarch
Wrong exception has been thrown as "expected".

Verified on both rhel6
qpid-java-common-0.30-5.el6.noarch
qpid-java-example-0.30-5.el6.noarch
qpid-java-client-0.30-5.el6.noarch

& rhel7
qpid-java-common-0.30-6.el7.noarch
qpid-java-example-0.30-6.el7.noarch
qpid-java-client-0.30-6.el7.noarch

using provided standalone reproducer with expected Exception thrown.
"Success - InvalidDestinationException exception type received"

Comment 17 errata-xmlrpc 2015-04-14 13:46:26 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHEA-2015-0805.html


Note You need to log in before you can comment on or make changes to this bug.