Java Mailing List Archive

http://www.junlu.com/

Home » user.castor »

[castor-user] NullPointer using XMLInstance2Schema

Alejandro Salas

2012-09-11

Replies: Find Java Web Hosting

Author LoginPost Reply
Hello everyone,

I'm trying to use XMLInstance2Schema. I followed the code sample from the javadoc but I'm getting a NullPointerException in XMLInstance2SchemaHandler, line 520.
I don't know if this is the correct behavior or if this is a bug. Somewhere during the parsing of my xml e1.getType() in line 487 returns null, next there are a couple of ifs, in my case the execution goes to line 493 and 494. The problem is that e1Type is never set to e2Type so it's still null when it arrives at 520. The same thing happens in the if from 507, e2Type is not being set. On both of the else clause (line 496 and 409) the variables are being set.

Is this a bug? Should I report it?
I attached the xml I'm using.

Here's part of the method from XMLInstance2SchemaHandler.


487 XMLType e1Type = e1.getType();
488        XMLType e2Type = e2.getType();
489         
490        //-- Make sure types are not null and if so create them
491        if (e1Type == null) {
492            if (e2Type == null) return; //-- nothing to merge
493 if (e2Type.isSimpleType()) {
494    e1.setType(e2Type);
495 }
496 else {
497    ComplexType cType = new ComplexType(_schema);
498    Group group = new Group();
499    group.setOrder(_defaultGroupOrder);
500    cType.addGroup(group);
501    e1.setType(cType);
502    e1Type = cType;
503 }
504        }
505        else if (e2Type == null) {
506            if (e1Type.isSimpleType()) {
507                e2.setType(e1Type);
508            }
509            else {
510                ComplexType cType = new ComplexType(_schema);
511                Group group = new Group();
512                group.setOrder(_defaultGroupOrder);
513                cType.addGroup(group);
514                e2.setType(cType);
515                e2Type = cType;
516            }
517        }
518        
519        //-- both simple types
520        if (e1Type.isSimpleType() && e2Type.isSimpleType()) {

Thanks in advance!
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:xmlDummyControl xmlns:ns2="myControl">
 <name>dummyControl</name>
 <className>DummyDevice</className>
  <measureValueObject>
    <accessMode>READ</accessMode>
    <comment>comment</comment>
    <itemName>00B2</itemName>
    <groupName>Group</groupName>
    <plcVarName>varName</plcVarName>
    <persist>true</persist>
    <varName>Xi</varName>
    <gain>1.0</gain>
    <offset>0.0</offset>
    <unit>°C</unit>
  </measureValueObject>
  <measureValueObject>
    <accessMode>READ</accessMode>
    <comment>other comment</comment>
    <itemName>00B1</itemName>
    <plcVarName>otherplcVarName</plcVarName>
    <persist>true</persist>
    <varName>varName</varName>
    <gain>1.0</gain>
    <offset>0.0</offset>
    <unit>°C</unit>
  </measureValueObject>
  <measureValueObject>
    <accessMode>WRITE</accessMode>
    <comment>com</comment>
    <itemName>00B3</itemName>
    <persist>true</persist>
    <plcVarName>plc3</plcVarName>
    <varName>var</varName>
    <gain>1.0</gain>
    <offset>0.0</offset>
    <unit>bit</unit>
  </measureValueObject>
   <statusValueObject>
   <accessMode>READ</accessMode>
   <comment>Digital 1</comment>
   <itemName>22B1</itemName>
   <plcVarName>digit</plcVarName>
   <varName>On/off</varName>
 </statusValueObject>
   <statusValueObject>
   <accessMode>WRITE</accessMode>
   <comment>Digital 2</comment>
   <itemName>22B2</itemName>
    <groupName>group</groupName>
   <plcVarName>digit2</plcVarName>
   <varName>On/off 2</varName>
 </statusValueObject>
   <statusValueObject>
   <accessMode>WRITE</accessMode>
   <comment>com</comment>
   <itemName>44B3</itemName>
    <groupName>group32</groupName>
   <plcVarName>digit3</plcVarName>
   <varName>On/off 3</varName>
 </statusValueObject>
   <statusValueObject>
   <accessMode>WRITE</accessMode>
   <comment>Digital </comment>
   <itemName>55B3</itemName>
   <plcVarName>digit4</plcVarName>
   <varName>On/off 4</varName>
 </statusValueObject>
 <clocks>
   <clock>
     <name></name>
     <index>0</index>
   </clock>
   <clock>
     <name>Zone OG</name>
     <index>1</index>
   </clock>
   <clock>
     <name>Zone OG</name>
     <index>2</index>
   </clock>
   <clock>
     <name>Zone EG</name>
     <index>3</index>
   </clock>
   <clock>
     <name>Zone EG</name>
     <index>4</index>
   </clock>
 </clocks>
</ns2:xmlDummyControl>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email
©2008 junlu.com - Jax Systems, LLC, U.S.A.