joniles / mpxj

Primary repository for MPXJ library
http://www.mpxj.org/
GNU Lesser General Public License v2.1
250 stars 104 forks source link

Reading P6 XER file fails with Exception #743

Closed mavoalice closed 2 months ago

mavoalice commented 3 months ago

When reading a P6 XER file with code below.

var reader = new UniversalProjectReader(); projectFiles = reader.readAll(fileContent);

some of them (we know about 4 now, but I don't have simple XER file that I could provide) fail with exception below on readAll operation:

Caused by: java.lang.NullPointerException: Cannot invoke "java.time.LocalDate.getDayOfWeek()" because "date" is null
    at net.sf.mpxj.ProjectCalendar.getRanges(ProjectCalendar.java:1807) ~[mpxj-13.1.0.jar:?]
    at net.sf.mpxj.ProjectCalendar.getNextWorkStart(ProjectCalendar.java:907) ~[mpxj-13.1.0.jar:?]
    at net.sf.mpxj.primavera.TimephasedHelper.read(TimephasedHelper.java:62) ~[mpxj-13.1.0.jar:?]
    at net.sf.mpxj.primavera.PrimaveraReader.processAssignments(PrimaveraReader.java:1814) ~[mpxj-13.1.0.jar:?]
    at net.sf.mpxj.primavera.PrimaveraXERFileReader.processAssignments(PrimaveraXERFileReader.java:582) ~[mpxj-13.1.0.jar:?]
    at net.sf.mpxj.primavera.PrimaveraXERFileReader.readProject(PrimaveraXERFileReader.java:243) ~[mpxj-13.1.0.jar:?]
    at net.sf.mpxj.primavera.PrimaveraXERFileReader.readAll(PrimaveraXERFileReader.java:168) ~[mpxj-13.1.0.jar:?]
    at net.sf.mpxj.reader.UniversalProjectReader$StreamReaderProxy.readAll(UniversalProjectReader.java:164) ~[mpxj-13.1.0.jar:?]
    at net.sf.mpxj.reader.UniversalProjectReader.readAll(UniversalProjectReader.java:307) ~[mpxj-13.1.0.jar:?]
    ... 21 more

I assume there is a missing NPE check in ProjectCalendar class on date? As in getException and getWorkWeek the date is checked for null.

protected ProjectCalendarHours getRanges(LocalDate date)
   {
      // Check for exceptions for this date in this calendar and any base calendars
      ProjectCalendarHours ranges = getException(date);
      if (ranges != null)
      {
         return ranges;
      }

      // Determine which week definition to use
      ProjectCalendarDays week = getWorkWeek(date);
      if (week == null)
      {
         week = this;
      }

      // Use the day type to retrieve the ranges
      DayOfWeek day = date.getDayOfWeek(); // NPE here
}

Version used: 13.1.0, but fails also on 13.3.0, Java 21

lnevaril commented 3 months ago

Hi, I can provide some additional information about the issue. The problem is that resource assignment in the XER file contains non-null value for the property remain_crv but at the same time it is missing property restart_date (accessed through assignment.getRemainingEarlyStart()).

Problem leading to the NPE starts here:

net.sf.mpxj.primavera.PrimaveraReader#processAssignments

TimephasedWorkContainer timephasedRemainingWork = TimephasedHelper.read(effectiveCalendar, assignment.getRemainingEarlyStart(), row.getString("remain_crv"));

I can provide you the file to replicate the issue via email. No problem is encountered when importing the file to P6 and it just ignores the budgeted, actual and remaining units setting them all to 0.

Screenshot 2024-08-29 at 16 30 46
joniles commented 3 months ago

@lnevaril if you could provide a sample file that would be very helpful - thanks!

joniles commented 2 months ago

I've updated MPXJ to handle this, the changes will be in the next release which I'll try to get out today.