Steps to reproduce the issue:
- Unpack clean "apache-activemq-5.6.0-bin.zip" to local drive.
- Change the default configuration to use the mKahaDB adapter and per-destination instances (exactly as given at http://activemq.apache.org/kahadb.html in the very last config snippet). See also attached activemq.xml
- Start up ActiveMQ from bin/activemq.bat
- Run a small test program that simply creates a Topic and attempts to consume (that main point here is that the Topic is created and due to "per-destination" mKahaDB, a folder is created in the data directory specifically for this Topic.
- Shutdown ActiveMQ normally.
- Restart ActiveMQ normally, and the ArrayIndexOutOfBoundsException will be thrown. (see attached activemq.log)
I have done some investigation and it seems that on restart when it is attempting to "registerExistingAdapter", it wants to register each adapter with one of the destinations (the first in fact) that each adapter applies to (adapter.getDestinations()...). However, in getDestinations(), empty topics get filtered out of the return value, and since we are using per-destination="true" there can be adapters for topics only and so a chance that getDestinations() returns an empty List. Hence causing the Exception when trying to access the first destination from that list.
The reason that I haven't gone further, to supply a patch, is that I am unsure of what would be an appropriate way to register these adapters, or if you could leave them and not register them anyway, since they are empty topics.
Note, that if you extend the configuration of the mKahaDB adapter to provide an explicit adapter for all topics, then the issue goes away. (see commented part of mKahaDB config in activemq.xml attached)