Fix NullPointerException when creating job executions for job instances without executions
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
0a116824cb
commit
18ae02ab02
@@ -116,6 +116,10 @@ public class SimpleJobRepository implements JobRepository {
|
||||
|
||||
List<JobExecution> executions = jobExecutionDao.findJobExecutions(jobInstance);
|
||||
|
||||
if (executions.isEmpty()) {
|
||||
throw new IllegalStateException("Cannot find any job execution for job instance: " + jobInstance);
|
||||
}
|
||||
|
||||
// check for running executions and find the last started
|
||||
for (JobExecution execution : executions) {
|
||||
if (execution.isRunning() || execution.isStopping()) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -274,6 +275,14 @@ public class SimpleJobRepositoryTests {
|
||||
jobRepository.createJobExecution("foo", new JobParameters());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testCreateJobExecutionInstanceWithoutExecutions() throws Exception {
|
||||
when(jobInstanceDao.getJobInstance("foo", new JobParameters())).thenReturn(jobInstance);
|
||||
when(jobExecutionDao.findJobExecutions(jobInstance)).thenReturn(Collections.emptyList());
|
||||
|
||||
jobRepository.createJobExecution("foo", new JobParameters());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepExecutionCount() {
|
||||
// Given
|
||||
|
||||
Reference in New Issue
Block a user