Java validator crashes when using fullUrl and references in a bundle (JSON)

I’ve found that the Java validator crashes instead of returning useful messages for certain inputs. Run this command on the following bundle:

java -jar validator/org.hl7.fhir.validator.jar transaction-crash.json -defn definitions.xml.zip

  .. load FHIR from definitions.xml.zip
  .. connect to tx server @ http://tx.fhir.org/r3
    (vnull-null)
  .. validate
Exception in thread "main" java.lang.NullPointerException
	at org.hl7.fhir.dstu3.validation.InstanceValidator.getFromBundle(InstanceValidator.java:1838)
	at org.hl7.fhir.dstu3.validation.InstanceValidator.localResolve(InstanceValidator.java:2051)
	at org.hl7.fhir.dstu3.validation.InstanceValidator.checkReference(InstanceValidator.java:1381)
	at org.hl7.fhir.dstu3.validation.InstanceValidator.validateElement(InstanceValidator.java:3186)
	at org.hl7.fhir.dstu3.validation.InstanceValidator.start(InstanceValidator.java:2344)
	at org.hl7.fhir.dstu3.validation.InstanceValidator.validateResource(InstanceValidator.java:3420)
	at org.hl7.fhir.dstu3.validation.InstanceValidator.validateContains(InstanceValidator.java:2918)
	at org.hl7.fhir.dstu3.validation.InstanceValidator.validateElement(InstanceValidator.java:3192)
	at org.hl7.fhir.dstu3.validation.InstanceValidator.validateElement(InstanceValidator.java:3253)
	at org.hl7.fhir.dstu3.validation.InstanceValidator.start(InstanceValidator.java:2344)
	at org.hl7.fhir.dstu3.validation.InstanceValidator.validateResource(InstanceValidator.java:3420)
	at org.hl7.fhir.dstu3.validation.InstanceValidator.validate(InstanceValidator.java:532)
	at org.hl7.fhir.dstu3.validation.InstanceValidator.validate(InstanceValidator.java:382)
	at org.hl7.fhir.dstu3.validation.ValidationEngine.validate(ValidationEngine.java:473)
	at org.hl7.fhir.dstu3.validation.ValidationEngine.validate(ValidationEngine.java:401)
	at org.hl7.fhir.dstu3.validation.Validator.main(Validator.java:248)

The problem with this bundle is that the first resource is missing a fullUrl, but the second resource has a fullUrl. If you add a fullUrl to the first resource, it validates successfully. If you remove the fullUrl from the second resource, the validator returns an appropriate error message. Likewise, removing the reference to the Patient resource from the Coverage resource prevents the crash.

{
  "resourceType": "Bundle",
  "id": "bundle-transaction",
  "type": "transaction",
  "entry": [
    {
      "resource": {
        "resourceType": "Patient",
        "id": "patient1",
        "identifier": [
          {
            "type": {
              "coding": [
                {
                  "system": "http://hl7.org/fhir/v2/0203",
                  "code": "MR"
                }
              ],
              "text": "Medical Record Number"
            },
            "value": "abcd1234"
          }
        ],
        "name": [
          {
            "family": "Doe",
            "given": [
              "John",
              "Wayne"
            ],
            "suffix": "Jr."
          }
        ],
        "gender": "male",
        "birthDate": "1991-12-01",
        "address": [
          {
            "use": "home",
            "type": "postal",
            "line": "1234 South Orange Ave",
            "city": "Orlando",
            "state": "FL",
            "postalCode": "32812"
          }
        ]
      },
      "request": {
        "method": "POST",
        "url": "Patient"
      }
    },
    {
      "fullUrl": "urn:uuid:79378cb8-8f58-48e8-a5e8-60ac2755b674",
      "resource": {
        "resourceType": "Coverage",
        "id": "selfPay",
        "status": "active",
        "type": {
          "coding": [
            {
              "system": "http://hl7.org/fhir/coverage-selfpay",
              "code": "pay"
            }
          ]
        },
        "relationship": {
          "coding": [
            {
              "code": "self"
            }
          ]
        },
        "payor": [
          {
            "reference": "Patient/patient1"
          }
        ]
      },
      "request": {
        "method": "POST",
        "url": "Coverage"
      }
    }
  ]
}

Can you please submit a change request? (“Propose a change” link at the bottom of each page in the spec. - That’s how we track tooling bugs as well as requests for changes to the specification.)

I’m also facing the same issue with validation of Bundle. Did you resolve the issue @Craig_Finch ?

.. load FHIR from definitions.json.zip .. connect to tx server @ http://tx.fhir.org/r3 (vnull-null) .. validate Exception in thread "main" java.lang.NullPointerException at org.hl7.fhir.dstu3.validation.InstanceValidator.validateBundle(InstanceValidator.java:2820) at org.hl7.fhir.dstu3.validation.InstanceValidator.start(InstanceValidator.java:2349) at org.hl7.fhir.dstu3.validation.InstanceValidator.validateResource(InstanceValidator.java:3420) at org.hl7.fhir.dstu3.validation.InstanceValidator.validate(InstanceValidator.java:532) at org.hl7.fhir.dstu3.validation.InstanceValidator.validate(InstanceValidator.java:382) at org.hl7.fhir.dstu3.validation.ValidationEngine.validate(ValidationEngine.java:473) at org.hl7.fhir.dstu3.validation.ValidationEngine.validate(ValidationEngine.java:401) at org.hl7.fhir.dstu3.validation.Validator.main(Validator.java:248)

Are you using the current version of the validator? (The one from build.fhir.org)

Yes it is good to use latest version