diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/DefaultJobKeyGenerator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/DefaultJobKeyGenerator.java index bb9920c72..591e8cbf9 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/DefaultJobKeyGenerator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/DefaultJobKeyGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.springframework.util.Assert; + /** * Default implementation of the {@link JobKeyGenerator} interface. * This implementation provides a single hash value based on the JobParameters @@ -31,6 +33,7 @@ import java.util.Map; * are used in the calculation of the key. * * @author Michael Minella + * @author Mahmoud Ben Hassine * @since 2.2 */ public class DefaultJobKeyGenerator implements JobKeyGenerator { @@ -42,6 +45,7 @@ public class DefaultJobKeyGenerator implements JobKeyGenerator { @Override public String generateKey(JobParameters source) { + Assert.notNull(source, "source must not be null"); Map props = source.getParameters(); StringBuilder stringBuffer = new StringBuilder(); List keys = new ArrayList(props.keySet()); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/ItemReadListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/ItemReadListener.java index b96214685..879e09766 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/ItemReadListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/ItemReadListener.java @@ -17,7 +17,6 @@ package org.springframework.batch.core; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; -import org.springframework.lang.Nullable; /** * Listener interface around the reading of an item. @@ -34,11 +33,13 @@ public interface ItemReadListener extends StepListener { void beforeRead(); /** - * Called after {@link ItemReader#read()} + * Called after {@link ItemReader#read()}. + * This method is called only for actual items (ie it is not called when the + * reader returns null). * * @param item returned from read() */ - void afterRead(@Nullable T item); + void afterRead(T item); /** * Called if an error occurs while trying to read. diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobKeyGenerator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobKeyGenerator.java index eede44288..61022dcd0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobKeyGenerator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobKeyGenerator.java @@ -15,8 +15,6 @@ */ package org.springframework.batch.core; -import org.springframework.lang.Nullable; - /** * Strategy interface for the generation of the key used in identifying * unique {@link JobInstance}. @@ -32,10 +30,10 @@ public interface JobKeyGenerator { /** * Method to generate the unique key used to identify a job instance. * - * @param source Source information used to generate the key (can be {@code null}) + * @param source Source information used to generate the key (must not be {@code null}) * * @return a unique string identifying the job based on the information * supplied */ - String generateKey(@Nullable T source); + String generateKey(T source); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/StepLocator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/StepLocator.java index e18d75592..b9196c0fc 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/StepLocator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/StepLocator.java @@ -1,5 +1,5 @@ /* - * Copyright 2009 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,17 +18,20 @@ package org.springframework.batch.core.step; import java.util.Collection; import org.springframework.batch.core.Step; +import org.springframework.lang.Nullable; /** * Interface for locating a {@link Step} instance by name. * * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public interface StepLocator { Collection getStepNames(); - - Step getStep(String stepName) throws NoSuchStepException; + + @Nullable + Step getStep(String stepName); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProcessor.java index 0e69f9a74..995598c48 100755 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import org.springframework.batch.core.listener.MulticasterBatchListener; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemWriter; import org.springframework.beans.factory.InitializingBean; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -42,19 +43,22 @@ public class SimpleChunkProcessor implements ChunkProcessor, Initializi private final MulticasterBatchListener listener = new MulticasterBatchListener(); /** - * Default constructor for ease of configuration (both itemWriter and - * itemProcessor are mandatory). + * Default constructor for ease of configuration. */ @SuppressWarnings("unused") private SimpleChunkProcessor() { this(null, null); } - public SimpleChunkProcessor(ItemProcessor itemProcessor, ItemWriter itemWriter) { + public SimpleChunkProcessor(@Nullable ItemProcessor itemProcessor, ItemWriter itemWriter) { this.itemProcessor = itemProcessor; this.itemWriter = itemWriter; } + public SimpleChunkProcessor(ItemWriter itemWriter) { + this(null, itemWriter); + } + /** * @param itemProcessor the {@link ItemProcessor} to set */ @@ -77,7 +81,6 @@ public class SimpleChunkProcessor implements ChunkProcessor, Initializi @Override public void afterPropertiesSet() throws Exception { Assert.notNull(itemWriter, "ItemWriter must be set"); - Assert.notNull(itemProcessor, "ItemProcessor must be set"); } /** diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/DefaultJobKeyGeneratorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/DefaultJobKeyGeneratorTests.java index b2b3c7cb8..00a184b3b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/DefaultJobKeyGeneratorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/DefaultJobKeyGeneratorTests.java @@ -29,6 +29,11 @@ public class DefaultJobKeyGeneratorTests { jobKeyGenerator = new DefaultJobKeyGenerator(); } + @Test(expected = IllegalArgumentException.class) + public void testNullParameters() { + jobKeyGenerator.generateKey(null); + } + @Test public void testMixedParameters() { JobParameters jobParameters1 = new JobParametersBuilder().addString(