NullPointerException in

Hi devs,

We have encountered a null pointer exception from when trying to add a new event using Event Capture.

Anyway, when looking at the code I realized that, null pointer exception is possible in the following piece of code.

List programInstances = getActiveProgramInstances( cacheKey, program );

        if ( programInstances == null || programInstances.isEmpty() )


            // Create PI if it doesn't exist (should only be one)

            ProgramInstance pi = new ProgramInstance();

            pi.setEnrollmentDate( new Date() );

            pi.setIncidentDate( new Date() );

            pi.setProgram( program );

            pi.setStatus( ProgramStatus.ACTIVE );

            programInstanceService.addProgramInstance( pi );

            programInstances.add( pi );


Here, if block can be executed even if programInstances is null, but at the end we are adding an object to the possible null List.

To be exact, this is line 427-442 of dhis2-core, 2.28 branch.



HISP Sri Lanka