jersey
  1. jersey
  2. JERSEY-728

Multipart unmarshalling should throw exceptions instead of returning null when it fails

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0, 1.0.1, 1.0.2, 1.0.3, 1.1.0-ea, 1.1.1-ea, 1.1.2-ea, 1.1.3-ea, 1.1.4, 1.1.5, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8
    • Fix Version/s: 2.5
    • Component/s: tools
    • Labels:
      None

      Description

      When unmarshalling a mutlipart BodyPart using getEntityAs(<type>), all IOExceptions originating from the reader are swallowed and null is returned instead.
      This makes error handling different from the way it works for unmarshalling in regular requests and makes it impossible to differiantiate between different reasons for failing.

      For example the Jackson POJO mapping allows to differiantiate between a JsonParseException which one should map to a 400 Bad Request status and a UnrecognizedPropertyException or JsonMappingException which one should map to a 422 Unprocessable Entity status.

      The attached patch solves this, but also changes the mehtod signatures of course.

        Activity

        Hide
        Marek Potociar added a comment -

        Check if applicable for Jersey 2.x. If yes, we need to fix, if not (only applicable to Jersey 1.x), let's close as won't fix.

        Show
        Marek Potociar added a comment - Check if applicable for Jersey 2.x. If yes, we need to fix, if not (only applicable to Jersey 1.x), let's close as won't fix.
        Hide
        Juraj Misur added a comment - - edited

        Hi guys, this bug gave us a hard laugh when my debugger stopped in the exception handling block of this short source:

        try {
            return reader.readFrom(clazz, clazz, annotations, mediaType, headers, ((BodyPartEntity) entity).getInputStream());
        } catch (IOException e) {
            return null; // Can not happen.
        }
        

        The code snippet is from jersey master branch at github
        https://github.com/jersey/jersey/blob/master/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/BodyPart.java
        so it affects versions 1.0 - 2.x. I bet people take it already as a feature and do workarounds.
        Workaround for jackson: use @JsonIgnoreProperties(ignoreUnknown = true) on target pojo if you have, for example, UnrecognizedPropertyException.

        Thanks for entertaining us, now let's fix it!!!

        Show
        Juraj Misur added a comment - - edited Hi guys, this bug gave us a hard laugh when my debugger stopped in the exception handling block of this short source: try { return reader.readFrom(clazz, clazz, annotations, mediaType, headers, ((BodyPartEntity) entity).getInputStream()); } catch (IOException e) { return null ; // Can not happen. } The code snippet is from jersey master branch at github https://github.com/jersey/jersey/blob/master/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/BodyPart.java so it affects versions 1.0 - 2.x. I bet people take it already as a feature and do workarounds. Workaround for jackson: use @JsonIgnoreProperties(ignoreUnknown = true) on target pojo if you have, for example, UnrecognizedPropertyException. Thanks for entertaining us, now let's fix it!!!

          People

          • Assignee:
            Michal Gajdos
            Reporter:
            samuelvogel
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 30 minutes Original Estimate - 30 minutes
              30m
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 2 hours
              2h