Fix NullPointerException when creating job executions for job instances without executions
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
dc6618c475
commit
c7f9d582bf
@@ -115,6 +115,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()) {
|
||||
|
||||
@@ -26,6 +26,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;
|
||||
|
||||
@@ -272,4 +273,12 @@ 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user