Skip to content

Commit 276acd1

Browse files
fmbenhassinemminella
authored andcommitted
code review changes
1 parent 24b8d72 commit 276acd1

File tree

6 files changed

+30
-16
lines changed

6 files changed

+30
-16
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/DefaultJobKeyGenerator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2013 the original author or authors.
2+
* Copyright 2006-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,13 +24,16 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27+
import org.springframework.util.Assert;
28+
2729
/**
2830
* Default implementation of the {@link JobKeyGenerator} interface.
2931
* This implementation provides a single hash value based on the JobParameters
3032
* passed in. Only identifying parameters (per {@link JobParameter#isIdentifying()})
3133
* are used in the calculation of the key.
3234
*
3335
* @author Michael Minella
36+
* @author Mahmoud Ben Hassine
3437
* @since 2.2
3538
*/
3639
public class DefaultJobKeyGenerator implements JobKeyGenerator<JobParameters> {
@@ -42,6 +45,7 @@ public class DefaultJobKeyGenerator implements JobKeyGenerator<JobParameters> {
4245
@Override
4346
public String generateKey(JobParameters source) {
4447

48+
Assert.notNull(source, "source must not be null");
4549
Map<String, JobParameter> props = source.getParameters();
4650
StringBuilder stringBuffer = new StringBuilder();
4751
List<String> keys = new ArrayList<String>(props.keySet());

spring-batch-core/src/main/java/org/springframework/batch/core/ItemReadListener.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import org.springframework.batch.item.ItemReader;
1919
import org.springframework.batch.item.ItemWriter;
20-
import org.springframework.lang.Nullable;
2120

2221
/**
2322
* Listener interface around the reading of an item.
@@ -34,11 +33,13 @@ public interface ItemReadListener<T> extends StepListener {
3433
void beforeRead();
3534

3635
/**
37-
* Called after {@link ItemReader#read()}
36+
* Called after {@link ItemReader#read()}.
37+
* This method is called only for actual items (ie it is not called when the
38+
* reader returns null).
3839
*
3940
* @param item returned from read()
4041
*/
41-
void afterRead(@Nullable T item);
42+
void afterRead(T item);
4243

4344
/**
4445
* Called if an error occurs while trying to read.

spring-batch-core/src/main/java/org/springframework/batch/core/JobKeyGenerator.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.batch.core;
1717

18-
import org.springframework.lang.Nullable;
19-
2018
/**
2119
* Strategy interface for the generation of the key used in identifying
2220
* unique {@link JobInstance}.
@@ -32,10 +30,10 @@ public interface JobKeyGenerator<T> {
3230
/**
3331
* Method to generate the unique key used to identify a job instance.
3432
*
35-
* @param source Source information used to generate the key (can be {@code null})
33+
* @param source Source information used to generate the key (must not be {@code null})
3634
*
3735
* @return a unique string identifying the job based on the information
3836
* supplied
3937
*/
40-
String generateKey(@Nullable T source);
38+
String generateKey(T source);
4139
}

spring-batch-core/src/main/java/org/springframework/batch/core/step/StepLocator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,17 +18,20 @@
1818
import java.util.Collection;
1919

2020
import org.springframework.batch.core.Step;
21+
import org.springframework.lang.Nullable;
2122

2223
/**
2324
* Interface for locating a {@link Step} instance by name.
2425
*
2526
* @author Dave Syer
27+
* @author Mahmoud Ben Hassine
2628
*
2729
*/
2830
public interface StepLocator {
2931

3032
Collection<String> getStepNames();
31-
32-
Step getStep(String stepName) throws NoSuchStepException;
33+
34+
@Nullable
35+
Step getStep(String stepName);
3336

3437
}

spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProcessor.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2013 the original author or authors.
2+
* Copyright 2006-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
import org.springframework.batch.item.ItemProcessor;
2525
import org.springframework.batch.item.ItemWriter;
2626
import org.springframework.beans.factory.InitializingBean;
27+
import org.springframework.lang.Nullable;
2728
import org.springframework.util.Assert;
2829

2930
/**
@@ -42,19 +43,22 @@ public class SimpleChunkProcessor<I, O> implements ChunkProcessor<I>, Initializi
4243
private final MulticasterBatchListener<I, O> listener = new MulticasterBatchListener<I, O>();
4344

4445
/**
45-
* Default constructor for ease of configuration (both itemWriter and
46-
* itemProcessor are mandatory).
46+
* Default constructor for ease of configuration.
4747
*/
4848
@SuppressWarnings("unused")
4949
private SimpleChunkProcessor() {
5050
this(null, null);
5151
}
5252

53-
public SimpleChunkProcessor(ItemProcessor<? super I, ? extends O> itemProcessor, ItemWriter<? super O> itemWriter) {
53+
public SimpleChunkProcessor(@Nullable ItemProcessor<? super I, ? extends O> itemProcessor, ItemWriter<? super O> itemWriter) {
5454
this.itemProcessor = itemProcessor;
5555
this.itemWriter = itemWriter;
5656
}
5757

58+
public SimpleChunkProcessor(ItemWriter<? super O> itemWriter) {
59+
this(null, itemWriter);
60+
}
61+
5862
/**
5963
* @param itemProcessor the {@link ItemProcessor} to set
6064
*/
@@ -77,7 +81,6 @@ public void setItemWriter(ItemWriter<? super O> itemWriter) {
7781
@Override
7882
public void afterPropertiesSet() throws Exception {
7983
Assert.notNull(itemWriter, "ItemWriter must be set");
80-
Assert.notNull(itemProcessor, "ItemProcessor must be set");
8184
}
8285

8386
/**

spring-batch-core/src/test/java/org/springframework/batch/core/DefaultJobKeyGeneratorTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public void setUp() throws Exception {
2929
jobKeyGenerator = new DefaultJobKeyGenerator();
3030
}
3131

32+
@Test(expected = IllegalArgumentException.class)
33+
public void testNullParameters() {
34+
jobKeyGenerator.generateKey(null);
35+
}
36+
3237
@Test
3338
public void testMixedParameters() {
3439
JobParameters jobParameters1 = new JobParametersBuilder().addString(

0 commit comments

Comments
 (0)