Skip to content

NPE is thrown when validating a bag against a BagIt profile #136

@sprater

Description

@sprater

bagit-java version: 5.2.0
Operating System CentOS (Linux) 7

A null pointer exception is thrown when I attempt to validate a bag against a BagIt 1.3.0 profile without a Manifests-Required block. Looking at the class BagitProfileDeserializer (https://github.com/LibraryOfCongress/bagit-java/blob/5.2.0/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java), it looks like all the parse* methods will throw NPEs in their for loops if the parsed block does not exist in the profile.

As I read the latest BagIt profile spec 1.3.0 (https://bagit-profiles.github.io/bagit-profiles-specification/), none of the blocks that throw NPEs if missing are required to be in a profile.

Given

  • I have a BagIt profile without a "Manfests-Required" block
  • And I have a Bag that references this profile

When

  • I validate the Bag against the profile

Then

  • The Bag should validate.

Log output:

$ java -jar target/bagmanager.jar verify --with-profile /var/tmp/testbag1
Verifying valid bag from contents at '/var/tmp/testbag1'
Verifying conformance to BagIt profile
Bag is not valid
java.lang.NullPointerException: null
        at gov.loc.repository.bagit.conformance.profile.BagitProfileDeserializer.parseManifestTypesRequired(BagitProfileDeserializer.java:128)
        at gov.loc.repository.bagit.conformance.profile.BagitProfileDeserializer.deserialize(BagitProfileDeserializer.java:47)
        at gov.loc.repository.bagit.conformance.profile.BagitProfileDeserializer.deserialize(BagitProfileDeserializer.java:24)
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4011)
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3058)
        at gov.loc.repository.bagit.conformance.BagProfileChecker.parseBagitProfile(BagProfileChecker.java:95)
        at gov.loc.repository.bagit.conformance.BagProfileChecker.bagConformsToProfile(BagProfileChecker.java:73)
[...]

bagit-profile-sample-v1_0_json.txt

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