ServiceMix
  1. ServiceMix
  2. SM-1186

NormalizedMessageImpl.getAttachment() returns DataHandler when it should return null

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.2.1
    • Fix Version/s: 3.2.2, 3.3
    • Component/s: servicemix-core
    • Labels:
      None
    • Environment:

      any

    • Patch Info:
      Patch Available

      Description

      The current implementation of getAttachment() in NormalizedMessageImpl always returns a DataHandler if the message has any attachments, even if it does not have an attachment with the given ID:

      public DataHandler getAttachment(String id) {
      if (attachments != null)

      { return new DataHandler((DataSource) attachments.get(id)); }

      return null;
      }

      According to the JBI javadocs, getAttachment should return "DataHandler representing attachment content, or null if an attachment with the specified identifier is not found".

      Thus, the implementation should add an additional check

      if(attachments !=null && attachments.get(id) != null){
      return new DataHandler((DataSource) attachments.get(id));
      }

      1. SM1186_patch.txt
        0.6 kB
        Jamie goodyear

        Activity

        Alex Vigdor created issue -
        Guillaume Nodet made changes -
        Field Original Value New Value
        Fix Version/s 3.1.3 [ 11846 ]
        Fix Version/s 3.3 [ 11850 ]
        Fix Version/s 3.2.2 [ 11861 ]
        Hide
        Jamie goodyear added a comment -

        Created patch for the issue described in SM-1186 based upon Alex Vigdor's suggested solution. The relevant JBI spec indicates a null return if attachment with specified identifier is not found [1].

        File Modified:
        /x2/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/NormalizedMessageImpl.java

        Tested on Mac OSX 10.5.2
        Java: 1.5.0_13

        [1] http://java.sun.com/integration/1.0/docs/sdk/api/javax/jbi/messaging/NormalizedMessage.html#getAttachment(java.lang.String)

        Show
        Jamie goodyear added a comment - Created patch for the issue described in SM-1186 based upon Alex Vigdor's suggested solution. The relevant JBI spec indicates a null return if attachment with specified identifier is not found [1] . File Modified: /x2/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/NormalizedMessageImpl.java Tested on Mac OSX 10.5.2 Java: 1.5.0_13 [1] http://java.sun.com/integration/1.0/docs/sdk/api/javax/jbi/messaging/NormalizedMessage.html#getAttachment(java.lang.String )
        Jamie goodyear made changes -
        Attachment SM1186_patch.txt [ 16121 ]
        Guillaume Nodet made changes -
        Patch Info [Patch Available]
        Lars Heinemann made changes -
        Assignee Lars Heinemann [ lhe ]
        Hide
        Lars Heinemann added a comment -

        The API documentation linked in Jamie Goodyear's comment states that in case of a non-existing attachment with the given id the method should return null.

        Show
        Lars Heinemann added a comment - The API documentation linked in Jamie Goodyear's comment states that in case of a non-existing attachment with the given id the method should return null.
        Lars Heinemann made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Lars Heinemann added a comment -
        • changed the getAttachment(String id) method to behave JBI compliant (see SM-1186 by Alex Vidgor)
        • added a testcase for this issue
        Show
        Lars Heinemann added a comment - changed the getAttachment(String id) method to behave JBI compliant (see SM-1186 by Alex Vidgor) added a testcase for this issue
        Lars Heinemann made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Jeff Turner made changes -
        Project Import Sat Nov 27 00:46:19 EST 2010 [ 1290836779991 ]

          People

          • Assignee:
            Lars Heinemann
            Reporter:
            Alex Vigdor
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development