Skip to content

Bug: Attempting to do a versioned read of a resource that was just expunged causes NullPointerException until it is expired in memory cache #7251

@ttntrifork

Description

@ttntrifork

Describe the bug

  • Attempting to do a versioned read of a resource that was just expunged (via MdmStorageInterceptor when isAutoExpungeGoldenResources == true) causes NullPointerException, until it is expired in the "forced id" memory cache (1 minute expiration), after which it then correctly throws ResourceNotFoundException as expected.

Expected behavior

  • The versioned read should cause a ResourceNotFoundException even if the PID is not yet expired in the memory cache

To Reproduce

  • I will open a PR that simulates the problem via a unit test and fixes it by introducing a null guard such that BaseHapiFhirResourceDao correctly throws a ResourceNotFoundException even if the PID is not yet expired in the memory cache

Fix Details
The problem could probably also be fixed by invalidating the caches after commit, as is done in https://github.com/hapifhir/hapi-fhir/blob/v8.4.0/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/expunge/JpaResourceExpungeService.java#L212-L225
But the null guard seems good to have in any case (and fixes the issue without invalidating the entire cache).

  • It could even be considered that the JpaResourceExpungeService should stop invalidating the cache (and thereby stop incurring a performance cost) with this fix?

Stacktrace:

Caused by: java.lang.NullPointerException: Cannot invoke "ca.uhn.fhir.jpa.model.entity.BaseHasResource.getVersion()" because "entity" is null
	at ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.readEntity(BaseHapiFhirResourceDao.java:1944)
	at ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.lambda$readEntity$21(BaseHapiFhirResourceDao.java:1680)
	at ca.uhn.fhir.jpa.dao.tx.HapiTransactionService.invokeCallableAndHandleAnyException(HapiTransactionService.java:663)
	... 13 more

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions