Qpid
  1. Qpid
  2. QPID-3760

Unable to use address strings with java client due to NPE

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 0.10
    • Fix Version/s: None
    • Component/s: Java Client
    • Labels:

      Description

      Stacktrace:

      Exception in thread "Thread-5" java.lang.NullPointerException
      	at org.apache.qpid.client.AMQDestination.equals(AMQDestination.java:577)
      	at org.springframework.jms.connection.CachingConnectionFactory$DestinationCacheKey.destinationEquals(CachingConnectionFactory.java:467)
      	at org.springframework.jms.connection.CachingConnectionFactory$DestinationCacheKey.equals(CachingConnectionFactory.java:474)
      	at java.util.HashMap.get(HashMap.java:385)
      	at org.springframework.jms.connection.CachingConnectionFactory$CachedSessionInvocationHandler.getCachedProducer(CachingConnectionFactory.java:353)
      	at org.springframework.jms.connection.CachingConnectionFactory$CachedSessionInvocationHandler.invoke(CachingConnectionFactory.java:320)
      	at $Proxy1.createProducer(Unknown Source)
      

      Exception happens for the following address:

      JbenchQueue;{create: always, node: {type:queue}}
      

      It seems the qpid java client tries to obtain exchangeClass property in AMQDestination.equals method, but this property is not set when using address strings.

        Activity

        Sergey Zhemzhitsky created issue -
        Hide
        Weston M. Price added a comment -

        Looks like this entire method could use a good review and a patch.

        Show
        Weston M. Price added a comment - Looks like this entire method could use a good review and a patch.
        Rob Godfrey made changes -
        Field Original Value New Value
        Labels addressing
        Hide
        Lars-Erik Helander added a comment -

        Since I experienced the same problem, I tried the following "fix" (only check equality if non-null values):

        if (_exchangeClass != null && that._exchangeClass != null) {
        if (!_exchangeClass.equals(that._exchangeClass))

        { return false; }
        }


        if (_exchangeName != null && that._exchangeName != null) {
        if (!_exchangeName.equals(that._exchangeName))
        { return false; }

        }

        and that solved my problem.

        Show
        Lars-Erik Helander added a comment - Since I experienced the same problem, I tried the following "fix" (only check equality if non-null values): if (_exchangeClass != null && that._exchangeClass != null) { if (!_exchangeClass.equals(that._exchangeClass)) { return false; } } if (_exchangeName != null && that._exchangeName != null) { if (!_exchangeName.equals(that._exchangeName)) { return false; } } and that solved my problem.
        Hide
        Michał Warecki added a comment -

        I think this doesn't resolve problem when _exchangeClass or _exchangeName in one class is null and in other is not. There is a need to check this before above comparision.

        Something like this:

        if(_exchangeClass == null && that._exchangeClass != null)

        { return false; }

        if(_exchangeClass != null && that._exchangeClass == null){ return false; }

        if(_exchangeClass != null && that._exchangeClass != null) {
        if (!_exchangeClass.equals(that._exchangeClass))

        { return false; }

        }

        if(_exchangeName == null && that._exchangeName != null)

        { return false; }

        if(_exchangeName != null && that._exchangeName == null){ return false; }

        if(_exchangeName != null && that._exchangeName != null) {
        if (!_exchangeName.equals(that._exchangeName))

        { return false; }

        }

        Show
        Michał Warecki added a comment - I think this doesn't resolve problem when _exchangeClass or _exchangeName in one class is null and in other is not. There is a need to check this before above comparision. Something like this: if(_exchangeClass == null && that._exchangeClass != null) { return false; } if(_exchangeClass != null && that._exchangeClass == null){ return false; } if(_exchangeClass != null && that._exchangeClass != null) { if (!_exchangeClass.equals(that._exchangeClass)) { return false; } } if(_exchangeName == null && that._exchangeName != null) { return false; } if(_exchangeName != null && that._exchangeName == null){ return false; } if(_exchangeName != null && that._exchangeName != null) { if (!_exchangeName.equals(that._exchangeName)) { return false; } }
        Hide
        Lars-Erik Helander added a comment -

        I have seen cases where one is null and the other is a zero-sized string. I am not sure if they should be regarded as equal or not (I do not know enough about qpid internals in order know the proper semantics of the equals() function).

        Show
        Lars-Erik Helander added a comment - I have seen cases where one is null and the other is a zero-sized string. I am not sure if they should be regarded as equal or not (I do not know enough about qpid internals in order know the proper semantics of the equals() function).
        Hide
        Azim Fatehi added a comment - - edited

        This bug renders it very difficult to use Apache Camel, as address strings and the spring CachingConnectionFactory are a must. Following the style of the existing _queueName check, I tried the patch which I've pasted below. I don't have any answer to Lars-Erik's comment about null versus "" strings, but this patch seems to work for me.

        --- /original/qpid-0.16/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java	2012-01-29 10:38:29.000000000 -0600
        +++ /modified/qpid-0.16/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java	2012-08-16 15:29:27.329126287 -0500
        @@ -600,11 +600,13 @@
         
                 final AMQDestination that = (AMQDestination) o;
         
        -        if (!_exchangeClass.equals(that._exchangeClass))
        +        if ((_exchangeClass == null && that._exchangeClass != null) ||
        +            (_exchangeClass != null && !_exchangeClass.equals(that._exchangeClass)))
                 {
                     return false;
                 }
        -        if (!_exchangeName.equals(that._exchangeName))
        +        if ((_exchangeName == null && that._exchangeName != null) ||
        +            (_exchangeName != null && !_exchangeName.equals(that._exchangeName)))
                 {
                     return false;
                 }
        
        Show
        Azim Fatehi added a comment - - edited This bug renders it very difficult to use Apache Camel, as address strings and the spring CachingConnectionFactory are a must. Following the style of the existing _queueName check, I tried the patch which I've pasted below. I don't have any answer to Lars-Erik's comment about null versus "" strings, but this patch seems to work for me. --- /original/qpid-0.16/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java 2012-01-29 10:38:29.000000000 -0600 +++ /modified/qpid-0.16/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java 2012-08-16 15:29:27.329126287 -0500 @@ -600,11 +600,13 @@ final AMQDestination that = (AMQDestination) o; - if (!_exchangeClass.equals(that._exchangeClass)) + if ((_exchangeClass == null && that._exchangeClass != null ) || + (_exchangeClass != null && !_exchangeClass.equals(that._exchangeClass))) { return false ; } - if (!_exchangeName.equals(that._exchangeName)) + if ((_exchangeName == null && that._exchangeName != null ) || + (_exchangeName != null && !_exchangeName.equals(that._exchangeName))) { return false ; }
        Hide
        Pavel Moravec added a comment -

        This is a duplicate of https://issues.apache.org/jira/browse/QPID-3769, fixed in 0.22.

        Show
        Pavel Moravec added a comment - This is a duplicate of https://issues.apache.org/jira/browse/QPID-3769 , fixed in 0.22.

          People

          • Assignee:
            Unassigned
            Reporter:
            Sergey Zhemzhitsky
          • Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:

              Development