[jdom-interest] Null Pointer Exception

Joanna Chen joanna.chen at towers.com
Wed Nov 6 11:28:55 PST 2002


Hi JDOM,
    I am facing a strange problem and need your help.
    I developed the following codes in January using JDOM 1.0 Beta 7.  They
have been run in test without  any NULL Pointer Exception.  When the codes
moved to production in the mid of October, I encounter the problem with
Null Pointer Exception;  When we undeploy and deploy the class module under
WebLogic 6.1, it works fine.  Then, the problem happens again.  I have been
testing it for one week to make it fails with variation of data;  However,
I can not make it happens.

I run out of idea how to fix the problem and I need your help!  Do you
think it has anything to do with classpath?

Here are the codes:

public void loadResourceFile(String xmlFile)
    throws Exception
    {
        if (traceFlag)
            traceService.logTrace("EnrollExtractProcess.loadResourceFile",
                                  "Start");

        try
        {
            InputStream inStream = this.getClass().getClassLoader
().getResourceAsStream(xmlFile);

            if (inStream != null)
            {
                //request document building without validation
                SAXBuilder builder = new SAXBuilder(false);
                //Document doc = builder.build(new File(xmlFile));
                Document doc = builder.build(inStream);

                //Get the root element
                root = doc.getRootElement();
            }
         }
         catch (Exception e)
         {
            //write to error object but the program should not end
            throw new DataAccessException
("EnrollExtractProcess.loadResourceFile " + e.toString());
         }

        if (traceFlag)
            traceService.logTrace("EnrollExtractProcess.loadResourceFile",
                                  "End");

      }

    -- end of loadResource File.

   I got NULL pointer exception on the following code.  But I don't know at
what line it causes NULL pointer exception.  The only reason I can think of
is the root is NULL or becomes NULL.  Would you please take a quick
look and let me know your thoughts are.

    private boolean getMappingFields(String table, String field)
    throws Exception
    {
        if (traceFlag)
            traceService.logTrace("EnrollExtractProcess.getMappingFields",
                                  "Start");

        try
        {

            List children = root.getChildren(table);

            if (children.size() == 0)
                return false;

            for (Iterator it = children.iterator(); it.hasNext(); )
            {
                org.jdom.Element currentElement = (org.jdom.Element)it.next
();

                className = currentElement.getAttributeValue("name");
                classPath = currentElement.getAttributeValue("classpath");
                classId = currentElement.getAttributeValue("id");

                List fields = currentElement.getChildren(field);

                Iterator i = fields.iterator();
                while(i.hasNext())
                {
                    org.jdom.Element e = (org.jdom.Element) i.next();

                    fieldName = e.getAttributeValue("name");
                    fieldType = e.getAttributeValue("type");
                }
                if (fields.size() == 0)
                    return false;
            }
        }

            catch (Exception e)
          {
            throw new DataAccessException("getMappingFields " + e.toString
());
            }

        if (traceFlag)
            traceService.logTrace("EnrollExtractProcess.getMappingFields",
                                  "End");

        return true;
    }

    The method loadResourceFile will only call once and getMappingFields
will call for every field found in the database.

    Will the root ever become NULL when calling the getRootElement?

   Thanks in advance for your help,
    Joanna

 Here is the portion of the xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<layout>
    <BENELIG name="FSAData" id="1" classpath="com.towers.bas.hw.data">
        <BE_DC_FSA_DED name="conAmt" type="double"/>
        <BE_HC_FSA_DED name="conAmt" type="double"/>
    </BENELIG>
    <BENSELECT name="BenefitData" id="2" classpath
="com.towers.bas.hw.data">
        <BS_BEN_ID name="benId" type="DecodeField"/>
    </BENSELECT>
    <EMPLOYEE name="EmployeeIndData" id="6" classpath
="com.towers.bas.hw.data">
          <E_DT_BORN name="birthDt" type="FormatField"/>
          <E_DT_EMP_STATUS name="empStatDt" type="FormatField"/>
          <E_DT_HIRE name="hireDt" type="FormatField"/>
          <E_ORG_ID1 name="org1" type="DecodeField"/>
          <E_ORG_ID2 name="org2" type="DecodeField"/>
          <E_ORG_ID3 name="org3" type="DecodeField"/>
          <E_OTH_ORG_ID1 name="othOrg1" type="DecodeField"/>
          <E_OTH_ORG_ID2 name="othOrg2" type="DecodeField"/>
          <E_OTH_ORG_ID3 name="othOrg3" type="DecodeField"/>
    </EMPLOYEE>
</layout>

Thanks,
Joanna





More information about the jdom-interest mailing list