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

validate gives a NullPointerException during validation of a directory containing Table_Character products #335

Closed
msbentley opened this issue May 4, 2021 · 4 comments
Assignees
Labels

Comments

@msbentley
Copy link

msbentley commented May 4, 2021

🐛 Describe the bug

I am getting the following output when trying to validate a directory of products using -t . in a directory containing Table_Character products. This always used to work, but now I get errors like:

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:71)
	at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
	at gov.nasa.pds.tools.validate.rule.pds4.LabelInFolderRule$1.run(LabelInFolderRule.java:154)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.NullPointerException
	at gov.nasa.pds.tools.validate.rule.RuleContext.getCheckInbetweenFields(RuleContext.java:427)
	at gov.nasa.pds.tools.validate.rule.pds4.TableDataContentValidationRule.getCheckInbetweenFields(TableDataContentValidationRule.java:115)
	at gov.nasa.pds.tools.validate.rule.pds4.TableDataContentValidationRule.validateTableDataContents(TableDataContentValidationRule.java:397)
	... 12 more

note that if I explicitly use -t *.xml then it works OK!

The following test product (uploaded also for another ticket) shows the problem:

validate_field_formats.zip

Update: I only seem to get the error when using a catalog file (my default). This seems a tricky one to pin down, so please ping me if you need further details!

📚 Version of Software Used

gov.nasa.pds:validate
Version 2.0.3
Release Date: 2021-05-03 16:04:16

🖥 System Info

  • OS: linux / ubuntu 20.094
  • java: openjdk 11

** 🦄 Applicable requirements**

@msbentley msbentley added bug Something isn't working needs:triage labels May 4, 2021
@msbentley msbentley changed the title validate gives a NullPointerException during validation validate gives a NullPointerException during validation of a directory containing Table_Character May 4, 2021
@msbentley msbentley changed the title validate gives a NullPointerException during validation of a directory containing Table_Character validate gives a NullPointerException during validation of a directory containing Table_Character products May 4, 2021
@jordanpadams jordanpadams added this to the 07.Evelyn.Ashford milestone May 4, 2021
@jordanpadams jordanpadams assigned qchaupds and unassigned jordanpadams May 4, 2021
@qchaupds
Copy link
Contributor

qchaupds commented May 4, 2021

@msbentley Hi Mark. I can confirm your finding when running with the -t parameter pointing to a directory.

The code in question is at line 427 for RuleContext:

423 }
424
425 public boolean getCheckInbetweenFields() {
426 LOG.debug("getCheckInbetweenFields {}",getContextValue(CHECK_INBETWEEN_FIELDS, Boolean.class));
427 return getContextValue(CHECK_INBETWEEN_FIELDS, Boolean.class);
428 }
429

This may be tricky to track down since it seems to work for the -t with a specific label and a specific -R rule but not -t to a directory. Will have a closer look at next opportunity.

@qchaupds
Copy link
Contributor

qchaupds commented May 4, 2021

Developer's note: could be helpful in debugging the pesky null pointer issue.

[pool-2-thread-1] DEBUG gov.nasa.pds.tools.validate.rule.RuleContext - getCheckInbetweenFields:CHECK_INBETWEEN_FIELDS validate.strict-field-checks
[pool-2-thread-1] DEBUG gov.nasa.pds.tools.validate.rule.RuleContext - getCheckInbetweenFields null
[pool-2-thread-1] DEBUG gov.nasa.pds.tools.util.Utility - isDir:file,url /home/qchau/sandbox/validate/src/test/resources/github291/valid/data_spectra/kgrs_calibrated_spectra_per1.xml,file:/home/qchau/sandbox/validate/src/test/resources/github291/valid/data_spectra/kgrs_calibrated_spectra_per1.xml
[pool-2-thread-1] DEBUG gov.nasa.pds.tools.util.Utility - isDir:ext_len,url 3,file:/home/qchau/sandbox/validate/src/test/resources/github291/valid/data_spectra/kgrs_calibrated_spectra_per1.xml
[pool-2-thread-1] DEBUG gov.nasa.pds.tools.util.Utility - isDir:isDir(),url,file false,file:/home/qchau/sandbox/validate/src/test/resources/github291/valid/data_spectra/kgrs_calibrated_spectra_per1.xml,/home/qchau/sandbox/validate/src/test/resources/github291/valid/data_spectra/kgrs_calibrated_spectra_per1.xml
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:71)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at gov.nasa.pds.tools.validate.rule.pds4.LabelInFolderRule$1.run(LabelInFolderRule.java:154)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.NullPointerException
at gov.nasa.pds.tools.validate.rule.RuleContext.getCheckInbetweenFields(RuleContext.java:428)
at gov.nasa.pds.tools.validate.rule.pds4.TableDataContentValidationRule.getCheckInbetweenFields(TableDataContentValidationRule.java:119)
at gov.nasa.pds.tools.validate.rule.pds4.TableDataContentValidationRule.validateTableDataContents(TableDataContentValidationRule.java:669)
... 12 more

@qchaupds
Copy link
Contributor

qchaupds commented May 4, 2021

We have some good results from the code fix in DEV. Running 3 different ways are now valid:

validate -R pds4.label --skip-context-validation -r report_github335_as_label.json -s json -t src/test/resources/github335/minimal_test_product.xml
validate --skip-context-validation -r report_github335_as_target.json -s json -t src/test/resources/github335/*.xml
validate --skip-context-validation -r report_github335_as_dir.json -s json -t src/test/resources/github335

{pds-dev3.jpl.nasa.gov}/home/qchau/sandbox/validate 174 % egrep "status|label" report_github335*.json
report_github335_as_dir.json: "status": "PASS",
report_github335_as_dir.json: "label": "file:/home/qchau/sandbox/validate/src/test/resources/github335/minimal_test_product.xml",
report_github335_as_label.json: "ruleType": "pds4.label",
report_github335_as_label.json: "status": "PASS",
report_github335_as_label.json: "label": "file:/home/qchau/sandbox/validate/src/test/resources/github335/minimal_test_product.xml",
report_github335_as_target.json: "status": "PASS",
report_github335_as_target.json: "label": "file:/home/qchau/sandbox/validate/src/test/resources/github335/minimal_test_product.xml",

Will check in the code at next opportunity.

qchaupds pushed a commit that referenced this issue May 5, 2021
…ased on record length instead of the normal <CR><LF> and null pointer should not show up.

1.  Correct the null pointer issue in RuleContext.java
2.  Move part of a long function into a shorter function validateTableContentLineWise() in TableDataContentValidationRule.java
3.  Add a peek into a text label for length of first line in TableDataContentValidationRule.java
4.  Add new function validateTableContentRecordWise() to process one record at a time according to record_length in TableDataContentValidationRule.java

Refs:

#325 Validate Incorrectly Throws Error When Embedded Field_Character Contains <CR><LF>
#335 validate gives a NullPointerException during validation of a directory containing Table_Character products
@qchaupds
Copy link
Contributor

qchaupds commented May 5, 2021

@jordanpadams Please close #336 as well when this issue is closed since it seems to be the same problem of null pointer.

jordanpadams added a commit that referenced this issue May 7, 2021
#338)

### Summary
Closes #325, #335

This pull request resolves two issues: Read the Table_Character correctly and corrected the null pointer when checking for a command line parameter.

Tested in DEV for #325
Previously would result in ERROR because it was reading the file line by line, which causes the record to end prematurely

% validate -R pds4.label --skip-context-validation -r report_github325_label_valid.json -s json -t src/test/resources/github325/crs009x.xml

Tested in DEV for #335
Three different ways to process a target, none should throw an exception.

% validate -R pds4.label --skip-context-validation -r report_github335_as_label.json -s json -t src/test/resources/github335/minimal_test_product.xml
% validate --skip-context-validation -r report_github335_as_target.json -s json -t src/test/resources/github335/*.xml
% validate --skip-context-validation -r report_github335_as_dir.json -s json -t src/test/resources/github335

---

* Read the Table_Character correctly to read to the end of the record based on record length instead of the normal <CR><LF> and null pointer should not show up.

1.  Correct the null pointer issue in RuleContext.java
2.  Move part of a long function into a shorter function validateTableContentLineWise() in TableDataContentValidationRule.java
3.  Add a peek into a text label for length of first line in TableDataContentValidationRule.java
4.  Add new function validateTableContentRecordWise() to process one record at a time according to record_length in TableDataContentValidationRule.java

Refs:

#325 Validate Incorrectly Throws Error When Embedded Field_Character Contains <CR><LF>
#335 validate gives a NullPointerException during validation of a directory containing Table_Character products

* Add javadoc to several functions

* Add missing test resources

* Update to latest PDS4 Jparser SNAPSHOT

* fix for backwards compatibility with java8

cast ByteBuffer to Buffer

* Add common error to docs for backwards incompatibility

when trying to run validate with bundle validation against a directory in java8, the software just hangs. updated docs with a workaround. refs #336

* Revert "Add common error to docs for backwards incompatibility"

This reverts commit a0158b8.

* Update regex to be more valid

This seems to work fine in newer versions of java, but java8 just hangs and doesn't know what do with those extra wildcards.

resolves #336

Co-authored-by: Qui T Chau <qchau@pds-dev3.jpl.nasa.gov>
Co-authored-by: Jordan Padams <jordan.h.padams@jpl.nasa.gov>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants