From 0660a4bdcb0ef0c5799f3200c36af79a8a79ead5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Faria?= Date: Thu, 2 Jul 2026 08:41:38 +0100 Subject: [PATCH] fix: null-check getLABEL() before calling equals/matches in StructMapValidator Fixes NullPointerException in validateCSIP88 (and 9 other methods) when a CSIP
or 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 Claude-Session: https://claude.ai/code/session_01Y4iKxBwBcXisaP7MJVJ6VN --- .../StructMapValidator.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/roda_project/commons_ip2/validator/components/structuralMapComponent/StructMapValidator.java b/src/main/java/org/roda_project/commons_ip2/validator/components/structuralMapComponent/StructMapValidator.java index ee7d557c..409ae727 100644 --- a/src/main/java/org/roda_project/commons_ip2/validator/components/structuralMapComponent/StructMapValidator.java +++ b/src/main/java/org/roda_project/commons_ip2/validator/components/structuralMapComponent/StructMapValidator.java @@ -164,7 +164,7 @@ protected ReporterDetails validateCSIP84(final MetsValidatorState metsValidatorS final List structMap = metsValidatorState.getMets().getStructMap(); if (structMap != null) { for (StructMapType struct : structMap) { - if (struct.getLABEL().equals("CSIP")) { + if (struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) { final DivType div = struct.getDiv(); if (div == null) { return new ReporterDetails(Constants.VALIDATION_REPORT_HEADER_CSIP_VERSION, @@ -222,7 +222,7 @@ protected ReporterDetails validateCSIP86(final MetsValidatorState metsValidatorS if (structMap != null) { for (StructMapType struct : structMap) { final DivType div = struct.getDiv(); - if (div != null && struct.getLABEL().equals("CSIP")) { + if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) { final String label = div.getLABEL(); if (label == null) { return new ReporterDetails(Constants.VALIDATION_REPORT_HEADER_CSIP_VERSION, @@ -284,7 +284,7 @@ protected ReporterDetails validateCSIP88(final MetsValidatorState metsValidatorS final List divs = struct.getDiv().getDiv(); int counter = 0; for (DivType d : divs) { - if (d.getLABEL().equals("Metadata")) { + if (d.getLABEL() != null && d.getLABEL().equals("Metadata")) { counter++; } } @@ -1206,10 +1206,10 @@ protected ReporterDetails validateCSIP105(final MetsValidatorState metsValidator if (metsValidatorState.isRootMets()) { for (StructMapType struct : structMap) { final DivType firstDiv = struct.getDiv(); - if (firstDiv != null && struct.getLABEL().equals("CSIP")) { + if (firstDiv != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) { final List divs = firstDiv.getDiv(); for (DivType div : divs) { - if (div.getLABEL().matches("Representations/.*/") && div.getMptr().isEmpty()) { + if (div.getLABEL() != null && div.getLABEL().matches("Representations/.*/") && div.getMptr().isEmpty()) { return new ReporterDetails(Constants.VALIDATION_REPORT_HEADER_CSIP_VERSION, Message.createErrorMessage( "When a package consists of multiple representations, " @@ -1275,7 +1275,7 @@ protected ReporterDetails validateCSIP107(final StructureValidatorState structur if (structMap != null) { for (StructMapType struct : structMap) { final DivType div = struct.getDiv(); - if (div != null && struct.getLABEL().equals("CSIP")) { + if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) { final List divs = div.getDiv(); for (DivType d : divs) { final String label = d.getLABEL(); @@ -1352,7 +1352,7 @@ protected ReporterDetails validateCSIP108(final MetsValidatorState metsValidator if (structMap != null) { for (StructMapType struct : structMap) { final DivType div = struct.getDiv(); - if (div != null && struct.getLABEL().equals("CSIP")) { + if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) { final List divs = div.getDiv(); for (DivType d : divs) { if (d.getLABEL() != null && d.getLABEL().matches("Representations/.*")) { @@ -1404,7 +1404,7 @@ protected ReporterDetails validateCSIP109(final MetsValidatorState metsValidator if (structMap != null) { for (StructMapType struct : structMap) { final DivType div = struct.getDiv(); - if (div != null && struct.getLABEL().equals("CSIP")) { + if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) { final List divs = div.getDiv(); for (DivType d : divs) { if (d.getLABEL() != null && d.getLABEL().matches("Representations/.*")) { @@ -1437,10 +1437,10 @@ protected ReporterDetails validateCSIP110(final StructureValidatorState structur if (structMap != null) { for (StructMapType struct : structMap) { final DivType div = struct.getDiv(); - if (div != null && struct.getLABEL().equals("CSIP")) { + if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) { final List divs = div.getDiv(); for (DivType d : divs) { - if (d.getLABEL().matches("Representations/.*")) { + if (d.getLABEL() != null && d.getLABEL().matches("Representations/.*")) { final List mptrs = d.getMptr(); if (!mptrs.isEmpty()) { for (DivType.Mptr mptr : mptrs) { @@ -1526,7 +1526,7 @@ protected ReporterDetails validateCSIP111(final StructureValidatorState structur if (!structMap.isEmpty()) { for (StructMapType struct : structMap) { final DivType div = struct.getDiv(); - if (div != null && struct.getLABEL().equals("CSIP")) { + if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) { final List divs = div.getDiv(); for (DivType d : divs) { if (d.getLABEL() != null && d.getLABEL().matches("Representations/")) { @@ -1567,7 +1567,7 @@ protected ReporterDetails validateCSIP112(final MetsValidatorState metsValidator if (structMap != null) { for (StructMapType struct : structMap) { final DivType div = struct.getDiv(); - if (div != null && struct.getLABEL().equals("CSIP")) { + if (div != null && struct.getLABEL() != null && struct.getLABEL().equals("CSIP")) { final List divs = div.getDiv(); for (DivType d : divs) { if (d.getLABEL() != null && d.getLABEL().matches("Representations/")) {