https://issues.apache.org/jira/browse/AMQ-5136 - fix and test (thanks barlabanov)