castor
  1. castor
  2. CASTOR-2311

NullPointerException while adding a .class to a MappingTool object

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.2
    • Fix Version/s: 1.3 rc1
    • Component/s: XML tools
    • Labels:
      None
    • Environment:
      Java SDK 1.5
    • Number of attachments :
      0

      Description

      Hello,

      I am using Version 1.2 and I am always getting a NullPointerException while trying to add a new .class to a MappingTool object. Here is my code:

      MappingTool mapTool = new MappingTool();
      mapTool.addClass(BudgetCode.class);

      After a lot of time trying to understand why it was failing, i decided to check the source code of Castor and I have found that the exception arises exactly at this point: MappingTool.java:259

      if (_mappings.get(cls) != null)

      { return; }

      Basically the error is that _mappings field is not initialized (it is null), so any time it is used, it generates a NullPointerException.

      I hope this information will be useful for you to solve it.

      Thanks,

      Carlos

        Activity

        Hide
        Werner Guttmann added a comment -

        Carlos, as part of Castor 1.2, we have introduced quite a few major changes (hence the major version number increase). As a result, your code needs to be changed to

        MappingTool mapTool = new MappingTool();
        mapToolsetInternalContext(new org.castor.xml.BackwardCompatibilityContext());
        mapTool.addClass(BudgetCode.class);
        

        I hope this makes any sense.

        I do acknowledge that there's a lack of information about the MappingTool on the web site. Would you be willing to help us with getting this changed ?

        Show
        Werner Guttmann added a comment - Carlos, as part of Castor 1.2, we have introduced quite a few major changes (hence the major version number increase). As a result, your code needs to be changed to MappingTool mapTool = new MappingTool(); mapToolsetInternalContext(new org.castor.xml.BackwardCompatibilityContext()); mapTool.addClass(BudgetCode.class); I hope this makes any sense. I do acknowledge that there's a lack of information about the MappingTool on the web site. Would you be willing to help us with getting this changed ?
        Hide
        Carlos Garcia Rodriguez added a comment -

        Ok, thanks a lot. I am just going to try what you suggest. I agree with you that there is not much information about the MappingTool, that i think it is very useful for non-very specialized users.

        Thanks again,

        Carlos

        Show
        Carlos Garcia Rodriguez added a comment - Ok, thanks a lot. I am just going to try what you suggest. I agree with you that there is not much information about the MappingTool, that i think it is very useful for non-very specialized users. Thanks again, Carlos
        Hide
        Werner Guttmann added a comment -

        I agree with you that there is not much information about the MappingTool, that i think it is very useful for non-very specialized users.

        So why don't you come up with an initial draft for a web page that documents the usage of the MappingTool, and I'll refine it and integrate it into the existing web page ?

        Show
        Werner Guttmann added a comment - I agree with you that there is not much information about the MappingTool, that i think it is very useful for non-very specialized users. So why don't you come up with an initial draft for a web page that documents the usage of the MappingTool, and I'll refine it and integrate it into the existing web page ?
        Hide
        Lou Parisi added a comment -

        Did you ever get an example for this issue to add to the web page? I will create one if you still need it. I had same problem and took me a little while to find this resolution. I have a working example I could make into a how-to

        Show
        Lou Parisi added a comment - Did you ever get an example for this issue to add to the web page? I will create one if you still need it. I had same problem and took me a little while to find this resolution. I have a working example I could make into a how-to
        Hide
        Werner Guttmann added a comment -

        No, I guess I didn't. How about identifying the relevant HTML page(s) where this should b added/changed, and I'll think about the rest ? And if you volunteer to write a HOW-TO, that would be appreciated.

        Show
        Werner Guttmann added a comment - No, I guess I didn't. How about identifying the relevant HTML page(s) where this should b added/changed, and I'll think about the rest ? And if you volunteer to write a HOW-TO, that would be appreciated.
        Hide
        anand added a comment -

        I think the details are still not present. I suggest the sample presented bt Werner should be added to the java documentation page for org.exolab.castor.tools.MappingTool itself.

        Show
        anand added a comment - I think the details are still not present. I suggest the sample presented bt Werner should be added to the java documentation page for org.exolab.castor.tools.MappingTool itself.
        Hide
        Werner Guttmann added a comment -

        Sure, why not. Feel free to attach a patch .... though above suggestions still make sense.

        Show
        Werner Guttmann added a comment - Sure, why not. Feel free to attach a patch .... though above suggestions still make sense.

          People

          • Assignee:
            Werner Guttmann
            Reporter:
            Carlos Garcia Rodriguez
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: