diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultJobLoader.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultJobLoader.java index a8e7af03ce..652bafc2dd 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultJobLoader.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultJobLoader.java @@ -278,7 +278,7 @@ private void doUnregister(String jobName) { @Override public void afterPropertiesSet() { - Assert.notNull(jobRegistry, "Job registry could not be null."); + Assert.state(jobRegistry != null, "Job registry could not be null."); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java index 6bcb32b0e0..d62a8c1241 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java @@ -98,7 +98,7 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(jobRegistry, "JobRegistry must not be null"); + Assert.state(jobRegistry != null, "JobRegistry must not be null"); } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/SimpleFlowFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/SimpleFlowFactoryBean.java index 8e383e6956..37e7a05ee9 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/SimpleFlowFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/SimpleFlowFactoryBean.java @@ -33,6 +33,7 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * Convenience factory for {@link SimpleFlow} instances for use in the XML namespace. It @@ -94,7 +95,7 @@ public void setStateTransitions(List stateTransitions) { */ @Override public void afterPropertiesSet() throws Exception { - Assert.hasText(name, "The flow must have a name"); + Assert.state(StringUtils.hasText(name), "The flow must have a name"); if (flowType == null) { flowType = SimpleFlow.class; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java index fe3c5b9f94..36553fe50e 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java @@ -153,7 +153,7 @@ public void setConversionService(@NonNull ConfigurableConversionService conversi @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource, "DataSource must not be null."); + Assert.state(dataSource != null, "DataSource must not be null."); if (jdbcOperations == null) { jdbcOperations = new JdbcTemplate(dataSource); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java index 2d69bc9c61..b125f09820 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java @@ -128,7 +128,7 @@ public void setJobParametersValidator(JobParametersValidator jobParametersValida */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(jobRepository, "JobRepository must be set"); + Assert.state(jobRepository != null, "JobRepository must be set"); } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/CompositeJobParametersValidator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/CompositeJobParametersValidator.java index 86ba78749d..8ed88989d9 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/CompositeJobParametersValidator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/CompositeJobParametersValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 the original author or authors. + * Copyright 2011-2022 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. @@ -60,8 +60,8 @@ public void setValidators(List validators) { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(validators, "The 'validators' may not be null"); - Assert.notEmpty(validators, "The 'validators' may not be empty"); + Assert.state(validators != null, "The 'validators' may not be null"); + Assert.state(!validators.isEmpty(), "The 'validators' may not be empty"); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java index 47f98cdef6..ca67fa9aa5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java @@ -110,10 +110,10 @@ public class SimpleJobOperator implements JobOperator, InitializingBean { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(jobLauncher, "JobLauncher must be provided"); - Assert.notNull(jobRegistry, "JobLocator must be provided"); - Assert.notNull(jobExplorer, "JobExplorer must be provided"); - Assert.notNull(jobRepository, "JobRepository must be provided"); + Assert.state(jobLauncher != null, "JobLauncher must be provided"); + Assert.state(jobRegistry != null, "JobLocator must be provided"); + Assert.state(jobExplorer != null, "JobExplorer must be provided"); + Assert.state(jobRepository != null, "JobRepository must be provided"); } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java index 83b56eb29d..c4b6bd9f7c 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/AbstractListenerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2022 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. @@ -196,7 +196,7 @@ public void setMetaDataMap(Map metaDataMap) { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(delegate, "Delegate must not be null"); + Assert.state(delegate != null, "Delegate must not be null"); } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java index 3d70205cba..4abfa685c7 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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. @@ -25,6 +25,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; /** * This class can be used to automatically promote items from the {@link Step} @@ -77,10 +78,10 @@ public ExitStatus afterStep(StepExecution stepExecution) { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(this.keys, "The 'keys' property must be provided"); - Assert.notEmpty(this.keys, "The 'keys' property must not be empty"); - Assert.notNull(this.statuses, "The 'statuses' property must be provided"); - Assert.notEmpty(this.statuses, "The 'statuses' property must not be empty"); + Assert.state(this.keys != null, "The 'keys' property must be provided"); + Assert.state(!ObjectUtils.isEmpty(this.keys), "The 'keys' property must not be empty"); + Assert.state(this.statuses != null, "The 'statuses' property must be provided"); + Assert.state(!ObjectUtils.isEmpty(this.statuses), "The 'statuses' property must not be empty"); } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java index f5d926ed56..2b84033c87 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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. @@ -78,8 +78,8 @@ public void setStepExecutionSplitter(StepExecutionSplitter stepExecutionSplitter */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(stepExecutionSplitter, "StepExecutionSplitter must be provided"); - Assert.notNull(partitionHandler, "PartitionHandler must be provided"); + Assert.state(stepExecutionSplitter != null, "StepExecutionSplitter must be provided"); + Assert.state(partitionHandler != null, "PartitionHandler must be provided"); super.afterPropertiesSet(); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java index 57c48811c9..aac208e4aa 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2022 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. @@ -79,7 +79,7 @@ public void setClobTypeToUse(int clobTypeToUse) { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(jdbcTemplate, "JdbcOperations is required"); + Assert.state(jdbcTemplate != null, "JdbcOperations is required"); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java index 207f3e6eef..ea4ae20877 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java @@ -138,7 +138,7 @@ public void setConversionService(@NonNull ConfigurableConversionService conversi @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); - Assert.notNull(jobExecutionIncrementer, "The jobExecutionIncrementer must not be null."); + Assert.state(jobExecutionIncrementer != null, "The jobExecutionIncrementer must not be null."); } @Override diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java index 79aa8e66ef..78cee51e72 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java @@ -311,7 +311,7 @@ public void setJobInstanceIncrementer(DataFieldMaxValueIncrementer jobInstanceIn @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); - Assert.notNull(jobInstanceIncrementer, "jobInstanceIncrementer is required"); + Assert.state(jobInstanceIncrementer != null, "jobInstanceIncrementer is required"); } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java index 66bab0fad9..ec001f3758 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java @@ -129,7 +129,7 @@ public void setStepExecutionIncrementer(DataFieldMaxValueIncrementer stepExecuti @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); - Assert.notNull(stepExecutionIncrementer, "StepExecutionIncrementer cannot be null."); + Assert.state(stepExecutionIncrementer != null, "StepExecutionIncrementer cannot be null."); } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java index 7369596311..84e97d0aeb 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java @@ -178,7 +178,7 @@ public void setTransactionAttributeSource(TransactionAttributeSource transaction @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(transactionManager, "TransactionManager must not be null."); + Assert.state(transactionManager != null, "TransactionManager must not be null."); if (this.transactionAttributeSource == null) { Properties transactionAttributes = new Properties(); transactionAttributes.setProperty("create*", diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java index 9e25453575..480028d585 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java @@ -199,7 +199,7 @@ public void setConversionService(@NonNull ConfigurableConversionService conversi @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource, "DataSource must not be null."); + Assert.state(dataSource != null, "DataSource must not be null."); if (jdbcOperations == null) { jdbcOperations = new JdbcTemplate(dataSource); @@ -226,12 +226,12 @@ public void afterPropertiesSet() throws Exception { serializer = defaultSerializer; } - Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), + Assert.state(incrementerFactory.isSupportedIncrementerType(databaseType), () -> "'" + databaseType + "' is an unsupported database type. The supported database types are " + StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes())); if (clobType != null) { - Assert.isTrue(isValidTypes(clobType), "lobType must be a value from the java.sql.Types class"); + Assert.state(isValidTypes(clobType), "lobType must be a value from the java.sql.Types class"); } if (this.conversionService == null) { 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 fddf2fbe33..813b6eb403 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 @@ -99,7 +99,7 @@ public void setMeterRegistry(MeterRegistry meterRegistry) { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(itemWriter, "ItemWriter must be set"); + Assert.state(itemWriter != null, "ItemWriter must be set"); } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapter.java index 120ea42c68..ccdf997917 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2022 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. @@ -49,7 +49,7 @@ public void setCallable(Callable callable) { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(callable, "A Callable is required"); + Assert.state(callable != null, "A Callable is required"); } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java index cd1ceb8199..9dedb00f3a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java @@ -37,6 +37,8 @@ import org.springframework.core.task.TaskExecutor; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; /** * {@link Tasklet} that executes a system command. @@ -190,14 +192,13 @@ public void setWorkingDirectory(String dir) { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(commandRunner, "CommandRunner must be set"); - Assert.notNull(cmdArray, "'cmdArray' property value must not be null"); - Assert.notEmpty(cmdArray, "'cmdArray' property value is required with at least 1 element"); - Assert.noNullElements(cmdArray, "'cmdArray' property value must not contain be null elements"); - Assert.hasLength(cmdArray[0], "'cmdArray' property value is required with at least 1 element"); - Assert.notNull(systemProcessExitCodeMapper, "SystemProcessExitCodeMapper must be set"); - Assert.isTrue(timeout > 0, "timeout value must be greater than zero"); - Assert.notNull(taskExecutor, "taskExecutor is required"); + Assert.state(commandRunner != null, "CommandRunner must be set"); + Assert.state(cmdArray != null, "'cmdArray' property value must not be null"); + Assert.state(!ObjectUtils.isEmpty(cmdArray), "'cmdArray' property value is required with at least 1 element"); + Assert.state(StringUtils.hasText(cmdArray[0]), "'cmdArray' property value is required with at least 1 element"); + Assert.state(systemProcessExitCodeMapper != null, "SystemProcessExitCodeMapper must be set"); + Assert.state(timeout > 0, "timeout value must be greater than zero"); + Assert.state(taskExecutor != null, "taskExecutor is required"); stoppable = jobExplorer != null; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessorTests.java index 923ac92bbe..6a1a495b53 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessorTests.java @@ -38,7 +38,7 @@ class JobRegistryBeanPostProcessorTests { @Test void testInitializationFails() { - Exception exception = assertThrows(IllegalArgumentException.class, processor::afterPropertiesSet); + Exception exception = assertThrows(IllegalStateException.class, processor::afterPropertiesSet); assertTrue(exception.getMessage().contains("JobRegistry")); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBeanTests.java index e081f0fa51..48a26cef3e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBeanTests.java @@ -84,7 +84,7 @@ void testCustomJdbcOperations() throws Exception { void testMissingDataSource() { factory.setDataSource(null); - Exception exception = assertThrows(IllegalArgumentException.class, factory::afterPropertiesSet); + Exception exception = assertThrows(IllegalStateException.class, factory::afterPropertiesSet); String message = exception.getMessage(); assertTrue(message.contains("DataSource"), "Wrong message: " + message); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/CompositeJobParametersValidatorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/CompositeJobParametersValidatorTests.java index 8d1274b525..767df315e3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/CompositeJobParametersValidatorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/CompositeJobParametersValidatorTests.java @@ -41,13 +41,13 @@ void setUp() { @Test void testValidatorsCanNotBeNull() { compositeJobParametersValidator.setValidators(null); - assertThrows(IllegalArgumentException.class, compositeJobParametersValidator::afterPropertiesSet); + assertThrows(IllegalStateException.class, compositeJobParametersValidator::afterPropertiesSet); } @Test void testValidatorsCanNotBeEmpty() { compositeJobParametersValidator.setValidators(new ArrayList<>()); - assertThrows(IllegalArgumentException.class, compositeJobParametersValidator::afterPropertiesSet); + assertThrows(IllegalStateException.class, compositeJobParametersValidator::afterPropertiesSet); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java index 6742b4024b..163a6545c5 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java @@ -120,7 +120,7 @@ void testToString() { @Test void testAfterPropertiesSet() { job.setJobRepository(null); - Exception exception = assertThrows(IllegalArgumentException.class, () -> job.afterPropertiesSet()); + Exception exception = assertThrows(IllegalStateException.class, () -> job.afterPropertiesSet()); assertTrue(exception.getMessage().contains("JobRepository")); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java index 7c230b0ab5..c8fe49f83a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java @@ -141,7 +141,7 @@ public Properties getProperties(@Nullable JobParameters params) { @Test void testMandatoryProperties() { jobOperator = new SimpleJobOperator(); - assertThrows(IllegalArgumentException.class, jobOperator::afterPropertiesSet); + assertThrows(IllegalStateException.class, jobOperator::afterPropertiesSet); } /** diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java index 10621d5cc8..7544e0c144 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java @@ -247,7 +247,7 @@ void promoteEntriesKeyNotFoundStrict() throws Exception { void keysMustBeSet() { ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener(); // didn't set the keys, same as listener.setKeys(null); - assertThrows(IllegalArgumentException.class, listener::afterPropertiesSet); + assertThrows(IllegalStateException.class, listener::afterPropertiesSet); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBeanTests.java index f3d439e1cb..425da4ba62 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBeanTests.java @@ -241,7 +241,7 @@ void testCustomJdbcOperations() throws Exception { void testMissingDataSource() { factory.setDataSource(null); - Exception exception = assertThrows(IllegalArgumentException.class, factory::afterPropertiesSet); + Exception exception = assertThrows(IllegalStateException.class, factory::afterPropertiesSet); String message = exception.getMessage(); assertTrue(message.contains("DataSource"), "Wrong message: " + message); @@ -255,7 +255,7 @@ void testMissingTransactionManager() { when(incrementerFactory.isSupportedIncrementerType("mockDb")).thenReturn(true); when(incrementerFactory.getSupportedIncrementerTypes()).thenReturn(new String[0]); - Exception exception = assertThrows(IllegalArgumentException.class, () -> factory.afterPropertiesSet()); + Exception exception = assertThrows(IllegalStateException.class, () -> factory.afterPropertiesSet()); String message = exception.getMessage(); assertTrue(message.contains("TransactionManager"), "Wrong message: " + message); @@ -268,7 +268,7 @@ void testInvalidDatabaseType() { when(incrementerFactory.isSupportedIncrementerType("foo")).thenReturn(false); when(incrementerFactory.getSupportedIncrementerTypes()).thenReturn(new String[0]); - Exception exception = assertThrows(IllegalArgumentException.class, () -> factory.afterPropertiesSet()); + Exception exception = assertThrows(IllegalStateException.class, () -> factory.afterPropertiesSet()); String message = exception.getMessage(); assertTrue(message.contains("foo"), "Wrong message: " + message); @@ -363,7 +363,7 @@ public void testCustomTransactionAttributesSource() throws Exception { @Test void testInvalidCustomLobType() { factory.setClobType(Integer.MAX_VALUE); - assertThrows(IllegalArgumentException.class, this::testCreateRepository); + assertThrows(IllegalStateException.class, this::testCreateRepository); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapterTests.java index 8d4773cda5..3792b17a32 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapterTests.java @@ -40,7 +40,7 @@ public RepeatStatus call() throws Exception { @Test void testAfterPropertiesSet() { - assertThrows(IllegalArgumentException.class, adapter::afterPropertiesSet); + assertThrows(IllegalStateException.class, adapter::afterPropertiesSet); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java index 185de0f20c..08ceb3f7af 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java @@ -187,7 +187,7 @@ void testInterruption() throws Exception { @Test public void testCommandRunnerNotSet() throws Exception { tasklet.setCommandRunner(null); - assertThrows(IllegalArgumentException.class, tasklet::afterPropertiesSet); + assertThrows(IllegalStateException.class, tasklet::afterPropertiesSet); } /* @@ -196,10 +196,10 @@ public void testCommandRunnerNotSet() throws Exception { @Test void testCommandNotSet() { tasklet.setCommand(null); - assertThrows(IllegalArgumentException.class, tasklet::afterPropertiesSet); + assertThrows(IllegalStateException.class, tasklet::afterPropertiesSet); tasklet.setCommand(""); - assertThrows(IllegalArgumentException.class, tasklet::afterPropertiesSet); + assertThrows(IllegalStateException.class, tasklet::afterPropertiesSet); } /* @@ -209,7 +209,7 @@ void testCommandNotSet() { void testTimeoutNotSet() { tasklet.setCommand("not-empty placeholder"); tasklet.setTimeout(0); - assertThrows(IllegalArgumentException.class, tasklet::afterPropertiesSet); + assertThrows(IllegalStateException.class, tasklet::afterPropertiesSet); } /* diff --git a/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java index 7faa3f67f7..0a344cb8b0 100644 --- a/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ b/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java @@ -76,7 +76,7 @@ public static void main(String... args) { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource, "A DataSource is required"); + Assert.state(dataSource != null, "A DataSource is required"); initialize(); } diff --git a/spring-batch-docs/src/main/asciidoc/step.adoc b/spring-batch-docs/src/main/asciidoc/step.adoc index 6b92c7c9f1..dc78f7746a 100644 --- a/spring-batch-docs/src/main/asciidoc/step.adoc +++ b/spring-batch-docs/src/main/asciidoc/step.adoc @@ -1397,7 +1397,7 @@ public class FileDeletingTasklet implements Tasklet, InitializingBean { } public void afterPropertiesSet() throws Exception { - Assert.notNull(directory, "directory must be set"); + Assert.state(directory != null, "directory must be set"); } } ---- diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/KeyValueItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/KeyValueItemWriter.java index 1b5997f138..16fabe8830 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/KeyValueItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/KeyValueItemWriter.java @@ -93,7 +93,7 @@ public void setDelete(boolean delete) { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(itemKeyMapper, "itemKeyMapper requires a Converter type."); + Assert.state(itemKeyMapper != null, "itemKeyMapper requires a Converter type."); init(); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java index 3152a65467..fc96aa5218 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 the original author or authors. + * Copyright 2006-2022 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. @@ -26,6 +26,7 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.MethodInvoker; +import org.springframework.util.StringUtils; /** * Superclass for delegating classes which dynamically call a custom method of injected @@ -126,8 +127,8 @@ private T doInvoke(MethodInvoker invoker) throws Exception { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(targetObject, "targetObject must not be null"); - Assert.hasLength(targetMethod, "targetMethod must not be empty"); + Assert.state(targetObject != null, "targetObject must not be null"); + Assert.state(StringUtils.hasText(targetMethod), "targetMethod must not be empty"); Assert.state(targetClassDeclaresTargetMethod(), "target class must declare a method with matching name and parameter types"); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java index 609d6f3d08..8c817ab458 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java @@ -24,6 +24,7 @@ import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; /** * Delegates processing to a custom method - extracts property values from item object and @@ -62,7 +63,8 @@ public void write(Chunk items) throws Exception { @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); - Assert.notEmpty(fieldsUsedAsTargetMethodArguments, "fieldsUsedAsTargetMethodArguments must not be empty"); + Assert.state(!ObjectUtils.isEmpty(fieldsUsedAsTargetMethodArguments), + "fieldsUsedAsTargetMethodArguments must not be empty"); } /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemWriter.java index 4ce7c96e43..b5f9543e28 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemWriter.java @@ -30,6 +30,7 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MethodInvoker; +import org.springframework.util.StringUtils; /** *

@@ -129,7 +130,7 @@ protected void doWrite(Chunk items) throws Exception { public void afterPropertiesSet() throws Exception { Assert.state(repository != null, "A CrudRepository implementation is required"); if (this.methodName != null) { - Assert.hasText(this.methodName, "methodName must not be empty."); + Assert.state(StringUtils.hasText(this.methodName), "methodName must not be empty."); } else { logger.debug("No method name provided, CrudRepository.saveAll will be used."); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractCursorItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractCursorItemReader.java index e3bd731fba..a926bb3d75 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractCursorItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractCursorItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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. @@ -154,7 +154,7 @@ public AbstractCursorItemReader() { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource, "DataSource must be provided"); + Assert.state(dataSource != null, "DataSource must be provided"); } /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractPagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractPagingItemReader.java index 0ede0eb5dd..e2cb8f6e9e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractPagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractPagingItemReader.java @@ -91,7 +91,7 @@ public void setPageSize(int pageSize) { */ @Override public void afterPropertiesSet() throws Exception { - Assert.isTrue(pageSize > 0, "pageSize must be greater than zero"); + Assert.state(pageSize > 0, "pageSize must be greater than zero"); } @Nullable diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxy.java index e79a4b01e0..972cbb2977 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -316,7 +316,7 @@ else if (iface.isAssignableFrom(dataSource.getClass())) { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource, "DataSource is required"); + Assert.state(dataSource != null, "DataSource is required"); } /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemReaderHelper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemReaderHelper.java index fc4faef6ec..6911572c44 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemReaderHelper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemReaderHelper.java @@ -101,7 +101,7 @@ public void afterPropertiesSet() throws Exception { Assert.state(sessionFactory != null, "A SessionFactory must be provided"); if (queryProvider == null) { - Assert.notNull(sessionFactory, "session factory must be set"); + Assert.state(sessionFactory != null, "session factory must be set"); Assert.state(StringUtils.hasText(queryString) ^ StringUtils.hasText(queryName), "queryString or queryName must be set"); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java index 8b0a6a7645..290ee6ef8b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java @@ -142,8 +142,8 @@ public void setJdbcTemplate(NamedParameterJdbcOperations namedParameterJdbcTempl */ @Override public void afterPropertiesSet() { - Assert.notNull(namedParameterJdbcTemplate, "A DataSource or a NamedParameterJdbcTemplate is required."); - Assert.notNull(sql, "An SQL statement is required."); + Assert.state(namedParameterJdbcTemplate != null, "A DataSource or a NamedParameterJdbcTemplate is required."); + Assert.state(sql != null, "An SQL statement is required."); List namedParameters = new ArrayList<>(); parameterCount = JdbcParameterUtils.countParameterPlaceholders(sql, namedParameters); if (namedParameters.size() > 0) { @@ -154,7 +154,7 @@ public void afterPropertiesSet() { usingNamedParameters = true; } if (!usingNamedParameters) { - Assert.notNull(itemPreparedStatementSetter, + Assert.state(itemPreparedStatementSetter != null, "Using SQL statement with '?' placeholders requires an ItemPreparedStatementSetter"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcCursorItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcCursorItemReader.java index 8443125769..c8d3717de4 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcCursorItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcCursorItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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. @@ -103,8 +103,8 @@ public void setPreparedStatementSetter(PreparedStatementSetter preparedStatement @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); - Assert.notNull(sql, "The SQL query must be provided"); - Assert.notNull(rowMapper, "RowMapper must be provided"); + Assert.state(sql != null, "The SQL query must be provided"); + Assert.state(rowMapper != null, "RowMapper must be provided"); } @Override diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java index c5fd0cfc93..0d484f2c45 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java @@ -155,14 +155,14 @@ public void setParameterValues(Map parameterValues) { @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); - Assert.notNull(dataSource, "DataSource may not be null"); + Assert.state(dataSource != null, "DataSource may not be null"); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); if (fetchSize != VALUE_NOT_SET) { jdbcTemplate.setFetchSize(fetchSize); } jdbcTemplate.setMaxRows(getPageSize()); namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); - Assert.notNull(queryProvider, "QueryProvider may not be null"); + Assert.state(queryProvider != null, "QueryProvider may not be null"); queryProvider.init(dataSource); this.firstPageSql = queryProvider.generateFirstPageQuery(getPageSize()); this.remainingPagesSql = queryProvider.generateRemainingPagesQuery(getPageSize()); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaCursorItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaCursorItemReader.java index 8b31239e4a..4dbae53614 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaCursorItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaCursorItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2022 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. @@ -30,6 +30,7 @@ import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.StringUtils; /** * {@link org.springframework.batch.item.ItemStreamReader} implementation based on JPA @@ -101,9 +102,10 @@ public void setParameterValues(Map parameterValues) { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(this.entityManagerFactory, "EntityManagerFactory is required"); + Assert.state(this.entityManagerFactory != null, "EntityManagerFactory is required"); if (this.queryProvider == null) { - Assert.hasLength(this.queryString, "Query string is required when queryProvider is null"); + Assert.state(StringUtils.hasLength(this.queryString), + "Query string is required when queryProvider is null"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaItemWriter.java index d526af59a5..70fd6ec8b5 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaItemWriter.java @@ -75,7 +75,7 @@ public void setUsePersist(boolean usePersist) { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(entityManagerFactory, "An EntityManagerFactory is required"); + Assert.state(entityManagerFactory != null, "An EntityManagerFactory is required"); } /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaPagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaPagingItemReader.java index 47ff7d211b..1d33e9a6f8 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaPagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaPagingItemReader.java @@ -31,6 +31,7 @@ import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.StringUtils; /** *

@@ -144,8 +145,8 @@ public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); if (queryProvider == null) { - Assert.notNull(entityManagerFactory, "EntityManager is required when queryProvider is null"); - Assert.hasLength(queryString, "Query string is required when queryProvider is null"); + Assert.state(entityManagerFactory != null, "EntityManager is required when queryProvider is null"); + Assert.state(StringUtils.hasLength(queryString), "Query string is required when queryProvider is null"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/StoredProcedureItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/StoredProcedureItemReader.java index 73a7ccddf3..d6f74827ae 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/StoredProcedureItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/StoredProcedureItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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. @@ -143,8 +143,8 @@ public void setRefCursorPosition(int refCursorPosition) { @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); - Assert.notNull(procedureName, "The name of the stored procedure must be provided"); - Assert.notNull(rowMapper, "RowMapper must be provided"); + Assert.state(procedureName != null, "The name of the stored procedure must be provided"); + Assert.state(rowMapper != null, "RowMapper must be provided"); } @Override diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/HibernateNativeQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/HibernateNativeQueryProvider.java index e02495d3a0..c2bd2a9a0e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/HibernateNativeQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/HibernateNativeQueryProvider.java @@ -69,8 +69,8 @@ public void setEntityClass(Class entityClazz) { } public void afterPropertiesSet() throws Exception { - Assert.isTrue(StringUtils.hasText(sqlQuery), "Native SQL query cannot be empty"); - Assert.notNull(entityClass, "Entity class cannot be NULL"); + Assert.state(StringUtils.hasText(sqlQuery), "Native SQL query cannot be empty"); + Assert.state(entityClass != null, "Entity class cannot be NULL"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/JpaNamedQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/JpaNamedQueryProvider.java index dc4ea290ba..da2bae86f5 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/JpaNamedQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/JpaNamedQueryProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2022 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. @@ -57,8 +57,8 @@ public void setEntityClass(Class entityClazz) { @Override public void afterPropertiesSet() throws Exception { - Assert.isTrue(StringUtils.hasText(this.namedQuery), "Named query cannot be empty"); - Assert.notNull(this.entityClass, "Entity class cannot be NULL"); + Assert.state(StringUtils.hasText(this.namedQuery), "Named query cannot be empty"); + Assert.state(this.entityClass != null, "Entity class cannot be NULL"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/JpaNativeQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/JpaNativeQueryProvider.java index 9dbf9d5cac..8ed7421217 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/JpaNativeQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/orm/JpaNativeQueryProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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. @@ -53,8 +53,8 @@ public void setEntityClass(Class entityClazz) { @Override public void afterPropertiesSet() throws Exception { - Assert.isTrue(StringUtils.hasText(sqlQuery), "Native SQL query cannot be empty"); - Assert.notNull(entityClass, "Entity class cannot be NULL"); + Assert.state(StringUtils.hasText(sqlQuery), "Native SQL query cannot be empty"); + Assert.state(entityClass != null, "Entity class cannot be NULL"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java index 34545fc579..6a19a371d8 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java @@ -286,7 +286,7 @@ protected void doOpen() throws Exception { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(lineMapper, "LineMapper is required"); + Assert.state(lineMapper != null, "LineMapper is required"); } @Override diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java index 520b41d31c..8bee1294a4 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java @@ -56,7 +56,7 @@ public FlatFileItemWriter() { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(lineAggregator, "A LineAggregator must be provided."); + Assert.state(lineAggregator != null, "A LineAggregator must be provided."); if (append) { shouldDeleteIfExists = false; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/DefaultLineMapper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/DefaultLineMapper.java index b47ad613e1..5392887fa7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/DefaultLineMapper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/DefaultLineMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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. @@ -52,8 +52,8 @@ public void setFieldSetMapper(FieldSetMapper fieldSetMapper) { @Override public void afterPropertiesSet() { - Assert.notNull(tokenizer, "The LineTokenizer must be set"); - Assert.notNull(fieldSetMapper, "The FieldSetMapper must be set"); + Assert.state(tokenizer != null, "The LineTokenizer must be set"); + Assert.state(fieldSetMapper != null, "The FieldSetMapper must be set"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PatternMatchingCompositeLineMapper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PatternMatchingCompositeLineMapper.java index 9d26e6fd87..58f0d3ffd8 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PatternMatchingCompositeLineMapper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PatternMatchingCompositeLineMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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. @@ -68,7 +68,7 @@ public T mapLine(String line, int lineNumber) throws Exception { @Override public void afterPropertiesSet() throws Exception { this.tokenizer.afterPropertiesSet(); - Assert.isTrue(this.patternMatcher != null, "The 'patternMatcher' property must be non-null"); + Assert.state(this.patternMatcher != null, "The 'patternMatcher' property must be non-null"); } public void setTokenizers(Map tokenizers) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/BeanWrapperFieldExtractor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/BeanWrapperFieldExtractor.java index 6bf43d6ab6..083839d2ca 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/BeanWrapperFieldExtractor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/BeanWrapperFieldExtractor.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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. @@ -60,7 +60,7 @@ public Object[] extract(T item) { @Override public void afterPropertiesSet() { - Assert.notNull(names, "The 'names' property must be set."); + Assert.state(names != null, "The 'names' property must be set."); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java index 74181a7357..717ec49d62 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2020 the original author or authors. + * Copyright 2006-2022 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. @@ -274,7 +274,7 @@ protected boolean isQuoteCharacter(char c) { @Override public void afterPropertiesSet() throws Exception { - Assert.hasLength(this.delimiter, "A delimiter is required"); + Assert.state(StringUtils.hasLength(this.delimiter), "A delimiter is required"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PatternMatchingCompositeLineTokenizer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PatternMatchingCompositeLineTokenizer.java index 25cdd507e9..54a061e7ff 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PatternMatchingCompositeLineTokenizer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PatternMatchingCompositeLineTokenizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2022 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. @@ -56,7 +56,7 @@ public FieldSet tokenize(@Nullable String line) { */ @Override public void afterPropertiesSet() throws Exception { - Assert.isTrue(this.tokenizers != null, "The 'tokenizers' property must be non-empty"); + Assert.state(this.tokenizers != null, "The 'tokenizers' property must be non-empty"); } public void setTokenizers(Map tokenizers) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemReader.java index b557283783..b9591dbf1f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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. @@ -90,7 +90,7 @@ public T read() { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(this.jmsTemplate, "The 'jmsTemplate' is required."); + Assert.state(this.jmsTemplate != null, "The 'jmsTemplate' is required."); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/kafka/KafkaItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/kafka/KafkaItemWriter.java index 3e496a4654..c494b93339 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/kafka/KafkaItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/kafka/KafkaItemWriter.java @@ -72,8 +72,8 @@ protected void flush() throws Exception { @Override protected void init() { - Assert.notNull(this.kafkaTemplate, "KafkaTemplate must not be null."); - Assert.notNull(this.kafkaTemplate.getDefaultTopic(), "KafkaTemplate must have the default topic set."); + Assert.state(this.kafkaTemplate != null, "KafkaTemplate must not be null."); + Assert.state(this.kafkaTemplate.getDefaultTopic() != null, "KafkaTemplate must have the default topic set."); } /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ldif/LdifReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ldif/LdifReader.java index 7e8035f140..3464143c52 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ldif/LdifReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ldif/LdifReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2019 the original author or authors. + * Copyright 2005-2022 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. @@ -175,8 +175,8 @@ public void setResource(Resource resource) { } public void afterPropertiesSet() throws Exception { - Assert.notNull(resource, "A resource is required to parse."); - Assert.notNull(ldifParser, "A parser is required"); + Assert.state(resource != null, "A resource is required to parse."); + Assert.state(ldifParser != null, "A parser is required"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ldif/MappingLdifReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ldif/MappingLdifReader.java index 92b17ed9b4..df0e6d5e88 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ldif/MappingLdifReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ldif/MappingLdifReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2019 the original author or authors. + * Copyright 2005-2022 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. @@ -172,8 +172,8 @@ public void setResource(Resource resource) { } public void afterPropertiesSet() throws Exception { - Assert.notNull(resource, "A resource is required to parse."); - Assert.notNull(ldifParser, "A parser is required"); + Assert.state(resource != null, "A resource is required to parse."); + Assert.state(ldifParser != null, "A parser is required"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemProcessor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemProcessor.java index c210bb63dc..4b23a000f1 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemProcessor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemProcessor.java @@ -93,8 +93,8 @@ private Object processItem(ItemProcessor processor, Object input) thro @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(delegates, "The 'delegates' may not be null"); - Assert.notEmpty(delegates, "The 'delegates' may not be empty"); + Assert.state(delegates != null, "The 'delegates' may not be null"); + Assert.state(!delegates.isEmpty(), "The 'delegates' may not be empty"); } /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java index 5613f16a68..0275833434 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java @@ -88,8 +88,8 @@ public void write(Chunk chunk) throws Exception { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(delegates, "The 'delegates' may not be null"); - Assert.notEmpty(delegates, "The 'delegates' may not be empty"); + Assert.state(delegates != null, "The 'delegates' may not be null"); + Assert.state(!delegates.isEmpty(), "The 'delegates' may not be empty"); } /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ScriptItemProcessor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ScriptItemProcessor.java index 30315ade99..79a0840c5a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ScriptItemProcessor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ScriptItemProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 the original author or authors. + * Copyright 2014-2022 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. @@ -139,7 +139,7 @@ public void afterPropertiesSet() throws Exception { "Either a script source or script file must be provided, not both"); if (scriptSource != null && scriptEvaluator instanceof StandardScriptEvaluator) { - Assert.isTrue(StringUtils.hasLength(language), + Assert.state(StringUtils.hasLength(language), "Language must be provided when using the default ScriptEvaluator and raw source code"); ((StandardScriptEvaluator) scriptEvaluator).setLanguage(language); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamReader.java index 7f8f75dfb2..5b79c401e2 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2022 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. @@ -71,7 +71,7 @@ public void update(ExecutionContext executionContext) { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(this.delegate, "A delegate item reader is required"); + Assert.state(this.delegate != null, "A delegate item reader is required"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamWriter.java index 2cfe6fc3f2..f655bdac53 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamWriter.java @@ -82,7 +82,7 @@ public void close() throws ItemStreamException { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(this.delegate, "A delegate item writer is required"); + Assert.state(this.delegate != null, "A delegate item writer is required"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/validator/SpringValidator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/validator/SpringValidator.java index d4b8e5d0ab..4db6e7bb7e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/validator/SpringValidator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/validator/SpringValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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. @@ -85,7 +85,7 @@ public void setValidator(org.springframework.validation.Validator validator) { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(validator, "validator must be set"); + Assert.state(validator != null, "validator must be set"); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/validator/ValidatingItemProcessor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/validator/ValidatingItemProcessor.java index d48cd882da..4b1e2aeef2 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/validator/ValidatingItemProcessor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/validator/ValidatingItemProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2022 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. @@ -91,7 +91,7 @@ public T process(T item) throws ValidationException { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(validator, "Validator must not be null."); + Assert.state(validator != null, "Validator must not be null."); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java index 9a91b28763..39d4615e59 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java @@ -160,10 +160,10 @@ public void setEncoding(String encoding) { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(unmarshaller, "The Unmarshaller must not be null."); - Assert.notEmpty(fragmentRootElementNames, "The FragmentRootElementNames must not be empty"); + Assert.state(unmarshaller != null, "The Unmarshaller must not be null."); + Assert.state(!fragmentRootElementNames.isEmpty(), "The FragmentRootElementNames must not be empty"); for (QName fragmentRootElementName : fragmentRootElementNames) { - Assert.hasText(fragmentRootElementName.getLocalPart(), + Assert.state(StringUtils.hasText(fragmentRootElementName.getLocalPart()), "The FragmentRootElementNames must not contain empty elements"); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java index 8bf4ce9f35..8af5576930 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java @@ -367,7 +367,7 @@ public void setSaveState(boolean saveState) { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(marshaller, "A Marshaller is required"); + Assert.state(marshaller != null, "A Marshaller is required"); if (rootTagName.contains("{")) { rootTagNamespace = rootTagName.replaceAll("\\{(.*)\\}.*", "$1"); rootTagName = rootTagName.replaceAll("\\{.*\\}(.*)", "$1"); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java index d62f06ab02..83e389d27d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java @@ -60,7 +60,7 @@ void testAfterPropertiesSet() throws Exception { writer.setRepository(repository); writer.setMethodName(""); - Exception exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet); + Exception exception = assertThrows(IllegalStateException.class, writer::afterPropertiesSet); assertEquals("methodName must not be empty.", exception.getMessage()); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxyTests.java index 711679fb7f..5ac9310378 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxyTests.java @@ -231,7 +231,7 @@ public Void doInTransaction(TransactionStatus status) { void delegateIsRequired() { ExtendedConnectionDataSourceProxy tested = new ExtendedConnectionDataSourceProxy(null); - assertThrows(IllegalArgumentException.class, tested::afterPropertiesSet); + assertThrows(IllegalStateException.class, tested::afterPropertiesSet); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java index 21e375a9c3..ef7561f507 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java @@ -85,17 +85,17 @@ public void setValues(String item, PreparedStatement ps) throws SQLException { @Test void testAfterPropertiesSet() { writer = new JdbcBatchItemWriter<>(); - Exception exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet); + Exception exception = assertThrows(IllegalStateException.class, writer::afterPropertiesSet); assertTrue(exception.getMessage().contains("NamedParameterJdbcTemplate"), "Message does not contain ' NamedParameterJdbcTemplate'."); writer.setJdbcTemplate(new NamedParameterJdbcTemplate(jdbcTemplate)); - exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet); + exception = assertThrows(IllegalStateException.class, writer::afterPropertiesSet); String message = exception.getMessage(); assertTrue(message.toLowerCase().contains("sql"), "Message does not contain 'sql'."); writer.setSql("select * from foo where id = ?"); - exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet); + exception = assertThrows(IllegalStateException.class, writer::afterPropertiesSet); assertTrue(exception.getMessage().contains("ItemPreparedStatementSetter"), "Message does not contain 'ItemPreparedStatementSetter'."); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java index 1d5939e2ed..30ffdce930 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java @@ -101,13 +101,13 @@ void setUp() { @Test void testAfterPropertiesSet() { writer = new JdbcBatchItemWriter<>(); - Exception exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet); + Exception exception = assertThrows(IllegalStateException.class, writer::afterPropertiesSet); String message = exception.getMessage(); assertTrue(message.contains("NamedParameterJdbcTemplate"), "Message does not contain 'NamedParameterJdbcTemplate'."); writer.setJdbcTemplate(namedParameterJdbcOperations); - exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet); + exception = assertThrows(IllegalStateException.class, writer::afterPropertiesSet); message = exception.getMessage().toLowerCase(); assertTrue(message.contains("sql"), "Message does not contain 'sql'."); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaItemWriterTests.java index 4d523519f7..d9e78bc90c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaItemWriterTests.java @@ -61,7 +61,7 @@ void setUp() { @Test void testAfterPropertiesSet() { writer = new JpaItemWriter<>(); - Exception exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet); + Exception exception = assertThrows(IllegalStateException.class, writer::afterPropertiesSet); String message = exception.getMessage(); assertTrue(message.contains("EntityManagerFactory"), "Wrong message for exception: " + message); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemWriterTests.java index e96440b7a4..c0c74d86bf 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemWriterTests.java @@ -545,7 +545,7 @@ void testOpenWithNonWritableFile() throws Exception { @Test void testAfterPropertiesSetChecksMandatory() { writer = new FlatFileItemWriter<>(); - assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet); + assertThrows(IllegalStateException.class, writer::afterPropertiesSet); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/DefaultLineMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/DefaultLineMapperTests.java index ea8fb42bc2..47ee5aecc9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/DefaultLineMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/DefaultLineMapperTests.java @@ -35,13 +35,13 @@ class DefaultLineMapperTests { @Test void testMandatoryTokenizer() { - assertThrows(IllegalArgumentException.class, tested::afterPropertiesSet); + assertThrows(IllegalStateException.class, tested::afterPropertiesSet); } @Test void testMandatoryMapper() { tested.setLineTokenizer(new DelimitedLineTokenizer()); - assertThrows(IllegalArgumentException.class, tested::afterPropertiesSet); + assertThrows(IllegalStateException.class, tested::afterPropertiesSet); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java index eb375456c9..4696559dc6 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java @@ -140,7 +140,7 @@ void testDelimitedLineTokenizerNullDelimiter() { @Test void testDelimitedLineTokenizerEmptyString() { DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(""); - assertThrows(IllegalArgumentException.class, tokenizer::afterPropertiesSet); + assertThrows(IllegalStateException.class, tokenizer::afterPropertiesSet); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PatternMatchingCompositeLineTokenizerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PatternMatchingCompositeLineTokenizerTests.java index 78f54061fc..4a5e3159c7 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PatternMatchingCompositeLineTokenizerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PatternMatchingCompositeLineTokenizerTests.java @@ -38,7 +38,7 @@ class PatternMatchingCompositeLineTokenizerTests { @Test void testNoTokenizers() { - assertThrows(IllegalArgumentException.class, tokenizer::afterPropertiesSet); + assertThrows(IllegalStateException.class, tokenizer::afterPropertiesSet); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemWriterTests.java index 0693768039..ddebe9d807 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemWriterTests.java @@ -69,11 +69,11 @@ void setUp() throws Exception { void testAfterPropertiesSet() { this.writer = new KafkaItemWriter<>(); - Exception exception = assertThrows(IllegalArgumentException.class, () -> this.writer.afterPropertiesSet()); + Exception exception = assertThrows(IllegalStateException.class, () -> this.writer.afterPropertiesSet()); assertEquals("itemKeyMapper requires a Converter type.", exception.getMessage()); this.writer.setItemKeyMapper(this.itemKeyMapper); - exception = assertThrows(IllegalArgumentException.class, () -> this.writer.afterPropertiesSet()); + exception = assertThrows(IllegalStateException.class, () -> this.writer.afterPropertiesSet()); assertEquals("KafkaTemplate must not be null.", exception.getMessage()); this.writer.setKafkaTemplate(this.kafkaTemplate); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemProcessorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemProcessorTests.java index b82040c098..f8d15de35b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemProcessorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemProcessorTests.java @@ -103,11 +103,11 @@ void testAfterPropertiesSet() { // value not set composite.setDelegates(null); - assertThrows(IllegalArgumentException.class, composite::afterPropertiesSet); + assertThrows(IllegalStateException.class, composite::afterPropertiesSet); // empty list composite.setDelegates(new ArrayList>()); - assertThrows(IllegalArgumentException.class, composite::afterPropertiesSet); + assertThrows(IllegalStateException.class, composite::afterPropertiesSet); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamWriterTests.java index 6df1ab6509..20c6b75087 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamWriterTests.java @@ -36,7 +36,7 @@ protected SynchronizedItemStreamWriter createNewSynchronizedItemStreamWr @Test void testDelegateIsNotNullWhenPropertiesSet() { - final Exception expectedException = assertThrows(IllegalArgumentException.class, + final Exception expectedException = assertThrows(IllegalStateException.class, () -> ((InitializingBean) new SynchronizedItemStreamWriter<>()).afterPropertiesSet()); assertEquals("A delegate item writer is required", expectedException.getMessage()); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/SpringValidatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/SpringValidatorTests.java index f8f4d8e9d9..a13e49d640 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/SpringValidatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/SpringValidatorTests.java @@ -44,7 +44,7 @@ void setUp() { @Test void testNullValidator() { validator.setValidator(null); - assertThrows(IllegalArgumentException.class, validator::afterPropertiesSet); + assertThrows(IllegalStateException.class, validator::afterPropertiesSet); } /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java index 858e20fcfa..c46b9321e0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java @@ -116,11 +116,11 @@ void testAfterPropertiesSetException() { source = createNewInputSource(); source.setFragmentRootElementName(""); - assertThrows(IllegalArgumentException.class, source::afterPropertiesSet); + assertThrows(IllegalStateException.class, source::afterPropertiesSet); source = createNewInputSource(); source.setUnmarshaller(null); - assertThrows(IllegalArgumentException.class, source::afterPropertiesSet); + assertThrows(IllegalStateException.class, source::afterPropertiesSet); } /** diff --git a/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java index 9785cdf5cf..f1ef5bd74e 100644 --- a/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ b/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java @@ -104,7 +104,7 @@ public void doDestroy() { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource, "A DataSource is required"); + Assert.state(dataSource != null, "A DataSource is required"); initialize(); } diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/async/AsyncItemProcessor.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/async/AsyncItemProcessor.java index db1ddbcf0f..97283df8e0 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/async/AsyncItemProcessor.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/async/AsyncItemProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2022 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. @@ -59,7 +59,7 @@ public class AsyncItemProcessor implements ItemProcessor>, In * @see InitializingBean#afterPropertiesSet() */ public void afterPropertiesSet() throws Exception { - Assert.notNull(delegate, "The delegate must be set."); + Assert.state(delegate != null, "The delegate must be set."); } /** diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/async/AsyncItemWriter.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/async/AsyncItemWriter.java index 65c4932fea..4b3336afc6 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/async/AsyncItemWriter.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/async/AsyncItemWriter.java @@ -39,7 +39,7 @@ public class AsyncItemWriter implements ItemStreamWriter>, Initiali private ItemWriter delegate; public void afterPropertiesSet() throws Exception { - Assert.notNull(delegate, "A delegate ItemWriter must be provided."); + Assert.state(delegate != null, "A delegate ItemWriter must be provided."); } /** diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandler.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandler.java index 2ff1c65a23..4b68bcbbbf 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandler.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandler.java @@ -56,7 +56,7 @@ public class ChunkProcessorChunkHandler implements ChunkHandler, Initializ * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ public void afterPropertiesSet() throws Exception { - Assert.notNull(chunkProcessor, "A ChunkProcessor must be provided"); + Assert.state(chunkProcessor != null, "A ChunkProcessor must be provided"); } /** diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/MessageChannelPartitionHandler.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/MessageChannelPartitionHandler.java index 4b48a6836a..334634684e 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/MessageChannelPartitionHandler.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/MessageChannelPartitionHandler.java @@ -111,7 +111,7 @@ public class MessageChannelPartitionHandler extends AbstractPartitionHandler imp @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(stepName, "A step name must be provided for the remote workers."); + Assert.state(stepName != null, "A step name must be provided for the remote workers."); Assert.state(messagingGateway != null, "The MessagingOperations must be set"); pollRepositoryForResults = !(dataSource == null && jobExplorer == null); diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/async/AsyncItemProcessorTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/async/AsyncItemProcessorTests.java index 50f859617c..6ad12bf2e9 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/async/AsyncItemProcessorTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/async/AsyncItemProcessorTests.java @@ -46,7 +46,7 @@ public String process(String item) throws Exception { @Test void testNoDelegate() { - assertThrows(IllegalArgumentException.class, processor::afterPropertiesSet); + assertThrows(IllegalStateException.class, processor::afterPropertiesSet); } @Test diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemListener.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemListener.java index 7bff52b4d8..bef7c2eaf5 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemListener.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2012 the original author or authors. + * Copyright 2006-2022 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. @@ -39,7 +39,7 @@ public void setDataSource(DataSource dataSource) { @Override public final void afterPropertiesSet() throws Exception { - Assert.notNull(jdbcTemplate, "You must provide a DataSource."); + Assert.state(jdbcTemplate != null, "You must provide a DataSource."); } @Override diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemProcessor.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemProcessor.java index a3a6151093..27969c69ee 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemProcessor.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2019 the original author or authors. + * Copyright 2009-2022 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. @@ -49,7 +49,7 @@ public void setDataSource(DataSource dataSource) { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(jdbcTemplate, "Either jdbcTemplate or dataSource must be set"); + Assert.state(jdbcTemplate != null, "Either jdbcTemplate or dataSource must be set"); } /** diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java index 3650dacae2..3642ad14cd 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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. @@ -72,7 +72,7 @@ public void destroy() throws Exception { @Override public final void afterPropertiesSet() throws Exception { - Assert.notNull(jdbcTemplate, "You must provide a DataSource."); + Assert.state(jdbcTemplate != null, "You must provide a DataSource."); } private List retrieveKeys() { diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/multiline/AggregateItemFieldSetMapper.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/multiline/AggregateItemFieldSetMapper.java index 5fe6427dfd..b49d2fe253 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/multiline/AggregateItemFieldSetMapper.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/multiline/AggregateItemFieldSetMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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. @@ -68,7 +68,7 @@ public void setBegin(String begin) { */ @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(delegate, "A FieldSetMapper delegate must be provided."); + Assert.state(delegate != null, "A FieldSetMapper delegate must be provided."); } /** diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/HibernateAwareCustomerCreditItemWriter.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/HibernateAwareCustomerCreditItemWriter.java index 51848ef149..69d0ac8169 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/HibernateAwareCustomerCreditItemWriter.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/HibernateAwareCustomerCreditItemWriter.java @@ -68,7 +68,7 @@ public void setSessionFactory(SessionFactory sessionFactory) { @Override public void afterPropertiesSet() throws Exception { Assert.state(sessionFactory != null, "Hibernate SessionFactory is required"); - Assert.notNull(dao, "Delegate DAO must be set"); + Assert.state(dao != null, "Delegate DAO must be set"); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/loop/GeneratingTradeResettingListener.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/loop/GeneratingTradeResettingListener.java index 1161b76a82..53be166810 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/loop/GeneratingTradeResettingListener.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/loop/GeneratingTradeResettingListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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. @@ -47,7 +47,7 @@ public void setReader(GeneratingTradeItemReader reader) { @Override public void afterPropertiesSet() throws Exception { - Assert.notNull(this.reader, "The 'reader' must be set."); + Assert.state(this.reader != null, "The 'reader' must be set."); } } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemFieldSetMapperTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemFieldSetMapperTests.java index e06732b941..7d2b0d8871 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemFieldSetMapperTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/multiline/AggregateItemFieldSetMapperTests.java @@ -52,7 +52,7 @@ void testSetEndRecord() throws Exception { @Test void testMandatoryProperties() { - assertThrows(IllegalArgumentException.class, mapper::afterPropertiesSet); + assertThrows(IllegalStateException.class, mapper::afterPropertiesSet); } @Test diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/DataSourceInitializer.java b/spring-batch-test/src/main/java/org/springframework/batch/test/DataSourceInitializer.java index a4201e491c..c34651ca32 100755 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/DataSourceInitializer.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/DataSourceInitializer.java @@ -107,7 +107,7 @@ public void destroy() { @Override public void afterPropertiesSet() { - Assert.notNull(this.dataSource, "A DataSource is required"); + Assert.state(this.dataSource != null, "A DataSource is required"); initialize(); }