Skip to content

ClassCastException when reading def_cost_per_qty with setIgnoreErrors(false) in 16.7.0 #938

Description

@lkp-k

Hi I'm using 16.7.0 with Java 21. Disclaimer: I am trying to learn how to use mpxj and I'm using a example P6 .xer file I found online for testing purposes here https://www.onepager.com/solutions/construction/hospital-expansion-project.html

However, even all the .xer you use in your own tests like ProjectDefaultCalendar.xer lead to the same issue. For example the calendar test uses the default reader which is more lenient and doesn't check this price. So they do not detect this problem.

Anyway I encountered ClassCastException when reading the file with setIgnoreErrors(false).

In that .xer file I tested, the project def_cost_per_qty is 100.0000 so

import org.mpxj.primavera.PrimaveraXERFileReader;

public class Repro {
    public static void main(String[] args) throws Exception {
        var reader = new PrimaveraXERFileReader();
        reader.setIgnoreErrors(false);
        reader.readAll("Hospital Expansion Project.xer");
    }
}

I would expect the file to load successfully and getActivityDefaultPricePerUnit() to return 100.0.

Instead reading fails with ClassCastException: java.lang.String cannot be cast to java.lang.Number in AbstractRow.getDouble, called from TableProjectReader.processProjectProperties.

In your library code, def_cost_per_qty appears to be missing from XerFile.FIELD_TYPE_MAP. So, it defaults to DataType.STRING, but the project reader subsequently requests it through row.getDouble("def_cost_per_qty").

The likely fix might be

FIELD_TYPE_MAP.put("def_cost_per_qty", DataType.NUMERIC);

With setIgnoreErrors(true), the read completes, but getActivityDefaultPricePerUnit() returns null and getIgnoredErrors() is empty so I don't know how I can detect that lost value.

Does that diagnosis look correct?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions