diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapExecutionContextDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapExecutionContextDao.java index 80a9c0961..94c54c423 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapExecutionContextDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapExecutionContextDao.java @@ -27,8 +27,9 @@ import org.springframework.batch.support.transaction.TransactionAwareProxyFactor /** * In-memory implementation of {@link ExecutionContextDao} backed by static * maps. - * + * * @author Robert Kasanicky + * @author Dave Syer */ public class MapExecutionContextDao implements ExecutionContextDao { @@ -52,7 +53,10 @@ public class MapExecutionContextDao implements ExecutionContextDao { } public void updateExecutionContext(StepExecution stepExecution) { - contextsByStepExecutionId.put(stepExecution.getId(), copy(stepExecution.getExecutionContext())); + ExecutionContext executionContext = stepExecution.getExecutionContext(); + if (executionContext != null) { + contextsByStepExecutionId.put(stepExecution.getId(), copy(executionContext)); + } } public ExecutionContext getExecutionContext(JobExecution jobExecution) { @@ -60,7 +64,10 @@ public class MapExecutionContextDao implements ExecutionContextDao { } public void updateExecutionContext(JobExecution jobExecution) { - contextsByJobExecutionId.put(jobExecution.getId(), copy(jobExecution.getExecutionContext())); + ExecutionContext executionContext = jobExecution.getExecutionContext(); + if (executionContext != null) { + contextsByJobExecutionId.put(jobExecution.getId(), copy(executionContext)); + } } public void saveExecutionContext(JobExecution jobExecution) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java index df069203a..b6e857afd 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java @@ -67,7 +67,7 @@ public class TransactionAwareProxyFactory { * @return an independent copy */ @SuppressWarnings("unchecked") - protected final T begin(T target) { + protected synchronized final T begin(T target) { if (target instanceof List) { return (T) new ArrayList((List) target); } @@ -91,7 +91,7 @@ public class TransactionAwareProxyFactory { * @param target the original target of the factory. */ @SuppressWarnings("unchecked") - protected void commit(T copy, T target) { + protected synchronized void commit(T copy, T target) { if (target instanceof Collection) { ((Collection) target).clear(); ((Collection) target).addAll((Collection) copy);