From 11169bae108e2fe7825dbe34a482f400a40fb513 Mon Sep 17 00:00:00 2001 From: Mark John Moreno Date: Tue, 16 May 2023 19:37:28 +0800 Subject: [PATCH] Align exception message with exception handling condition Resolves #4025 --- .../repository/support/SimpleJobRepository.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java index cabece4e0..44f8bf6ec 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java @@ -21,7 +21,6 @@ import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; -import org.springframework.batch.core.JobParameter; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; @@ -54,6 +53,7 @@ import java.util.List; * @author Mahmoud Ben Hassine * @author Baris Cubukcuoglu * @author Parikshit Dutta + * @author Mark John Moreno * @see JobRepository * @see JobInstanceDao * @see JobExecutionDao @@ -151,15 +151,14 @@ public class SimpleJobRepository implements JobRepository { + "The last execution ended with a failure that could not be rolled back, " + "so it may be dangerous to proceed. Manual intervention is probably necessary."); } - Collection> allJobParameters = execution.getJobParameters().getParameters().values(); - long identifyingJobParametersCount = allJobParameters.stream() - .filter(JobParameter::isIdentifying) - .count(); - if (identifyingJobParametersCount > 0 + JobParameters allJobParameters = execution.getJobParameters(); + JobParameters identifyingJobParameters = new JobParameters(allJobParameters.getIdentifyingParameters()); + if (!identifyingJobParameters.isEmpty() && (status == BatchStatus.COMPLETED || status == BatchStatus.ABANDONED)) { throw new JobInstanceAlreadyCompleteException( - "A job instance already exists and is complete for parameters=" + jobParameters - + ". If you want to run this job again, change the parameters."); + "A job instance already exists and is complete for identifying parameters=" + + identifyingJobParameters + ". If you want to run this job again, " + + "change the parameters."); } } executionContext = ecDao.getExecutionContext(jobExecutionDao.getLastJobExecution(jobInstance));