Skip to content

Commit d6ce9f6

Browse files
authored
Fix JobParameter validation bug in compact constructor
Resolves #5050 Signed-off-by: mugeon <pos04167@kakao.com>
1 parent b848638 commit d6ce9f6

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/job/parameters/JobParameter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public record JobParameter<T>(String name, T value, Class<T> type, boolean ident
4747
* @since 6.0
4848
*/
4949
public JobParameter {
50-
Assert.notNull(value, "name must not be null");
50+
Assert.notNull(name, "name must not be null");
5151
Assert.notNull(value, "value must not be null");
5252
Assert.notNull(type, "type must not be null");
5353
}

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,42 @@
1515
*/
1616
package org.springframework.batch.core;
1717

18-
import static org.junit.jupiter.api.Assertions.assertEquals;
19-
import static org.junit.jupiter.api.Assertions.assertTrue;
20-
2118
import java.util.Date;
2219

2320
import org.junit.jupiter.api.Test;
2421

2522
import org.springframework.batch.core.job.parameters.JobParameter;
2623

24+
import static org.junit.jupiter.api.Assertions.*;
25+
2726
/**
2827
* @author Lucas Ward
2928
* @author Mahmoud Ben Hassine
3029
*
3130
*/
3231
class JobParameterTests {
3332

33+
@Test
34+
void testConstructorNameNotNull() {
35+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
36+
() -> new JobParameter<>(null, "test", String.class, true));
37+
assertEquals("name must not be null", exception.getMessage());
38+
}
39+
40+
@Test
41+
void testConstructorValueNotNull() {
42+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
43+
() -> new JobParameter<>("param", null, String.class, true));
44+
assertEquals("value must not be null", exception.getMessage());
45+
}
46+
47+
@Test
48+
void testConstructorTypeNotNull() {
49+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
50+
() -> new JobParameter<>("param", "test", null, true));
51+
assertEquals("type must not be null", exception.getMessage());
52+
}
53+
3454
@Test
3555
void testStringParameter() {
3656
JobParameter<String> jobParameter = new JobParameter<>("param", "test", String.class, true);

0 commit comments

Comments
 (0)