https://issues.apache.org/jira/browse/AMQ-5016

Added test and a fix.