Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation succeeds despite throwing exception #33

Closed
jbrumf opened this issue Jul 1, 2019 · 16 comments · Fixed by #49
Closed

Validation succeeds despite throwing exception #33

jbrumf opened this issue Jul 1, 2019 · 16 comments · Fixed by #49
Assignees
Labels
bug Something isn't working

Comments

@jbrumf
Copy link

jbrumf commented Jul 1, 2019

The validator (1.14.0) sometimes reports no errors even though it has thrown a NullPointerException during the validation process. This leaves me wondering whether there is actually an error in the XML. The exception message doesn't give a line number, so I don't know where in the XML the problem occurs.

Please see the attached output.

ValidationLog.txt

@jordanpadams
Copy link
Member

@jbrumf can you please attach the schema/schematron you are using, the product that is failing validation, and any other additional information that may help us debug?

also, have you tried this again with v1.15.0 of validate? we have several bug fixes in that version that may be able to help you.

https://pds-engineering.jpl.nasa.gov/development/pds4/current/preparation/validate/index.html

@jordanpadams jordanpadams added the bug Something isn't working label Jul 1, 2019
@jordanpadams jordanpadams self-assigned this Jul 1, 2019
@jbrumf
Copy link
Author

jbrumf commented Jul 2, 2019

Many thanks. I will try v1.15.0 first. If that doesn't fix it, I will post the schema and product XML files.

@jbrumf
Copy link
Author

jbrumf commented Jul 3, 2019

We upgraded to validator 1.15.0 and pds4-tools 0.12.0 and now get a slightly different exception.

Caused by: java.lang.NullPointerException at gov.nasa.pds.tools.validate.rule.pds4.ContextProductReferenceValidationRule.checkContextReferences(ContextProductReferenceValidationRule.java:106)

We think the problem is that the method setRegisteredProducts() is only called when the validator is called by command line (using the main[] method). We are creating an instance of ValidateLauncher in Java code but we can't call the setRegisteredProducts method because it is private.

We need to configure the JSON file with the registered products. How should we do this?

@jbrumf
Copy link
Author

jbrumf commented Jul 5, 2019

I have attached a ZIP containing the files which you requested:

Files.zip

@josinde
Copy link

josinde commented Jul 5, 2019

In case it helps this is the stack trace of the exception raised during the validation (using 1.15.0 version):

2019-07-05 15:28:51 ERROR Unexpected exception executing validation rule
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at gov.nasa.pds.tools.validate.rule.AbstractValidationRule.execute(AbstractValidationRule.java:61)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at gov.nasa.pds.tools.validate.task.ValidationTask.execute(ValidationTask.java:129)
at gov.nasa.pds.tools.validate.task.BlockingTaskManager.submit(BlockingTaskManager.java:27)
at gov.nasa.pds.tools.label.LocationValidator.validate(LocationValidator.java:154)
at gov.nasa.pds.validate.ValidateLauncher.doValidation(ValidateLauncher.java:846)
at esa.esac.exm16.pds.validation.PdsProductValidator.validate(PdsProductValidator.java:129)
at esa.esac.exm16.pds.validation.PdsProductValidator.validate(PdsProductValidator.java:83)
at esa.esac.exm16.pds.validation.cli.PdsValidatorTool.process(PdsValidatorTool.java:90)
at esa.esac.exm16.pds.validation.cli.PdsValidatorTool.main(PdsValidatorTool.java:126)
Caused by: java.lang.NullPointerException
at gov.nasa.pds.tools.util.Utility.fixSlashes(Utility.java:242)
at gov.nasa.pds.tools.util.Utility.makeAbsolute(Utility.java:257)
at gov.nasa.pds.tools.label.XMLCatalogResolver.resolveResource(XMLCatalogResolver.java:396)
at gov.nasa.pds.tools.label.XMLCatalogResolver.resolveResource(XMLCatalogResolver.java:353)
at org.apache.xerces.util.DOMEntityResolverWrapper.resolveEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.resolveEntity(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.resolveDocument(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.processAttributes(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at org.apache.xerces.jaxp.validation.ValidatorHandlerImpl.startElement(Unknown Source)
at gov.nasa.pds.tools.label.LabelValidator.walkNode(LabelValidator.java:619)
at gov.nasa.pds.tools.label.LabelValidator.walkChildren(LabelValidator.java:639)
at gov.nasa.pds.tools.label.LabelValidator.walkNode(LabelValidator.java:620)
at gov.nasa.pds.tools.label.LabelValidator.walkChildren(LabelValidator.java:639)
at gov.nasa.pds.tools.label.LabelValidator.walkNode(LabelValidator.java:620)
at gov.nasa.pds.tools.label.LabelValidator.walkChildren(LabelValidator.java:639)
at gov.nasa.pds.tools.label.LabelValidator.walkNode(LabelValidator.java:620)
at gov.nasa.pds.tools.label.LabelValidator.walkChildren(LabelValidator.java:639)
at gov.nasa.pds.tools.label.LabelValidator.walkNode(LabelValidator.java:620)
at gov.nasa.pds.tools.label.LabelValidator.walkChildren(LabelValidator.java:639)
at gov.nasa.pds.tools.label.LabelValidator.walkNode(LabelValidator.java:620)
at gov.nasa.pds.tools.label.LabelValidator.walkChildren(LabelValidator.java:639)
at gov.nasa.pds.tools.label.LabelValidator.walkNode(LabelValidator.java:597)
at gov.nasa.pds.tools.label.LabelValidator.parseAndValidate(LabelValidator.java:380)
at gov.nasa.pds.tools.validate.rule.pds4.LabelValidationRule.validateLabel(LabelValidationRule.java:163)
... 14 more

@josinde
Copy link

josinde commented Jul 5, 2019

More in detail, it seems a null 'sysid' variable in Utility.fixSlashes():
at gov.nasa.pds.tools.util.Utility.fixSlashes(Utility.java:242)
at gov.nasa.pds.tools.util.Utility.makeAbsolute(Utility.java:257)

@josinde
Copy link

josinde commented Jul 5, 2019

(updated)
We found this problem using a catalog or the force flag. It doesn't appear, for instances, if we specify the schemas and schematrons explicity using the S/x flags.

@josinde
Copy link

josinde commented Jul 9, 2019

One more thing, sorry. We tested the validation tool from the command line, using the stand-alone application provided in the package and using two different setups:

  1. Setting the schemas and schematrons explicitly (-S and -x flags)
  2. Using a catalog.

In neither of the two cases the tool raises any exception but the first case reports three problems for our label file while the second execution only reports one problem. My conclusion is that the validation is correctly executed when the schemas and schematrons are provided explicitly (first case) and it gets interrupted in the second case when the same NullPointerException problem is found. Seems that the code handles this exception internally and stops the validation before it is finished without reporting any problem to the stdout, just the validation status up to that moment.

ticket.tar.gz

@jordanpadams
Copy link
Member

@josinde I poked into this, and haven't quite been able to track down the solution, but I was able to easily replicate the problem. it looks like once the label invalidates, for some reason when a catalog file is involved, it just stops validating anything else after that.

that being said, once I fixed the problem in the label, and re-ran validate, it completed all of the validation successfully. so in the meantime, I think the workaround would be to fix the validation errors you are getting in the labels, and then re-run validate to see if any additional errors exist (e.g. context products, context validation, etc.)

@josinde
Copy link

josinde commented Jul 13, 2019

@jordanpadams Thanks for look into this. Being able to reproduce the problem in your side are already a good news. We run the validator integrated in our own software and I need to check that the code reports a label problem even when this exception is raised. If this is the case your proposal could perfectly work for us.

In case it helps to the solution, what I found is that checking the sysid value in the Utility.fixSlashes() method the code returns a full validation report without exceptions as if no catalog were configured. Seems that at one point in the label validation it needs to resolve the schema locations. When a catalog is used, this process triggers the following sequence of invocations: XMLCatalogResolver.resolveResource(..) -> Utility.makeAbsolute() -> Utility.fixSlashes() and this last method raises the NullPointerException when the input argument is null. I don't know why the code ends up resolving a location with null sysid and understand this should be great but at least this can work as a temporal workaround.

jordanpadams added a commit that referenced this issue Jul 13, 2019
…rce,

if systemId is null, we should just return null before trying to resolve it.

Resolves #33
jordanpadams added a commit that referenced this issue Jul 13, 2019
Similar to the functionality in CachedLSResourceResolver.resolveResource,
if systemId is null, we should just return null before trying to resolve it.

Resolves #33
@jordanpadams
Copy link
Member

@josinde I think this is fixed. see #49 . I would like our resident validate expert @mcayanan to scope it for us, but I think this will do the trick.

@josinde
Copy link

josinde commented Jul 15, 2019

@jordanpadams You are right, #49 and this seems to be the same issue. Thanks for spotting this. Looking forward to have the patch finally integrated in the code.

@mcayanan
Copy link
Contributor

@jordanpadams Seems like this patch works. Although, I still can't seem to figure out why systemId is null in this case. SystemId should always be set to the schema or schematron URL and in this instance, it seems to be null because of the following error in the label:

        <fField_Character>
          <name>dose_hour_CD</name>
          <field_number>5</field_number>
          <field_location unit="byte">51</field_location>
          <data_type>ASCII_Real</data_type>
          <field_length unit="byte">9</field_length>
          <unit>microGy/h</unit>
          <description>Dose rate in direction CD</description>
          <Special_Constants>
            <missing_constant>-999.99</missing_constant>
          </Special_Constants>
        </fField_Character>

I'm tempted to recommend that instead of simply returning null, maybe it might be worthwhile to add reporting a warning message so as to not hide any issues that may come about in the future, something like:

        if (getProblemHandler() != null) {
          getProblemHandler().addProblem(
              new ValidationProblem(
                  new ProblemDefinition(
                      ExceptionType.WARNING,
                      ProblemType.CATALOG_UNRESOLVABLE_RESOURCE,
                      "systemid is not set."), 
                  baseUrl));
        }

jordanpadams added a commit that referenced this issue Jul 17, 2019
Issue #33: Ignore resources with null systemId
@jordanpadams
Copy link
Member

@jbrumf @josinde this fix has been merged (along with a couple other). I deployed a SNAPSHOT version if you want to download and try it out:

https://oss.sonatype.org/content/repositories/snapshots/gov/nasa/pds/validate/1.16.0-SNAPSHOT/validate-1.16.0-20190717.175446-5-bin.tar.gz

@josinde
Copy link

josinde commented Jul 18, 2019

@jordanpadams New snapshot tested locally and working as expected, including a new warnign when a null sysId is detected. Many thanks!

Output logs:
test_report.txt

@josinde
Copy link

josinde commented Jul 18, 2019

Same test removing the 'resources' problem:
test_report.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants