← Back to team overview

dhis2-devs team mailing list archive

NullPointerException in AbstractEventService.java

 

Hi devs,

We have encountered a null pointer exception from AbstractEventService.java
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<ProgramInstance> 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 AbstractEventService.java line 427-442 of dhis2-core,
2.28 branch.

Thanks,
Chathura
HISP Sri Lanka