Project

Profile

Help

Bug #3111

closed

NPE in ContentValidator.makeValidatorForType(ContentValidator.java:496), abstract type

Added by Petr K almost 8 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Internals
Sprint/Milestone:
-
Start date:
2017-01-19
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.7
Fix Committed on Branch:
9.7, trunk
Fixed in Maintenance Release:
Platforms:

Description

could be different view of #3062

please check


Files

ValidationNPE.zip (2.12 KB) ValidationNPE.zip Petr K, 2017-01-19 12:16
Actions #1

Updated by O'Neil Delpratt almost 8 years ago

  • Category set to Internals
  • Assignee set to O'Neil Delpratt

Thanks for your bug report and repo. I confirm this is a bug.

Full error:

alidation error 
  XQDY0027: In content of element <myns:doc>: The content model does not allow element
  <Q{.../myns}object> to appear immediately after element <Q{.../myns}object>. No further
  elements are allowed at this point. 
  See http://www.w3.org/TR/xmlschema11-1/#cvc-complex-type clause 2.4

java.lang.NullPointerException
	at com.saxonica.ee.validate.ContentValidator.makeValidatorForType(ContentValidator.java:496)
	at com.saxonica.ee.validate.ContentValidator.makeValidator(ContentValidator.java:265)
	at com.saxonica.ee.validate.ComplexContentValidator.recover(ComplexContentValidator.java:439)
	at com.saxonica.ee.validate.ComplexContentValidator.startElement(ComplexContentValidator.java:166)
	at com.saxonica.ee.validate.ValidationStack.startElement(ValidationStack.java:280)
	at com.saxonica.ee.validate.XSIAttributeHandler.startElement(XSIAttributeHandler.java:123)
	at net.sf.saxon.event.StartTagBuffer.startContent(StartTagBuffer.java:236)
	at net.sf.saxon.event.ProxyReceiver.startContent(ProxyReceiver.java:177)
	at net.sf.saxon.event.ProxyReceiver.startContent(ProxyReceiver.java:177)
	at net.sf.saxon.tree.tiny.TinyElementImpl.copy(TinyElementImpl.java:357)
	at net.sf.saxon.tree.tiny.TinyDocumentImpl.copy(TinyDocumentImpl.java:289)
	at net.sf.saxon.expr.instruct.CopyOf.processLeavingTail(CopyOf.java:698)
	at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:149)
	at net.sf.saxon.expr.instruct.CopyOf.iterate(CopyOf.java:885)
	at EE_main_21491218219.iterate()
	at com.saxonica.ee.bytecode.CompiledExpression.iterate(CompiledExpression.java:200)
	at net.sf.saxon.query.XQueryExpression.iterator(XQueryExpression.java:323)
	at com.saxonica.xqj.SaxonXQPreparedExpression.executeQuery(SaxonXQPreparedExpression.java:93)
	at com.saxonica.xqj.SaxonXQExpression.executeQuery(SaxonXQExpression.java:96)
	at s9apitest.TestXQueryCompiler.testValidationNPE(TestXQueryCompiler.java:120)
	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 junit.framework.TestCase.runTest(TestCase.java:168)
	at junit.framework.TestCase.runBare(TestCase.java:134)
	at junit.framework.TestResult$1.protect(TestResult.java:110)
	at junit.framework.TestResult.runProtected(TestResult.java:128)
	at junit.framework.TestResult.run(TestResult.java:113)
	at junit.framework.TestCase.run(TestCase.java:124)
	at junit.framework.TestSuite.runTest(TestSuite.java:243)
	at junit.framework.TestSuite.run(TestSuite.java:238)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
	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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Currently investigating.

Actions #2

Updated by O'Neil Delpratt almost 8 years ago

  • Assignee changed from O'Neil Delpratt to Michael Kay
Actions #3

Updated by Michael Kay almost 8 years ago

The code at line 462 does "throw null" when it should clearly do "return null". Not sure when this (crass) error was introduced.

Actions #4

Updated by O'Neil Delpratt almost 8 years ago

I did try making that change, but hit upon another NPE:

java.lang.NullPointerException
	at com.saxonica.ee.validate.ValidationStack.startElement(ValidationStack.java:284)
	at com.saxonica.ee.validate.XSIAttributeHandler.startElement(XSIAttributeHandler.java:123)
	at net.sf.saxon.event.StartTagBuffer.startContent(StartTagBuffer.java:236)
	at net.sf.saxon.event.ProxyReceiver.startContent(ProxyReceiver.java:177)

With the change return null in the class ContentValidator we now get the NPE in the ValidationStack class for the ContentValidator variable v1. Investigating further the correct action to take here.

Actions #5

Updated by Michael Kay almost 8 years ago

After the first validation error (the second "object" element, which shouldn't be there) the code goes into a recovery routine. This code attempts to validate an element even if the element itself is mispositioned. We found several things wrong with the recovery routine:

  1. it's trying to validate the "object" element against the declared type for "object" (ignoring any xsi:type), which produces the error that you can't validate against an abstract type. I don't think it would be appropriate to use the xsi:type here (we might be in recovery because the xsi:type was invalid), so instead I think we should do "anyType" validation for the content of the second "object" element, just as we would if we couldn't find a declared type for it.

  2. we found that the recovery routine was first leaving the childValidator null (which caused an NPE) and was then leaving it unchanged (reusing the validator for the previous "object" element, which was already in its final state, causing a spurious second validation error for the field element. Fixed this to ensure that the childValidator is an AnyTypeValidator.

We also investigated why the validation errors include no location information. This can be fixed in the calling application code by (a) supplying a base URI instead of "null" when creating the document node, and (b) calling setProperty(FeatureKeys.LINE_NUMBERING, "true") on the XQDataSource object.

Actions #6

Updated by O'Neil Delpratt almost 8 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100
  • Applies to branch 9.8 added
  • Fix Committed on Branch 9.7, 9.8 added

Changes made in the classes ContentValidator and ComplexContentValidator. Bug fix committed to subversion.

Actions #7

Updated by O'Neil Delpratt almost 8 years ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release 9.7.0.15 added

Bug fix applied to the Saxon 9.7.0.15 maintenance release

Actions #8

Updated by O'Neil Delpratt over 7 years ago

  • Fix Committed on Branch trunk added
  • Fix Committed on Branch deleted (9.8)
Actions #9

Updated by O'Neil Delpratt over 7 years ago

  • Applies to branch deleted (9.8)

Please register to edit this issue

Also available in: Atom PDF