Skip to content

Commit fc0ec01

Browse files
danilopiazzafmbenhassine
authored andcommitted
Throw IllegalStateException from afterPropertiesSet
Consistently use Assert.state in the afterPropertiesSet() methods to throw IllegalStateException instead of IllegalArgumentException when some properties are missing and/or invalid. Resolves #2244
1 parent b9d6e26 commit fc0ec01

File tree

96 files changed

+188
-178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+188
-178
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultJobLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private void doUnregister(String jobName) {
278278

279279
@Override
280280
public void afterPropertiesSet() {
281-
Assert.notNull(jobRegistry, "Job registry could not be null.");
281+
Assert.state(jobRegistry != null, "Job registry could not be null.");
282282
}
283283

284284
}

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
9898
*/
9999
@Override
100100
public void afterPropertiesSet() throws Exception {
101-
Assert.notNull(jobRegistry, "JobRegistry must not be null");
101+
Assert.state(jobRegistry != null, "JobRegistry must not be null");
102102
}
103103

104104
/**

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/SimpleFlowFactoryBean.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.beans.factory.FactoryBean;
3434
import org.springframework.beans.factory.InitializingBean;
3535
import org.springframework.util.Assert;
36+
import org.springframework.util.StringUtils;
3637

3738
/**
3839
* Convenience factory for {@link SimpleFlow} instances for use in the XML namespace. It
@@ -94,7 +95,7 @@ public void setStateTransitions(List<StateTransition> stateTransitions) {
9495
*/
9596
@Override
9697
public void afterPropertiesSet() throws Exception {
97-
Assert.hasText(name, "The flow must have a name");
98+
Assert.state(StringUtils.hasText(name), "The flow must have a name");
9899

99100
if (flowType == null) {
100101
flowType = SimpleFlow.class;

spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void setConversionService(@NonNull ConfigurableConversionService conversi
153153
@Override
154154
public void afterPropertiesSet() throws Exception {
155155

156-
Assert.notNull(dataSource, "DataSource must not be null.");
156+
Assert.state(dataSource != null, "DataSource must not be null.");
157157

158158
if (jdbcOperations == null) {
159159
jdbcOperations = new JdbcTemplate(dataSource);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void setJobParametersValidator(JobParametersValidator jobParametersValida
128128
*/
129129
@Override
130130
public void afterPropertiesSet() throws Exception {
131-
Assert.notNull(jobRepository, "JobRepository must be set");
131+
Assert.state(jobRepository != null, "JobRepository must be set");
132132
}
133133

134134
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2018 the original author or authors.
2+
* Copyright 2011-2022 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.
@@ -60,8 +60,8 @@ public void setValidators(List<JobParametersValidator> validators) {
6060

6161
@Override
6262
public void afterPropertiesSet() throws Exception {
63-
Assert.notNull(validators, "The 'validators' may not be null");
64-
Assert.notEmpty(validators, "The 'validators' may not be empty");
63+
Assert.state(validators != null, "The 'validators' may not be null");
64+
Assert.state(!validators.isEmpty(), "The 'validators' may not be empty");
6565
}
6666

6767
}

spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ public class SimpleJobOperator implements JobOperator, InitializingBean {
110110
*/
111111
@Override
112112
public void afterPropertiesSet() throws Exception {
113-
Assert.notNull(jobLauncher, "JobLauncher must be provided");
114-
Assert.notNull(jobRegistry, "JobLocator must be provided");
115-
Assert.notNull(jobExplorer, "JobExplorer must be provided");
116-
Assert.notNull(jobRepository, "JobRepository must be provided");
113+
Assert.state(jobLauncher != null, "JobLauncher must be provided");
114+
Assert.state(jobRegistry != null, "JobLocator must be provided");
115+
Assert.state(jobExplorer != null, "JobExplorer must be provided");
116+
Assert.state(jobRepository != null, "JobRepository must be provided");
117117
}
118118

119119
/**

spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -196,7 +196,7 @@ public void setMetaDataMap(Map<String, String> metaDataMap) {
196196

197197
@Override
198198
public void afterPropertiesSet() throws Exception {
199-
Assert.notNull(delegate, "Delegate must not be null");
199+
Assert.state(delegate != null, "Delegate must not be null");
200200
}
201201

202202
/**

spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -25,6 +25,7 @@
2525
import org.springframework.beans.factory.InitializingBean;
2626
import org.springframework.lang.Nullable;
2727
import org.springframework.util.Assert;
28+
import org.springframework.util.ObjectUtils;
2829

2930
/**
3031
* This class can be used to automatically promote items from the {@link Step}
@@ -77,10 +78,10 @@ public ExitStatus afterStep(StepExecution stepExecution) {
7778

7879
@Override
7980
public void afterPropertiesSet() throws Exception {
80-
Assert.notNull(this.keys, "The 'keys' property must be provided");
81-
Assert.notEmpty(this.keys, "The 'keys' property must not be empty");
82-
Assert.notNull(this.statuses, "The 'statuses' property must be provided");
83-
Assert.notEmpty(this.statuses, "The 'statuses' property must not be empty");
81+
Assert.state(this.keys != null, "The 'keys' property must be provided");
82+
Assert.state(!ObjectUtils.isEmpty(this.keys), "The 'keys' property must not be empty");
83+
Assert.state(this.statuses != null, "The 'statuses' property must be provided");
84+
Assert.state(!ObjectUtils.isEmpty(this.statuses), "The 'statuses' property must not be empty");
8485
}
8586

8687
/**

spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -78,8 +78,8 @@ public void setStepExecutionSplitter(StepExecutionSplitter stepExecutionSplitter
7878
*/
7979
@Override
8080
public void afterPropertiesSet() throws Exception {
81-
Assert.notNull(stepExecutionSplitter, "StepExecutionSplitter must be provided");
82-
Assert.notNull(partitionHandler, "PartitionHandler must be provided");
81+
Assert.state(stepExecutionSplitter != null, "StepExecutionSplitter must be provided");
82+
Assert.state(partitionHandler != null, "PartitionHandler must be provided");
8383
super.afterPropertiesSet();
8484
}
8585

0 commit comments

Comments
 (0)