Description
When executing TcpTransportFactory.createTransport(URI location, WireFormat wf) the following warning is incorrectly generated:
WARNING: path isn't a valid local location for TcpTransport to use
java.lang.NumberFormatException: For input string: "/exampleTopic"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.parseInt(Integer.java:497)
at org.apache.activemq.transport.tcp.TcpTransportFactory.createTransport(TcpTransportFactory.java:125)
at org.apache.activemq.transport.TransportFactory.doConnect(TransportFactory.java:141)
at org.apache.activemq.transport.TransportFactory.doConnect(TransportFactory.java:51)
at org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:80)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:237)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:252)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:224)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:172)
...
With the topic name set to "/exampleTopic"
The code responsible for this looks like:
URI localLocation = null;
String path = location.getPath();
// see if the path is a local URI location
if (path != null && path.length() > 0) {
int localPortIndex = path.indexOf(':');
try
catch (Exception e)
{ LOG.warn("path isn't a valid local location for TcpTransport to use", e); } }
SocketFactory socketFactory = createSocketFactory();
return createTcpTransport(wf, socketFactory, location, localLocation);
}
The problem seems to be that for the path="/exampleTopic", the following line:
int localPortIndex = path.indexOf(':');
returns -1 (no colon and no port specified in path
and the subsequent line:
Integer.parseInt(path.substring(localPortIndex + 1, path.length()));
generates the NumberFormatException (because the path does not have any integer).
It seems that perhaps there should be some test like:
if (localPortIndex != -1) {
...
}
I will create a patch if desired. Just LMK.