[ 
https://issues.apache.org/jira/browse/XERCESJ-1488?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12972031#action_12972031
 ] 

Mukul Gandhi commented on XERCESJ-1488:
---------------------------------------

Hi Khaled,
    Here are few examples illustrating why the code-base in question is written 
currently like it is now.

XML Instance document:

<Example attr="2010-08-25" />

XML Schema 1.1 document:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>
   
     <xs:element name="Example">
           <xs:complexType>
                <xs:attribute name="attr">
                     <xs:simpleType>
                          <xs:union memberTypes="xs:int MYDATE" />
                     </xs:simpleType>
                </xs:attribute>
           </xs:complexType>
     </xs:element>
   
     <xs:simpleType name="MYDATE">
           <xs:restriction base="xs:date">
               <xs:assertion test="$value gt xs:date('2010-08-25')" />
           </xs:restriction>
     </xs:simpleType>

</xs:schema>

There are two cases I want to consider for the above example, which probably 
would clarify the doubts in this thread.

Case 1:

The simpleType's union description is following,

<xs:union memberTypes="xs:int MYDATE" />

The call attDV.validate(attrValue, fValidationState, fValidatedInfo) returns 
true.

In this case assertion evaluations from memberTypes of union do not contribute 
to reported validity of the above result. Therefore we must do few extra checks 
after the above call to consider the effect of assertion evaluations on the 
final instance document validity; which is thereafter accomplished by the call 
XSTypeHelper.isAtomicValueValidForAnUnion(..) -- this returns false and 
variable fisAtomicValueValidForSTVarietyUnion remains true, and assertions are 
then evaluated in XMLAssertPsychopathImpl which then cause overall failure of 
the validation episode. 

Case 2:

The simpleType's union description is following (we are adding a member type 
xs:date which would obviously cause the instance validation to pass),

<xs:union memberTypes="xs:int MYDATE xs:date" />

The call attDV.validate(attrValue, fValidationState, fValidatedInfo) returns 
true.

and the call XSTypeHelper.isAtomicValueValidForAnUnion(..) after this returns 
true, and variable fisAtomicValueValidForSTVarietyUnion becomes false and 
assertions are then not evaluated in XMLAssertPsychopathImpl.  

Since the call XSTypeHelper.isAtomicValueValidForAnUnion(..) considers effect 
of assertions, therefore all of above algorithmic steps seems to correctly 
refelect the desired processing needed in these cases.

To summarizing I would say, since the call attDV.validate(attrValue, 
fValidationState, fValidatedInfo) returns true in both of the above cases we 
needed something like XSTypeHelper.isAtomicValueValidForAnUnion(..) after this 
call for simpleType -> union cases.

At the moment I'm seemingly convinced that all of such processing may be 
correct.

I'm also curious to look at the sample test cases which the originator of this 
bug report had tried which has caused the NullPointerException. That would help 
us to debug the cause of NullPointerException better.

I hope this makes the things more clear. Please let me know, if I can answer 
any more questions.

Regards,
Mukul

> NullPointerException caused by XMLSchemaValidator.addDefaultAttributes
> ----------------------------------------------------------------------
>
>                 Key: XERCESJ-1488
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1488
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: XML Schema 1.1 Structures
>    Affects Versions: 2.11.0
>         Environment: Java version: 1.6.0_23
> Java home: C:\Program Files\Java\jdk1.6.0_23\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows vista" version: "6.0" arch: "amd64" Family: "windows"
>            Reporter: Gary Gregory
>            Assignee: Khaled Noaman
>            Priority: Blocker
>         Attachments: XERCESJ-1488_samples.zip
>
>
> The following is a regression from 2.10 because our unit tests run OK with 
> 2.10 and blow up with 2.11.
> NullPointerException caused by XMLSchemaValidator.addDefaultAttributes  
> Note that the second argument is null in the call:
> {noformat}
> if (XSTypeHelper.isAtomicValueValidForAnUnion(attDV.getMemberTypes(), 
>       null, defaultValue)) {
> {noformat}
> at
> XMLSchemaValidator.addDefaultAttributes(QName, XMLAttributes, 
> XSAttributeGroupDecl) line: 3385        
> Which means that at this point in the call chain:
> {noformat}
> Thread [main] (Suspended (breakpoint at line 2255 in XSSimpleTypeDecl))       
>       XSSimpleTypeDecl.normalize(Object, short) line: 2255    
>       XSSimpleTypeDecl.getActualValue(Object, ValidationContext, 
> ValidatedInfo, boolean) line: 2053   
>       XSSimpleTypeDecl.validate(String, ValidationContext, ValidatedInfo) 
> line: 1742  
>       XSTypeHelper.isValueValidForASimpleType(String, XSSimpleType) line: 135 
>       XSTypeHelper.isAtomicValueValidForAnUnion(XSObjectList, String, 
> ValidatedInfo) line: 108        
>       XMLSchemaValidator.addDefaultAttributes(QName, XMLAttributes, 
> XSAttributeGroupDecl) line: 3385  
>       XMLSchemaValidator.handleStartElement(QName, XMLAttributes, 
> Augmentations) line: 2375   
>       XMLSchemaValidator.startElement(QName, XMLAttributes, Augmentations) 
> line: 815  
>       XMLNSDocumentScannerImpl.scanStartElement() line: 283   
>       XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook() 
> line: 733    
>       
> XMLNSDocumentScannerImpl$NSContentDispatcher(XMLDocumentFragmentScannerImpl$FragmentContentDispatcher).dispatch(boolean)
>  line: 1754     
>       
> XMLNSDocumentScannerImpl(XMLDocumentFragmentScannerImpl).scanDocument(boolean)
>  line: 324        
>       IntegratedParserConfiguration(DTDConfiguration).parse(boolean) line: 
> 515        
>       IntegratedParserConfiguration(DTDConfiguration).parse(XMLInputSource) 
> line: 571 
>       DOMParser(XMLParser).parse(XMLInputSource) line: 108    
>       DOMParser.parse(InputSource) line: 230  
>       DocumentBuilderImpl.parse(InputSource) line: 298        
>       XmlValidator.validate(InputSource) line: 279    
>       XmlValidator.validate(URL) line: 317    
>       XmlValidator.validate(String) line: 300 
>       XmlValidatorTestCase.validateXmlSchema1_0_2(String) line: 187   
>       XmlValidatorTestCase.testSimpleXsd_XmlSchema1_0_2() line: 126   
>       NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not 
> available [native method]  
>       NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39      
>       DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25  
>       Method.invoke(Object, Object...) line: 597      
>       FrameworkMethod$1.runReflectiveCall() line: 44  
>       FrameworkMethod$1(ReflectiveCallable).run() line: 15    
>       FrameworkMethod.invokeExplosively(Object, Object...) line: 41   
>       InvokeMethod.evaluate() line: 20        
>       BlockJUnit4ClassRunner.runNotIgnored(FrameworkMethod, EachTestNotifier) 
> line: 79        
>       BlockJUnit4ClassRunner.runChild(FrameworkMethod, RunNotifier) line: 71  
>       BlockJUnit4ClassRunner.runChild(Object, RunNotifier) line: 49   
>       ParentRunner$3.run() line: 193  
>       ParentRunner$1.schedule(Runnable) line: 52      
>       BlockJUnit4ClassRunner(ParentRunner<T>).runChildren(RunNotifier) line: 
> 191      
>       ParentRunner<T>.access$000(ParentRunner, RunNotifier) line: 42  
>       ParentRunner$2.evaluate() line: 184     
>       BlockJUnit4ClassRunner(ParentRunner<T>).run(RunNotifier) line: 236      
>       JUnit4TestMethodReference(JUnit4TestReference).run(TestExecution) line: 
> 49      
>       TestExecution.run(ITestReference[]) line: 38    
>       RemoteTestRunner.runTests(String[], String, TestExecution) line: 467    
>       RemoteTestRunner.runTests(TestExecution) line: 683      
>       RemoteTestRunner.run() line: 390        
>       RemoteTestRunner.main(String[]) line: 197       
> {noformat}
>       
> The "return null;" runs at:
> XSSimpleTypeDecl.normalize(Object, short) line: 2255  
> {noformat}
>         if (content == null)
>             return null;
> {noformat}
>                       
> Which then causes:
> {noformat}
> java.lang.NullPointerException
>       at java.util.StringTokenizer.<init>(StringTokenizer.java:182)
>       at java.util.StringTokenizer.<init>(StringTokenizer.java:204)
>       at 
> org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl.getActualValue(XSSimpleTypeDecl.java:2105)
>       at 
> org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl.validate(XSSimpleTypeDecl.java:1742)
>       at 
> org.apache.xerces.impl.xs.util.XSTypeHelper.isValueValidForASimpleType(XSTypeHelper.java:135)
>       at 
> org.apache.xerces.impl.xs.util.XSTypeHelper.isAtomicValueValidForAnUnion(XSTypeHelper.java:108)
>       at 
> org.apache.xerces.impl.xs.XMLSchemaValidator.addDefaultAttributes(XMLSchemaValidator.java:3385)
>       at 
> org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2375)
>       at 
> org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:815)
>       at 
> org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:283)
>       at 
> org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:733)
>       at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1754)
>       at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:324)
>       at 
> org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:515)
>       at 
> org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:571)
>       at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:108)
>       at org.apache.xerces.parsers.DOMParser.parse(DOMParser.java:230)
>       at 
> org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:298)
>       at 
> com.seagullsw.toolbox.xml.XmlValidator.validate(XmlValidator.java:279)
>       at 
> com.seagullsw.toolbox.xml.XmlValidator.validate(XmlValidator.java:317)
>       at 
> com.seagullsw.toolbox.xml.XmlValidator.validate(XmlValidator.java:300)
>       at 
> com.seagullsw.toolbox.xml.XmlValidatorTestCase.validateXmlSchema1_0_2(XmlValidatorTestCase.java:187)
>       at 
> com.seagullsw.toolbox.xml.XmlValidatorTestCase.testSimpleXsd_XmlSchema1_0_2(XmlValidatorTestCase.java:126)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:597)
>       at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>       at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>       at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>       at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>       at 
> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>       at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>       at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>       at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>       at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>       at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>       at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>       at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>       at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>       at 
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
>       at 
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> {noformat}
> because the null value is passed all the way down the call chain until it 
> causes the implosion.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to