ActiveMQ
  1. ActiveMQ
  2. AMQ-2256

Unnecessary TcpTransportFactory NumberFormatException and warning

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 5.2.0
    • Fix Version/s: 5.5.0
    • Component/s: Transport
    • Labels:
      None
    • Environment:

      Windows XP

      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

      { Integer.parseInt(path.substring(localPortIndex + 1, path.length())); String localString = location.getScheme() + ":/" + path; localLocation = new URI(localString); }

      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.

        Activity

        Hide
        Scott Lewis added a comment -

        Is there any way to shut off the presentation of this NumberFormatException in 5.2.0. Short of having it fixed, it would be very nice to at least prevent the spurious NumberFormatException and stack trace from appearing when using the tcp protocol in this manner

        Show
        Scott Lewis added a comment - Is there any way to shut off the presentation of this NumberFormatException in 5.2.0. Short of having it fixed, it would be very nice to at least prevent the spurious NumberFormatException and stack trace from appearing when using the tcp protocol in this manner
        Hide
        Gary Tully added a comment -

        could you attach a test case for this issue? Exactly what parameters are passed to the API?

        Show
        Gary Tully added a comment - could you attach a test case for this issue? Exactly what parameters are passed to the API?
        Hide
        Scott Lewis added a comment -

        The String path passed to the API at org.apache.activemq.transport.tcp.TcpTransportFactory.createTransport(TcpTransportFactory.java:125)

        is "/exampleTopic". The exact contents of the string doesn't matter.

        Show
        Scott Lewis added a comment - The String path passed to the API at org.apache.activemq.transport.tcp.TcpTransportFactory.createTransport(TcpTransportFactory.java:125) is "/exampleTopic". The exact contents of the string doesn't matter.
        Hide
        Timothy Bish added a comment -

        Not enough information provided to construct a test case. Can be reopened if a test case is provided so this can be validated.

        Show
        Timothy Bish added a comment - Not enough information provided to construct a test case. Can be reopened if a test case is provided so this can be validated.
        Hide
        Scott Lewis added a comment -

        The test case is simply:

        new ActiveMQConnectionFactory("tcp://localhost:61616/exampleTopic").createConnection();

        The connection is created successfully, bu the NumberFormatException is still being produced to standard error.

        Although originally reported on 5.2.0, the same problem exists on 5.3.2 as well (what I happen to be using now).

        As stated in the bug, the problem is in TcpTransportFactory.createTransport. Here is an annotated code fragment that shows the problem (modified slightly from TcpTransportFactory.createTransport)

        URI location = new URI("tcp://localhost:61616/exampleTopic");
        String path = location.getPath();
        // path is "/exampleTopic"
        if (path != null && path.length() > 0) {
        int localPortIndex = path.indexOf(':');
        // localPortIndex == -1 ...this is wrong, since //exampleTopic has no port in it
        try {
        Integer.parseInt(path.substring(localPortIndex + 1,path.length()));
        // the previous line throws NumberFormatException because path.substring(0.path.length()) does not produce a number, because path is "/exampleTopic"

        Show
        Scott Lewis added a comment - The test case is simply: new ActiveMQConnectionFactory("tcp://localhost:61616/exampleTopic").createConnection(); The connection is created successfully, bu the NumberFormatException is still being produced to standard error. Although originally reported on 5.2.0, the same problem exists on 5.3.2 as well (what I happen to be using now). As stated in the bug, the problem is in TcpTransportFactory.createTransport. Here is an annotated code fragment that shows the problem (modified slightly from TcpTransportFactory.createTransport) URI location = new URI("tcp://localhost:61616/exampleTopic"); String path = location.getPath(); // path is "/exampleTopic" if (path != null && path.length() > 0) { int localPortIndex = path.indexOf(':'); // localPortIndex == -1 ...this is wrong, since //exampleTopic has no port in it try { Integer.parseInt(path.substring(localPortIndex + 1,path.length())); // the previous line throws NumberFormatException because path.substring(0.path.length()) does not produce a number, because path is "/exampleTopic"
        Hide
        Timothy Bish added a comment -

        Thanks, having your full URI made that much easier. The code will suppress the full exception stack and just log a warning now unless debug logging is on.

        Show
        Timothy Bish added a comment - Thanks, having your full URI made that much easier. The code will suppress the full exception stack and just log a warning now unless debug logging is on.
        Hide
        liugang added a comment -

        sorry, But I found we still have some output which looks like:
        [/50/data/fileIn] TcpTransportFactory WARN path isn't a valid local location for TcpTransport to use
        I tested on activemq-5.7.0, it's a problem or not? Thanks.

        Show
        liugang added a comment - sorry, But I found we still have some output which looks like: [/50/data/fileIn] TcpTransportFactory WARN path isn't a valid local location for TcpTransport to use I tested on activemq-5.7.0, it's a problem or not? Thanks.

          People

          • Assignee:
            Timothy Bish
            Reporter:
            Scott Lewis
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development