bagit-java icon indicating copy to clipboard operation
bagit-java copied to clipboard

NPE is thrown when validating a bag against a BagIt profile

Open sprater opened this issue 6 years ago • 2 comments

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

sprater avatar Dec 30 '19 22:12 sprater

@sprater I don't think this library is maintained anymore. Feel free to submit to my maintained fork of this library at https://github.com/jscancella/bagging

jscancella avatar Dec 31 '19 19:12 jscancella

Will do, thanks @jscancella.

sprater avatar Dec 31 '19 19:12 sprater