Skip to content

Commit 0660a4b

Browse files
luis100claude
andcommitted
fix: null-check getLABEL() before calling equals/matches in StructMapValidator
Fixes NullPointerException in validateCSIP88 (and 9 other methods) when a CSIP <div> or <structMap> element has no LABEL attribute. LABEL is optional in the METS schema, so packages without a representations folder (metadata-only SIPs) could crash the entire validation run instead of producing a report. Fixes #378 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y4iKxBwBcXisaP7MJVJ6VN
1 parent f842a48 commit 0660a4b

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/main/java/org/roda_project/commons_ip2/validator/components/structuralMapComponent/StructMapValidator.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected ReporterDetails validateCSIP84(final MetsValidatorState metsValidatorS
164164
final List<StructMapType> structMap = metsValidatorState.getMets().getStructMap();
165165
if (structMap != null) {
166166
for (StructMapType struct : structMap) {
167-
if (struct.getLABEL().equals("CSIP")) {
167+
if (struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) {
168168
final DivType div = struct.getDiv();
169169
if (div == null) {
170170
return new ReporterDetails(Constants.VALIDATION_REPORT_HEADER_CSIP_VERSION,
@@ -222,7 +222,7 @@ protected ReporterDetails validateCSIP86(final MetsValidatorState metsValidatorS
222222
if (structMap != null) {
223223
for (StructMapType struct : structMap) {
224224
final DivType div = struct.getDiv();
225-
if (div != null && struct.getLABEL().equals("CSIP")) {
225+
if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) {
226226
final String label = div.getLABEL();
227227
if (label == null) {
228228
return new ReporterDetails(Constants.VALIDATION_REPORT_HEADER_CSIP_VERSION,
@@ -284,7 +284,7 @@ protected ReporterDetails validateCSIP88(final MetsValidatorState metsValidatorS
284284
final List<DivType> divs = struct.getDiv().getDiv();
285285
int counter = 0;
286286
for (DivType d : divs) {
287-
if (d.getLABEL().equals("Metadata")) {
287+
if (d.getLABEL() != null && d.getLABEL().equals("Metadata")) {
288288
counter++;
289289
}
290290
}
@@ -1206,10 +1206,10 @@ protected ReporterDetails validateCSIP105(final MetsValidatorState metsValidator
12061206
if (metsValidatorState.isRootMets()) {
12071207
for (StructMapType struct : structMap) {
12081208
final DivType firstDiv = struct.getDiv();
1209-
if (firstDiv != null && struct.getLABEL().equals("CSIP")) {
1209+
if (firstDiv != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) {
12101210
final List<DivType> divs = firstDiv.getDiv();
12111211
for (DivType div : divs) {
1212-
if (div.getLABEL().matches("Representations/.*/") && div.getMptr().isEmpty()) {
1212+
if (div.getLABEL() != null && div.getLABEL().matches("Representations/.*/") && div.getMptr().isEmpty()) {
12131213
return new ReporterDetails(Constants.VALIDATION_REPORT_HEADER_CSIP_VERSION,
12141214
Message.createErrorMessage(
12151215
"When a package consists of multiple representations, "
@@ -1275,7 +1275,7 @@ protected ReporterDetails validateCSIP107(final StructureValidatorState structur
12751275
if (structMap != null) {
12761276
for (StructMapType struct : structMap) {
12771277
final DivType div = struct.getDiv();
1278-
if (div != null && struct.getLABEL().equals("CSIP")) {
1278+
if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) {
12791279
final List<DivType> divs = div.getDiv();
12801280
for (DivType d : divs) {
12811281
final String label = d.getLABEL();
@@ -1352,7 +1352,7 @@ protected ReporterDetails validateCSIP108(final MetsValidatorState metsValidator
13521352
if (structMap != null) {
13531353
for (StructMapType struct : structMap) {
13541354
final DivType div = struct.getDiv();
1355-
if (div != null && struct.getLABEL().equals("CSIP")) {
1355+
if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) {
13561356
final List<DivType> divs = div.getDiv();
13571357
for (DivType d : divs) {
13581358
if (d.getLABEL() != null && d.getLABEL().matches("Representations/.*")) {
@@ -1404,7 +1404,7 @@ protected ReporterDetails validateCSIP109(final MetsValidatorState metsValidator
14041404
if (structMap != null) {
14051405
for (StructMapType struct : structMap) {
14061406
final DivType div = struct.getDiv();
1407-
if (div != null && struct.getLABEL().equals("CSIP")) {
1407+
if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) {
14081408
final List<DivType> divs = div.getDiv();
14091409
for (DivType d : divs) {
14101410
if (d.getLABEL() != null && d.getLABEL().matches("Representations/.*")) {
@@ -1437,10 +1437,10 @@ protected ReporterDetails validateCSIP110(final StructureValidatorState structur
14371437
if (structMap != null) {
14381438
for (StructMapType struct : structMap) {
14391439
final DivType div = struct.getDiv();
1440-
if (div != null && struct.getLABEL().equals("CSIP")) {
1440+
if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) {
14411441
final List<DivType> divs = div.getDiv();
14421442
for (DivType d : divs) {
1443-
if (d.getLABEL().matches("Representations/.*")) {
1443+
if (d.getLABEL() != null && d.getLABEL().matches("Representations/.*")) {
14441444
final List<DivType.Mptr> mptrs = d.getMptr();
14451445
if (!mptrs.isEmpty()) {
14461446
for (DivType.Mptr mptr : mptrs) {
@@ -1526,7 +1526,7 @@ protected ReporterDetails validateCSIP111(final StructureValidatorState structur
15261526
if (!structMap.isEmpty()) {
15271527
for (StructMapType struct : structMap) {
15281528
final DivType div = struct.getDiv();
1529-
if (div != null && struct.getLABEL().equals("CSIP")) {
1529+
if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) {
15301530
final List<DivType> divs = div.getDiv();
15311531
for (DivType d : divs) {
15321532
if (d.getLABEL() != null && d.getLABEL().matches("Representations/")) {
@@ -1567,7 +1567,7 @@ protected ReporterDetails validateCSIP112(final MetsValidatorState metsValidator
15671567
if (structMap != null) {
15681568
for (StructMapType struct : structMap) {
15691569
final DivType div = struct.getDiv();
1570-
if (div != null && struct.getLABEL().equals("CSIP")) {
1570+
if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) {
15711571
final List<DivType> divs = div.getDiv();
15721572
for (DivType d : divs) {
15731573
if (d.getLABEL() != null && d.getLABEL().matches("Representations/")) {

0 commit comments

Comments
 (0)