JiBX
  1. JiBX
  2. JIBX-32

Provide more info when nulls are passed to marshalling context

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0-beta3c
    • Fix Version/s: 1.0-RC0
    • Component/s: core
    • Labels:
      None
    • Number of attachments :
      1

      Description

      From the JiBX FAQ:

      Q. Why do I get a java.lang.NullPointerException when I try to
      marshal a document?
      A. The most likely cause is that you've got a null value for an
      object that's not marked as optional in the binding definition.
      ... snip ...
      add a pre-get method to that class for debugging purposes
      ... snip ...

      It occurs to me that it's relatively simple to change that NPE to a jibx exception that identifies that "name" value that was passed into MarshallingContext.element with a null value so that the user doesn't have to modify his bindings file just to figure out which item was null (which isn't always possible, especially when it happens in production).

      I've already applied this patch to beta3c (which we're using here); I'll attach the same patch to this issue.

        Activity

        Hide
        Joshua Davies added a comment -

        The attached file was generated with "diff -u", and has been tested with the command:

        patch -p0 < MarshallingContext.diff

        relative to the "jibx" directory of a freshly unzipped version of jibx-beta3c.zip.

        Show
        Joshua Davies added a comment - The attached file was generated with "diff -u", and has been tested with the command: patch -p0 < MarshallingContext.diff relative to the "jibx" directory of a freshly unzipped version of jibx-beta3c.zip.
        Hide
        Dennis Sosnoski added a comment -

        Used a different approach, actually catching exceptions and rethrowing, but same effect. Thanks for the suggestion!

        Show
        Dennis Sosnoski added a comment - Used a different approach, actually catching exceptions and rethrowing, but same effect. Thanks for the suggestion!

          People

          • Assignee:
            Dennis Sosnoski
            Reporter:
            Joshua Davies
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: