From 09a31f0bd8a03ff17ea160961e050e263fb1386e Mon Sep 17 00:00:00 2001 From: joniles Date: Thu, 25 Jul 2024 12:35:47 +0100 Subject: [PATCH] P6: handle invalid calendar exceptions --- src/changes/changes.xml | 1 + .../sf/mpxj/primavera/PrimaveraReader.java | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8363df9098..f605d07482 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -16,6 +16,7 @@ Improve recognition of non-working days when reading calendars certain PMXML files. Add support for the Resource Assignment field Remaining Units. (Note: this field defaults to the same value as Units if it is not explicitly populated). Ensure the Resource Assignment field Remaining Units is read from and written to P6 schedules. + Improve handling of invalid calendar exception data when reading P6 schedules from XER files or a P6 database. When writing XER files, provide a default value for the Resource ID if it is not populated. diff --git a/src/main/java/net/sf/mpxj/primavera/PrimaveraReader.java b/src/main/java/net/sf/mpxj/primavera/PrimaveraReader.java index d53a390caa..51423ab90e 100644 --- a/src/main/java/net/sf/mpxj/primavera/PrimaveraReader.java +++ b/src/main/java/net/sf/mpxj/primavera/PrimaveraReader.java @@ -655,7 +655,26 @@ private void processCalendarExceptions(ProjectCalendar calendar, StructuredTextR { for (StructuredTextRecord exception : exceptions.getChildren()) { - long daysFromEpoch = Integer.parseInt(exception.getAttribute("d")); + long daysFromEpoch; + + try + { + daysFromEpoch = Integer.parseInt(exception.getAttribute("d")); + } + + catch (NumberFormatException ex) + { + if (m_ignoreErrors) + { + m_project.addIgnoredError(ex); + continue; + } + else + { + throw ex; + } + } + LocalDate startEx = EXCEPTION_EPOCH.plusDays(daysFromEpoch); ProjectCalendarException pce = calendar.addCalendarException(startEx, startEx);