Saving new project causes null pointer exception

Hi, we are getting null pointer exception when trying to save project with:

public void save(OutputStream stream, int format)

outputStream and format are not null

Caused by: java.lang.NullPointerException
at com.aspose.tasks.Project.O(Unknown Source)
at com.aspose.tasks.Project.(Unknown Source)
at com.aspose.tasks.Project.(Unknown Source)
at com.aspose.tasks.qi.a(Unknown Source)
at com.aspose.tasks.qi.a(Unknown Source)
at com.aspose.tasks.XmlUtils.a(Unknown Source)
at com.aspose.tasks.dce.a(Unknown Source)
at com.aspose.tasks.bqr.a(Unknown Source)
at com.aspose.tasks.cka.c(Unknown Source)
at com.aspose.tasks.cka.a(Unknown Source)
at com.aspose.tasks.Project.save(Unknown Source)
at

Bundle-SymbolicName: com.aspose.tasks
Implementation-Version: 20.1

Can you help us what can cause the problem?

Hello @SoftwarePlant.

Could you please share working sample code and input file (if applicable) so we could reproduce the issue on our end. We will be able to proceed further with investigation on our end on provision of requested information.

project is created from template file:
project.mpp.zip (24.9 KB)

then we set fields on project:

Project project = createProject(templateFile);
    project.set(Prj.UID, structureData.getId());
			project.set(Prj.NAME, structureData.getSummary());
			project.set(Prj.START_DATE, DateTimeFactory.javaDateFrom(structureData.getStartDate()));
			project.set(Prj.FINISH_DATE, DateTimeFactory.javaDateFrom(structureData.getEndDate()));
			project.set(Prj.TIMESCALE_START, DateTimeFactory.javaDateFrom(structureData.getStartDate().plusDays(-2)));
			project.set(Prj.TIMESCALE_FINISH, DateTimeFactory.javaDateFrom(structureData.getEndDate().plusDays(2)));
			project.set(Prj.CURRENT_DATE, new Date());
			project.set(Prj.TITLE, structureData.getDescription());
			project.set(Prj.DURATION_FORMAT, TimeUnitType.Day);
			project.set(Prj.WORK_FORMAT, TimeUnitType.Day);
			project.set(Prj.DEFAULT_TASK_TYPE, TaskType.FixedDuration);
			project.set(Prj.SCHEDULE_FROM_START, NullableBool.to_NullableBool(true));
			project.setCalculationMode(CalculationMode.Manual);

		for (Filter filter : project.getTaskFilters().toList()) {
			if ("Wszystkie zadania".equals(filter.getName())) {
				filter.setName("All tasks");
			}
		}

		// Calendar
		log.debug("Calendar: {}", structureData.getCalendar().toString());
		Calendar calendar = new MSProjectCalendarExporter().export(structureData.getCalendar(), project);
		project.set(Prj.CALENDAR, calendar);

		// Tasks
		Map<Integer, Task> taskIdToExportedTask = new MSProjectTaskExporter().export(structureData.getTasks(), project, calendar);

		// Links
		new MSProjectTaskLinkExporter().export(structureData.getTaskLinks(), taskIdToExportedTask, project);

		project.recalculateResourceFields();

		saveProject(targetFileFormat, project, outputStream);

saveProject(file extension is XML):

if (FileFormat.XML.equals(fileFormat)) {
		File tempFile = File.createTempFile("tmp-ms-project-", "." + FileFormat.XML.getFileExtension());
		try {
			**project.save(tempFile.getAbsolutePath(), AsposeFileFormatType.getAsposeFileFormatType(fileFormat));**
			IOUtils.copy(new FileInputStream(tempFile), outputStream);
			return;
		} finally {
			tempFile.delete();
		}
	}

project.save(tempFile.getAbsolutePath(), SaveFileFormat.XML) causes null pointer.

@SoftwarePlant, hello.

I would like to draw you attention to that fact that the following classes/methods are missing:

new MSProjectCalendarExporter().export(structureData.getCalendar(), project);

new MSProjectTaskExporter().export(structureData.getTasks(), project, calendar);

new MSProjectTaskLinkExporter().export(structureData.getTaskLinks(), taskIdToExportedTask, project);

We need working sample code to reproduce the issue.

@SoftwarePlant, have you tried to run your code sample using Aspose.Tasks for Java v. 21.11 ?

exporters.zip (7.1 KB)
@vasiliysinitsyn please find the classes in the attached zip file

Hello @SoftwarePlant
Please check your code sample in latest version of Aspose.Tasks for Java.