jscancella / bagging

A clean and easy to use implementation of the BagIt specification
Other
2 stars 7 forks source link

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

Closed sprater closed 4 years ago

sprater commented 4 years ago

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/jscancella/bagging/blob/master/src/main/java/com/github/jscancella/conformance/profile/BagitProfileDeserializer.java#L183), 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

When

Then

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

jscancella commented 4 years ago

@sprater I have most of the work done, but I won't be able to work on this again for a few weeks. See https://github.com/jscancella/bagging/tree/bagit_profile if you want to help fix the remaining issues (just run ./gradlew check

sprater commented 4 years ago

@jscancella Sounds good. I first need to refactor my own code to use your library, in place of the older bagit-java library. Once I finish that, I'll look into this, and submit a PR.

Do you plan on tagging and pushing a release to maven central at some point?

jscancella commented 4 years ago

It has been on my TODO list, currently I have it uploaded to jcenter. See https://bintray.com/jscancella/com.github.jscancella/bagging

jscancella commented 4 years ago

This should be fixed in my latest merge. Please take a look and let me know if you find any problems. I will probably make another version and release it to jcenter soon.

sprater commented 4 years ago

@jscancella I pulled master after your PR was merged, and built bagging. The build failed a javadoc check and some SpotBugs checks, but all the tests passed. Is master the correct branch to be working from right now?

jscancella commented 4 years ago

Yes it is the correct branch. It builds fine on all the CI servers, as well as on my PC. I need more information in order to figure out what is wrong with your build:

Go ahead and submit this information in a new issue if you are still having a problem.

sprater commented 4 years ago

SpotBugs task passes when running under Java 8 -- I had inadvertently attempted to build it using Java 11.

Still three javadoc errors when I run a "clean check" on Windows, using Java 8. see issue #33 .