diff --git a/.mvn/jvm.config b/.mvn/jvm.config new file mode 100644 index 0000000000..32599cefea --- /dev/null +++ b/.mvn/jvm.config @@ -0,0 +1,10 @@ +--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED +--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED +--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED diff --git a/pom.xml b/pom.xml index e3be833083..06293d3a32 100644 --- a/pom.xml +++ b/pom.xml @@ -180,7 +180,34 @@ ${java.version} -parameters + + -XDcompilePolicy=simple + --should-stop=ifError=FLOW + + -Xplugin:ErrorProne + -Xep:DefaultCharset:OFF + -Xep:EqualsGetClass:OFF + -Xep:Finally:OFF + -Xep:HidingField:OFF + -Xep:JavaTimeDefaultTimeZone:OFF + -Xep:JdkObsolete:OFF + -Xep:MixedMutabilityReturnType:OFF + -Xep:MutablePublicArray:OFF + -Xep:NonAtomicVolatileUpdate:OFF + -Xep:ReferenceEquality:OFF + -Xep:StringCaseLocaleUsage:OFF + -Xep:StringSplitter:OFF + -Xep:SynchronizeOnNonFinalField:OFF + + true + + + com.google.errorprone + error_prone_core + 2.37.0 + + diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java b/spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java index 6bcc5818ab..78e3e2bcb3 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java @@ -146,7 +146,7 @@ public boolean equals(Object other) { @Override public int hashCode() { if (id == null) { - return super.hashCode(); + return System.identityHashCode(this); } return 39 + 87 * id.hashCode(); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java index c595f43e40..8a37b20bc3 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.ObjectInputStream; +import java.time.Clock; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collection; @@ -203,7 +204,7 @@ public void upgradeStatus(BatchStatus status) { /** * Convenience getter for the {@code id} of the enclosing job. Useful for DAO * implementations. - * @return the @{code id} of the enclosing job. + * @return the {@code id} of the enclosing job. */ public Long getJobId() { if (jobInstance != null) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameters.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameters.java index a5e54b0c65..5ddf610506 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameters.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameters.java @@ -373,7 +373,7 @@ public String toString() { for (Map.Entry> entry : this.parameters.entrySet()) { parameters.add(String.format("'%s':'%s'", entry.getKey(), entry.getValue())); } - return new StringBuilder("{").append(String.join(",", parameters)).append("}").toString(); + return "{" + String.join(",", parameters) + "}"; } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java index 1bf5164778..5f3a3f2115 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java @@ -492,7 +492,7 @@ public boolean equals(Object obj) { return super.equals(obj); } - return stepName.equals(other.getStepName()) && (jobExecutionId.equals(other.getJobExecutionId())) + return stepName.equals(other.getStepName()) && jobExecutionId.equals(other.getJobExecutionId()) && getId().equals(other.getId()); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobFactory.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobFactory.java index dafe2035f7..8538769c4d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobFactory.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobFactory.java @@ -32,7 +32,7 @@ public interface JobFactory { Job createJob(); /** - * @return The {@link String} that contains the {@link Job} name. + * Return the {@link String} that contains the {@link Job} name. */ String getJobName(); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchObservabilityBeanPostProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchObservabilityBeanPostProcessor.java index bc3d35159e..9d2bfb844b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchObservabilityBeanPostProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchObservabilityBeanPostProcessor.java @@ -50,11 +50,11 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw try { if (bean instanceof AbstractJob || bean instanceof AbstractStep) { ObservationRegistry observationRegistry = this.beanFactory.getBean(ObservationRegistry.class); - if (bean instanceof AbstractJob) { - ((AbstractJob) bean).setObservationRegistry(observationRegistry); + if (bean instanceof AbstractJob job) { + job.setObservationRegistry(observationRegistry); } - if (bean instanceof AbstractStep) { - ((AbstractStep) bean).setObservationRegistry(observationRegistry); + if (bean instanceof AbstractStep step) { + step.setObservationRegistry(observationRegistry); } } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchRegistrar.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchRegistrar.java index 3d23f6bcf7..4a08e87a48 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchRegistrar.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchRegistrar.java @@ -49,8 +49,6 @@ class BatchRegistrar implements ImportBeanDefinitionRegistrar { private static final Log LOGGER = LogFactory.getLog(BatchRegistrar.class); - private static final String MISSING_ANNOTATION_ERROR_MESSAGE = "EnableBatchProcessing is not present on importing class '%s' as expected"; - private static final String JOB_REPOSITORY = "jobRepository"; private static final String JOB_EXPLORER = "jobExplorer"; @@ -84,7 +82,8 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B private void validateState(AnnotationMetadata importingClassMetadata) { if (!importingClassMetadata.isAnnotated(EnableBatchProcessing.class.getName())) { String className = importingClassMetadata.getClassName(); - String errorMessage = String.format(MISSING_ANNOTATION_ERROR_MESSAGE, className); + String errorMessage = "EnableBatchProcessing is not present on importing class '%s' as expected" + .formatted(className); throw new IllegalStateException(errorMessage); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AbstractApplicationContextFactory.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AbstractApplicationContextFactory.java index 535886f96c..9ef7ef72d0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AbstractApplicationContextFactory.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AbstractApplicationContextFactory.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import org.apache.commons.logging.Log; @@ -196,13 +197,11 @@ protected void prepareContext(ConfigurableApplicationContext parent, Configurabl protected void prepareBeanFactory(ConfigurableListableBeanFactory parent, ConfigurableListableBeanFactory beanFactory) { if (copyConfiguration && parent != null) { - List parentPostProcessors = new ArrayList<>(); - List childPostProcessors = new ArrayList<>(); - - childPostProcessors.addAll(beanFactory instanceof AbstractBeanFactory - ? ((AbstractBeanFactory) beanFactory).getBeanPostProcessors() : new ArrayList<>()); - parentPostProcessors.addAll(parent instanceof AbstractBeanFactory - ? ((AbstractBeanFactory) parent).getBeanPostProcessors() : new ArrayList<>()); + List childPostProcessors = new ArrayList<>( + beanFactory instanceof AbstractBeanFactory factory ? factory.getBeanPostProcessors() + : new ArrayList<>()); + List parentPostProcessors = new ArrayList<>(parent instanceof AbstractBeanFactory factory + ? factory.getBeanPostProcessors() : new ArrayList<>()); try { Class applicationContextAwareProcessorClass = ClassUtils.forName( @@ -237,8 +236,8 @@ protected void prepareBeanFactory(ConfigurableListableBeanFactory parent, beanFactory.copyConfigurationFrom(parent); - List beanPostProcessors = beanFactory instanceof AbstractBeanFactory - ? ((AbstractBeanFactory) beanFactory).getBeanPostProcessors() : new ArrayList<>(); + List beanPostProcessors = beanFactory instanceof AbstractBeanFactory abstractBeanFactory + ? abstractBeanFactory.getBeanPostProcessors() : new ArrayList<>(); beanPostProcessors.clear(); beanPostProcessors.addAll(aggregatedPostProcessors); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrar.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrar.java index e8496b83d6..c76ee7b9dd 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrar.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrar.java @@ -79,8 +79,8 @@ public void setApplicationContext(ApplicationContext applicationContext) { * use */ public void addApplicationContextFactory(ApplicationContextFactory applicationContextFactory) { - if (applicationContextFactory instanceof ApplicationContextAware) { - ((ApplicationContextAware) applicationContextFactory).setApplicationContext(applicationContext); + if (applicationContextFactory instanceof ApplicationContextAware applicationContextAware) { + applicationContextAware.setApplicationContext(applicationContext); } this.applicationContextFactories.add(applicationContextFactory); } 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 4dde8ea152..3cf8ee41e1 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 @@ -255,11 +255,11 @@ private void doRegister(ConfigurableApplicationContext context, Job job) throws jobRegistry.register(jobFactory); if (stepRegistry != null) { - if (!(job instanceof StepLocator)) { + if (!(job instanceof StepLocator stepLocator)) { throw new UnsupportedOperationException("Cannot locate steps from a Job that is not a StepLocator: job=" + job.getName() + " does not implement StepLocator"); } - stepRegistry.register(job.getName(), getSteps((StepLocator) job, context)); + stepRegistry.register(job.getName(), getSteps(stepLocator, context)); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/GenericApplicationContextFactory.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/GenericApplicationContextFactory.java index a9074f6671..b523181eee 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/GenericApplicationContextFactory.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/GenericApplicationContextFactory.java @@ -126,7 +126,7 @@ protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) { GenericApplicationContextFactory.this.prepareBeanFactory(parentBeanFactory, beanFactory); for (Class cls : getBeanFactoryPostProcessorClasses()) { for (String name : parent.getBeanNamesForType(cls)) { - beanFactory.registerSingleton(name, (parent.getBean(name))); + beanFactory.registerSingleton(name, parent.getBean(name)); } } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/GroupAwareJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/GroupAwareJob.java index 2ea527202c..68dca95553 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/GroupAwareJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/GroupAwareJob.java @@ -99,8 +99,8 @@ public JobParametersValidator getJobParametersValidator() { @Override public boolean equals(Object obj) { - if (obj instanceof GroupAwareJob) { - return ((GroupAwareJob) obj).delegate.equals(delegate); + if (obj instanceof GroupAwareJob groupAwareJob) { + return groupAwareJob.delegate.equals(delegate); } return false; } 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 1f6ba7acfa..b70d8ae810 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 @@ -87,8 +87,8 @@ public void setJobRegistry(JobRegistry jobRegistry) { @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - if (beanFactory instanceof DefaultListableBeanFactory) { - this.beanFactory = (DefaultListableBeanFactory) beanFactory; + if (beanFactory instanceof DefaultListableBeanFactory defaultListableBeanFactory) { + this.beanFactory = defaultListableBeanFactory; } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractFlowParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractFlowParser.java index 876a9ed2ce..c378258a91 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractFlowParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractFlowParser.java @@ -404,7 +404,7 @@ protected static Collection createTransition(FlowExecutionStatus endBuilder.addConstructorArgValue(exitCodeExists ? exitCode : status.getName()); String endName = (status == FlowExecutionStatus.STOPPED ? STOP_ELE - : status == FlowExecutionStatus.FAILED ? FAIL_ELE : END_ELE) + (endCounter++); + : status == FlowExecutionStatus.FAILED ? FAIL_ELE : END_ELE) + endCounter++; endBuilder.addConstructorArgValue(endName); endBuilder.addConstructorArgValue(abandon); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java index c12eaf8633..ec1490bb9b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java @@ -119,15 +119,15 @@ protected AbstractBeanDefinition parseStep(Element stepElement, ParserContext pa } else if (FLOW_ELE.equals(name)) { boolean stepUnderspecified = CoreNamespaceUtils.isUnderspecified(stepElement); - parseFlow(stepElement, nestedElement, bd, parserContext, stepUnderspecified); + parseFlow(stepElement, nestedElement, bd); } else if (PARTITION_ELE.equals(name)) { boolean stepUnderspecified = CoreNamespaceUtils.isUnderspecified(stepElement); - parsePartition(stepElement, nestedElement, bd, parserContext, stepUnderspecified, jobFactoryRef); + parsePartition(stepElement, nestedElement, bd, parserContext, jobFactoryRef); } else if (JOB_ELE.equals(name)) { boolean stepUnderspecified = CoreNamespaceUtils.isUnderspecified(stepElement); - parseJob(stepElement, nestedElement, bd, parserContext, stepUnderspecified); + parseJob(nestedElement, bd, parserContext); } else if ("description".equals(name)) { bd.setDescription(nestedElement.getTextContent()); @@ -199,7 +199,7 @@ else if (ns.equals("http://www.springframework.org/schema/batch")) { } private void parsePartition(Element stepElement, Element partitionElement, AbstractBeanDefinition bd, - ParserContext parserContext, boolean stepUnderspecified, String jobFactoryRef) { + ParserContext parserContext, String jobFactoryRef) { bd.setBeanClass(StepParserStepFactoryBean.class); bd.setAttribute("isNamespaceStep", true); @@ -258,8 +258,7 @@ else if (inlineStepElement != null) { } - private void parseJob(Element stepElement, Element jobElement, AbstractBeanDefinition bd, - ParserContext parserContext, boolean stepUnderspecified) { + private void parseJob(Element jobElement, AbstractBeanDefinition bd, ParserContext parserContext) { bd.setBeanClass(StepParserStepFactoryBean.class); bd.setAttribute("isNamespaceStep", true); @@ -285,8 +284,7 @@ private void parseJob(Element stepElement, Element jobElement, AbstractBeanDefin } - private void parseFlow(Element stepElement, Element flowElement, AbstractBeanDefinition bd, - ParserContext parserContext, boolean stepUnderspecified) { + private void parseFlow(Element stepElement, Element flowElement, AbstractBeanDefinition bd) { bd.setBeanClass(StepParserStepFactoryBean.class); bd.setAttribute("isNamespaceStep", true); 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 18c9e4cf2e..55460af924 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 @@ -150,8 +150,8 @@ public Object getObject() { // create a proxy listener for only the interfaces that have methods to // be called ProxyFactory proxyFactory = new ProxyFactory(); - if (delegate instanceof Advised) { - proxyFactory.setTargetSource(((Advised) delegate).getTargetSource()); + if (delegate instanceof Advised advised) { + proxyFactory.setTargetSource(advised.getTargetSource()); } else { proxyFactory.setTarget(delegate); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/BatchScopeSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/BatchScopeSupport.java index 7cf74c855c..1b8da10bf5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/BatchScopeSupport.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/BatchScopeSupport.java @@ -185,8 +185,8 @@ protected Object resolveValue(Object value) { BeanDefinition definition = null; String beanName = null; - if (value instanceof BeanDefinition) { - definition = (BeanDefinition) value; + if (value instanceof BeanDefinition beanDefinition) { + definition = beanDefinition; beanName = BeanDefinitionReaderUtils.generateBeanName(definition, registry); } else if (value instanceof BeanDefinitionHolder holder) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/JobContext.java b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/JobContext.java index 25e51964c7..a1fb643bde 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/JobContext.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/JobContext.java @@ -161,8 +161,8 @@ public void close() { } Exception error = errors.get(0); - if (error instanceof RuntimeException) { - throw (RuntimeException) error; + if (error instanceof RuntimeException runtimeException) { + throw runtimeException; } else { throw new UnexpectedJobExecutionException( diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeItemReadListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeItemReadListenerTests.java index ac9bd41bac..68b12d9dc0 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeItemReadListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeItemReadListenerTests.java @@ -17,7 +17,7 @@ import static org.mockito.Mockito.mock; -import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -67,11 +67,7 @@ void testOnReadError() { @Test void testSetListeners() { - compositeListener.setListeners(new ArrayList<>() { - { - add(listener); - } - }); + compositeListener.setListeners(List.of(listener)); listener.beforeRead(); compositeListener.beforeRead(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeItemWriteListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeItemWriteListenerTests.java index 6531b4ef35..5e166c790e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeItemWriteListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeItemWriteListenerTests.java @@ -15,7 +15,7 @@ */ package org.springframework.batch.core.listener; -import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -69,11 +69,7 @@ void testOnWriteError() { @Test void testSetListeners() { - compositeListener.setListeners(new ArrayList<>() { - { - add(listener); - } - }); + compositeListener.setListeners(List.of(listener)); Chunk item = Chunk.of(new Object()); listener.beforeWrite(item); compositeListener.beforeWrite(item); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapperTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapperTests.java index 7e23e13dfa..4a10f757cf 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapperTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapperTests.java @@ -36,16 +36,13 @@ class ConfigurableSystemProcessExitCodeMapperTests { */ @Test void testMapping() { - Map mappings = new HashMap<>() { - { - put(0, ExitStatus.COMPLETED); - put(1, ExitStatus.FAILED); - put(2, ExitStatus.EXECUTING); - put(3, ExitStatus.NOOP); - put(4, ExitStatus.UNKNOWN); - put(ConfigurableSystemProcessExitCodeMapper.ELSE_KEY, ExitStatus.UNKNOWN); - } - }; + Map mappings = Map.of( // + 0, ExitStatus.COMPLETED, // + 1, ExitStatus.FAILED, // + 2, ExitStatus.EXECUTING, // + 3, ExitStatus.NOOP, // + 4, ExitStatus.UNKNOWN, // + ConfigurableSystemProcessExitCodeMapper.ELSE_KEY, ExitStatus.UNKNOWN); mapper.setMappings(mappings); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java index 52895ca79d..91d17ecebe 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java @@ -26,7 +26,7 @@ /** * Encapsulation of a list of items to be processed and possibly a list of failed items to - * be skipped. To mark an item as skipped clients should iterate over the chunk using the + * be skipped. To mark an item as skipped, clients should iterate over the chunk using the * {@link #iterator()} method, and if there is a failure call * {@link Chunk.ChunkIterator#remove()} on the iterator. The skipped items are then * available through the chunk. @@ -100,21 +100,21 @@ public void clear() { } /** - * @return a copy of the items to be processed as an unmodifiable list + * Return a copy of the items to be processed as an unmodifiable list. */ public List getItems() { return Collections.unmodifiableList(items); } /** - * @return a copy of the skips as an unmodifiable list + * Return a copy of the skips as an unmodifiable list. */ public List> getSkips() { return Collections.unmodifiableList(skips); } /** - * @return a copy of the anonymous errors as an unmodifiable list + * Return a copy of the anonymous errors as an unmodifiable list. */ public List getErrors() { return Collections.unmodifiableList(errors); @@ -130,7 +130,7 @@ public void skip(Exception e) { } /** - * @return true if there are no items in the chunk + * Return {@code true} if there are no items in the chunk. */ public boolean isEmpty() { return items.isEmpty(); @@ -146,7 +146,7 @@ public ChunkIterator iterator() { } /** - * @return the number of items (excluding skips) + * Return the number of items (excluding skips). */ public int size() { return items.size(); 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 c60d31ef34..bd65750db5 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 @@ -29,9 +29,9 @@ import org.springframework.util.StringUtils; /** - * Superclass for delegating classes which dynamically call a custom method of injected - * object. Provides convenient API for dynamic method invocation shielding subclasses from - * low-level details and exception handling. + * Superclass for delegating classes which dynamically call a custom method of an injected + * object. Provides a convenient API for dynamic method invocation shielding subclasses + * from low-level details and exception handling. *

* {@link Exception}s thrown by a successfully invoked delegate method are re-thrown * without wrapping. In case the delegate method throws a {@link Throwable} that doesn't @@ -164,7 +164,7 @@ private boolean targetClassDeclaresTargetMethod() { if (arguments[j] == null) { continue; } - if (!(ClassUtils.isAssignableValue(params[j], arguments[j]))) { + if (!ClassUtils.isAssignableValue(params[j], arguments[j])) { argumentsMatchParameters = false; } } @@ -179,24 +179,23 @@ private boolean targetClassDeclaresTargetMethod() { } /** - * @param targetObject the delegate - bean id can be used to set this value in Spring - * configuration + * Set the delegate - bean id can be used to set this value in Spring configuration. */ public void setTargetObject(Object targetObject) { this.targetObject = targetObject; } /** - * @param targetMethod name of the method to be invoked on - * {@link #setTargetObject(Object)}. + * Set the name of the method to be invoked on {@link #setTargetObject(Object)}. */ public void setTargetMethod(String targetMethod) { this.targetMethod = targetMethod; } /** - * @param arguments arguments values for the { {@link #setTargetMethod(String)}. These - * will be used only when the subclass tries to invoke the target method without + * Set the argument values for the {@link #setTargetMethod(String)}. + *

+ * These will be used only when the subclass tries to invoke the target method without * providing explicit argument values. *

* If arguments are set to not-null value {@link #afterPropertiesSet()} will check the @@ -205,19 +204,18 @@ public void setTargetMethod(String targetMethod) { * will be supplied at runtime. */ public void setArguments(Object[] arguments) { - this.arguments = arguments == null ? null : Arrays.asList(arguments).toArray(); + this.arguments = arguments == null ? null : arguments.clone(); } /** - * Return arguments. - * @return arguments + * Return the argument values for the method to be invoked. */ protected Object[] getArguments() { return arguments; } /** - * @return the object on which the method will be invoked. + * Return the object on which the method will be invoked. * @since 5.1 */ protected Object getTargetObject() { @@ -225,7 +223,7 @@ protected Object getTargetObject() { } /** - * @return the name of the method to be invoked. + * Return the name of the method to be invoked. * @since 5.1 */ protected String getTargetMethod() { 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 75b35c7dab..b840151e24 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 @@ -72,13 +72,13 @@ public void afterPropertiesSet() throws Exception { } /** - * @param fieldsUsedAsMethodArguments the values of the these item's fields will be - * used as arguments for the delegate method. Nested property values are supported, - * e.g. address.city + * Sets the values of the item's fields to be used as arguments for the delegate + * method. + *

+ * Nested property values are supported, e.g. address.city */ public void setFieldsUsedAsTargetMethodArguments(String[] fieldsUsedAsMethodArguments) { - this.fieldsUsedAsTargetMethodArguments = Arrays.asList(fieldsUsedAsMethodArguments) - .toArray(new String[fieldsUsedAsMethodArguments.length]); + this.fieldsUsedAsTargetMethodArguments = fieldsUsedAsMethodArguments.clone(); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/builder/AvroItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/builder/AvroItemReaderBuilder.java index c9803e2590..1dd2ecabe6 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/builder/AvroItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/builder/AvroItemReaderBuilder.java @@ -24,6 +24,8 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; +import java.nio.charset.Charset; + /** * A builder implementation for the {@link AvroItemReader}. * diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/builder/AvroItemWriterBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/builder/AvroItemWriterBuilder.java index 69c9eb85cc..b243da4b31 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/builder/AvroItemWriterBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/builder/AvroItemWriterBuilder.java @@ -22,6 +22,8 @@ import org.springframework.core.io.WritableResource; import org.springframework.util.Assert; +import java.nio.charset.Charset; + /** * A builder implementation for the {@link AvroItemWriter}. * @@ -40,7 +42,8 @@ public class AvroItemWriterBuilder { private String name = AvroItemWriter.class.getSimpleName(); /** - * @param resource the {@link WritableResource} used to write the serialized data. + * Sets the {@link WritableResource} used to write the serialized data. + * @param resource the {@code WritableResource} used to write the serialized data. * @return The current instance of the builder. */ public AvroItemWriterBuilder resource(WritableResource resource) { @@ -50,7 +53,9 @@ public AvroItemWriterBuilder resource(WritableResource resource) { } /** - * @param schema the Resource containing the schema JSON used to serialize the output. + * Sets the {@link Resource} containing the schema JSON used to serialize the output. + * @param schema the {@code Resource} containing the schema JSON used to serialize the + * output. * @return The current instance of the builder. */ public AvroItemWriterBuilder schema(Resource schema) { @@ -61,6 +66,7 @@ public AvroItemWriterBuilder schema(Resource schema) { } /** + * Sets the String containing the schema JSON used to serialize the output. * @param schemaString the String containing the schema JSON used to serialize the * output. * @return The current instance of the builder. @@ -72,6 +78,7 @@ public AvroItemWriterBuilder schema(String schemaString) { } /** + * Sets the Class of objects to be serialized. * @param type the Class of objects to be serialized. * @return The current instance of the builder. */ diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoCursorItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoCursorItemReader.java index 1759557d61..c505fdff16 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoCursorItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoCursorItemReader.java @@ -101,7 +101,7 @@ public void setTargetType(Class targetType) { } /** - * @param collection Mongo collection to be queried. + * The Mongo collection to be queried. */ public void setCollection(String collection) { this.collection = collection; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemReader.java index 9c8ce109d6..b347b6728b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemReader.java @@ -172,7 +172,7 @@ public void setSort(Map sorts) { } /** - * @param collection Mongo collection to be queried. + * The Mongo collection to be queried. */ public void setCollection(String collection) { this.collection = collection; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemWriter.java index b7aa27f375..0ff1cdc497 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemWriter.java @@ -107,7 +107,7 @@ public MongoItemWriter() { */ @Deprecated(since = "5.1", forRemoval = true) public void setDelete(boolean delete) { - this.mode = (delete) ? Mode.REMOVE : Mode.UPSERT; + this.mode = delete ? Mode.REMOVE : Mode.UPSERT; } /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoPagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoPagingItemReader.java index 5c2278cacc..f682b9b95c 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoPagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoPagingItemReader.java @@ -67,6 +67,7 @@ * @author Mahmoud Ben Hassine * @author Parikshit Dutta */ +@SuppressWarnings("removal") public class MongoPagingItemReader extends MongoItemReader { /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemReader.java index 98ce9941f3..eccf8402e7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemReader.java @@ -44,7 +44,7 @@ /** *

* A {@link org.springframework.batch.item.ItemReader} that reads records utilizing a - * {@link org.springframework.data.repository.PagingAndSortingRepository}. + * {@link PagingAndSortingRepository}. *

* *

@@ -54,9 +54,8 @@ *

* *

- * The reader must be configured with a - * {@link org.springframework.data.repository.PagingAndSortingRepository}, a - * {@link org.springframework.data.domain.Sort}, and a pageSize greater than 0. + * The reader must be configured with a {@link PagingAndSortingRepository}, a + * {@link Sort}, and a pageSize greater than 0. *

* *

@@ -127,15 +126,14 @@ public void setSort(Map sorts) { } /** - * @param pageSize The number of items to retrieve per page. Must be greater than 0. + * The number of items to retrieve per page. Must be greater than 0. */ public void setPageSize(int pageSize) { this.pageSize = pageSize; } /** - * The {@link org.springframework.data.repository.PagingAndSortingRepository} - * implementation used to read input from. + * The {@link PagingAndSortingRepository} implementation used to read input from. * @param repository underlying repository for input to be read from. */ public void setRepository(PagingAndSortingRepository repository) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoCursorItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoCursorItemReaderBuilder.java index b7c09835b7..a44e94baff 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoCursorItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoCursorItemReaderBuilder.java @@ -29,6 +29,8 @@ import org.springframework.util.StringUtils; /** + * A builder implementation for the {@link MongoCursorItemReader}. + * * @author LEE Juchan * @author Mahmoud Ben Hassine * @since 5.1 diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilder.java index 17747b8212..f04da97e7a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilder.java @@ -40,6 +40,7 @@ * @deprecated Use {@link MongoPagingItemReaderBuilder} instead. Scheduled for removal in * v5.3 or later. */ +@SuppressWarnings("removal") @Deprecated(since = "5.1", forRemoval = true) public class MongoItemReaderBuilder { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilder.java index 4df60a7d4c..3ad740649d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilder.java @@ -49,7 +49,7 @@ public class MongoItemWriterBuilder { */ @Deprecated(since = "5.1", forRemoval = true) public MongoItemWriterBuilder delete(boolean delete) { - this.mode = (delete) ? Mode.REMOVE : Mode.UPSERT; + this.mode = delete ? Mode.REMOVE : Mode.UPSERT; return this; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoPagingItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoPagingItemReaderBuilder.java index 286f043f0e..c3f2aa49b4 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoPagingItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/MongoPagingItemReaderBuilder.java @@ -36,6 +36,7 @@ * @author Parikshit Dutta * @since 5.1 */ +@SuppressWarnings("removal") public class MongoPagingItemReaderBuilder extends MongoItemReaderBuilder { /** @@ -45,6 +46,7 @@ public class MongoPagingItemReaderBuilder extends MongoItemReaderBuilder { * @param saveState defaults to true * @return The current instance of the builder. */ + @Override public MongoPagingItemReaderBuilder saveState(boolean saveState) { this.saveState = saveState; @@ -59,6 +61,7 @@ public MongoPagingItemReaderBuilder saveState(boolean saveState) { * @return The current instance of the builder. * @see org.springframework.batch.item.ItemStreamSupport#setName(String) */ + @Override public MongoPagingItemReaderBuilder name(String name) { this.name = name; @@ -71,6 +74,7 @@ public MongoPagingItemReaderBuilder name(String name) { * @return The current instance of the builder. * @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int) */ + @Override public MongoPagingItemReaderBuilder maxItemCount(int maxItemCount) { this.maxItemCount = maxItemCount; @@ -83,6 +87,7 @@ public MongoPagingItemReaderBuilder maxItemCount(int maxItemCount) { * @return this instance for method chaining * @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int) */ + @Override public MongoPagingItemReaderBuilder currentItemCount(int currentItemCount) { this.currentItemCount = currentItemCount; @@ -97,6 +102,7 @@ public MongoPagingItemReaderBuilder currentItemCount(int currentItemCount) { * @return The current instance of the builder * @see MongoPagingItemReader#setTemplate(MongoOperations) */ + @Override public MongoPagingItemReaderBuilder template(MongoOperations template) { this.template = template; @@ -111,6 +117,7 @@ public MongoPagingItemReaderBuilder template(MongoOperations template) { * @return The current instance of the builder * @see MongoPagingItemReader#setQuery(String) */ + @Override public MongoPagingItemReaderBuilder jsonQuery(String query) { this.jsonQuery = query; @@ -124,6 +131,7 @@ public MongoPagingItemReaderBuilder jsonQuery(String query) { * @return The current instance of the builder * @see MongoPagingItemReader#setTargetType(Class) */ + @Override public MongoPagingItemReaderBuilder targetType(Class targetType) { this.targetType = targetType; @@ -137,6 +145,7 @@ public MongoPagingItemReaderBuilder targetType(Class targetType) * @return The current instance of the builder * @see MongoPagingItemReader#setParameterValues(List) */ + @Override public MongoPagingItemReaderBuilder parameterValues(List parameterValues) { this.parameterValues = parameterValues; @@ -149,6 +158,7 @@ public MongoPagingItemReaderBuilder parameterValues(List parameterVal * @return The current instance of the builder * @see MongoPagingItemReader#setParameterValues(List) */ + @Override public MongoPagingItemReaderBuilder parameterValues(Object... parameterValues) { return parameterValues(Arrays.asList(parameterValues)); } @@ -159,6 +169,7 @@ public MongoPagingItemReaderBuilder parameterValues(Object... parameterValues * @return The current instance of the builder * @see MongoPagingItemReader#setFields(String) */ + @Override public MongoPagingItemReaderBuilder fields(String fields) { this.fields = fields; @@ -173,6 +184,7 @@ public MongoPagingItemReaderBuilder fields(String fields) { * @return The current instance of the builder * @see MongoPagingItemReader#setSort(Map) */ + @Override public MongoPagingItemReaderBuilder sorts(Map sorts) { this.sorts = sorts; @@ -185,6 +197,7 @@ public MongoPagingItemReaderBuilder sorts(Map sorts) * @return The current instance of the builder * @see MongoPagingItemReader#setCollection(String) */ + @Override public MongoPagingItemReaderBuilder collection(String collection) { this.collection = collection; @@ -197,6 +210,7 @@ public MongoPagingItemReaderBuilder collection(String collection) { * @return The current instance of the builder * @see MongoPagingItemReader#setHint(String) */ + @Override public MongoPagingItemReaderBuilder hint(String hint) { this.hint = hint; @@ -209,6 +223,7 @@ public MongoPagingItemReaderBuilder hint(String hint) { * @return this instance for method chaining * @see MongoPagingItemReader#setPageSize(int) */ + @Override public MongoPagingItemReaderBuilder pageSize(int pageSize) { this.pageSize = pageSize; @@ -222,6 +237,7 @@ public MongoPagingItemReaderBuilder pageSize(int pageSize) { * @return this instance for method chaining * @see MongoPagingItemReader#setQuery(Query) */ + @Override public MongoPagingItemReaderBuilder query(Query query) { this.query = query; 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 92e23beb83..534339748d 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 @@ -400,8 +400,8 @@ protected void doClose() throws Exception { this.con.setAutoCommit(this.initialConnectionAutoCommit); } - if (useSharedExtendedConnection && dataSource instanceof ExtendedConnectionDataSourceProxy) { - ((ExtendedConnectionDataSourceProxy) dataSource).stopCloseSuppression(this.con); + if (useSharedExtendedConnection && dataSource instanceof ExtendedConnectionDataSourceProxy dataSourceProxy) { + dataSourceProxy.stopCloseSuppression(this.con); if (!TransactionSynchronizationManager.isActualTransactionActive()) { DataSourceUtils.releaseConnection(con, dataSource); } 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 fad274bcfc..a11ae61939 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 @@ -142,6 +142,7 @@ public boolean isCloseSuppressionActive(Connection connection) { } /** + * Start the suppression of close calls for the given connection. * @param connection the {@link Connection} that close suppression is requested for */ public void startCloseSuppression(Connection connection) { @@ -158,6 +159,7 @@ public void startCloseSuppression(Connection connection) { } /** + * Stop the suppression of close calls for the given connection. * @param connection the {@link Connection} that close suppression should be turned * off for */ 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 d99d3c9245..1662ea700d 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 @@ -165,14 +165,14 @@ public void afterPropertiesSet() throws Exception { } /** - * @param queryString JPQL query string + * Set the JPQL query string. */ public void setQueryString(String queryString) { this.queryString = queryString; } /** - * @param queryProvider JPA query provider + * Set the {@link JpaQueryProvider}. */ public void setQueryProvider(JpaQueryProvider queryProvider) { this.queryProvider = queryProvider; 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 da2bae86f5..8db7b3d2f6 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 @@ -42,14 +42,14 @@ public Query createQuery() { } /** - * @param namedQuery name of a jpa named query + * Set the name of a JPA named query. */ public void setNamedQuery(String namedQuery) { this.namedQuery = namedQuery; } /** - * @param entityClazz name of a jpa entity class + * Set the name of a JPA entity class. */ public void setEntityClass(Class entityClazz) { this.entityClass = entityClazz; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java index dc78066fc5..9d5978c3c3 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import javax.sql.DataSource; @@ -90,35 +91,35 @@ public String getGroupClause() { } /** - * @param selectClause SELECT clause part of SQL query string + * Set the SELECT clause part of SQL query string. */ public void setSelectClause(String selectClause) { this.selectClause = removeKeyWord("select", selectClause); } /** - * @return SQL SELECT clause part of SQL query string + * Return the SQL SELECT clause part of SQL query string. */ protected String getSelectClause() { return selectClause; } /** - * @param fromClause FROM clause part of SQL query string + * Set the FROM clause part of SQL query string. */ public void setFromClause(String fromClause) { this.fromClause = removeKeyWord("from", fromClause); } /** - * @return SQL FROM clause part of SQL query string + * Return the SQL FROM clause part of SQL query string. */ protected String getFromClause() { return fromClause; } /** - * @param whereClause WHERE clause part of SQL query string + * Set the WHERE clause part of SQL query string. */ public void setWhereClause(String whereClause) { if (StringUtils.hasText(whereClause)) { @@ -130,14 +131,14 @@ public void setWhereClause(String whereClause) { } /** - * @return SQL WHERE clause part of SQL query string + * Return the SQL WHERE clause part of SQL query string. */ protected String getWhereClause() { return whereClause; } /** - * @param sortKeys key to use to sort and limit page content + * Set the keys to use to sort and limit page content. */ public void setSortKeys(Map sortKeys) { this.sortKeys = sortKeys; @@ -146,7 +147,7 @@ public void setSortKeys(Map sortKeys) { /** * A Map<String, Boolean> of sort columns as the key and boolean for * ascending/descending (ascending = true). - * @return sortKey key to use to sort and limit page content + * @return keys to use to sort and limit page content */ @Override public Map getSortKeys() { @@ -214,7 +215,7 @@ public void init(DataSource dataSource) throws Exception { /** * Method generating the query string to be used for retrieving the pages following - * the first page. This method must be implemented in sub classes. + * the first page. This method must be implemented in subclasses. * @param pageSize number of rows to read per page * @return query string */ diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/Db2PagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/Db2PagingQueryProvider.java index 660eb430b9..8bafc6906f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/Db2PagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/Db2PagingQueryProvider.java @@ -45,7 +45,7 @@ public String generateRemainingPagesQuery(int pageSize) { } private String buildLimitClause(int pageSize) { - return new StringBuilder().append("FETCH FIRST ").append(pageSize).append(" ROWS ONLY").toString(); + return "FETCH FIRST " + pageSize + " ROWS ONLY"; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactory.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactory.java index ef9c279cf8..2a029afc25 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactory.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactory.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Locale; import javax.sql.DataSource; import org.springframework.batch.support.DatabaseType; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DerbyPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DerbyPagingQueryProvider.java index 015454f90e..ec640e0088 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DerbyPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DerbyPagingQueryProvider.java @@ -46,7 +46,7 @@ public String generateRemainingPagesQuery(int pageSize) { } private String buildLimitClause(int pageSize) { - return new StringBuilder("FETCH FIRST ").append(pageSize).append(" ROWS ONLY").toString(); + return "FETCH FIRST " + pageSize + " ROWS ONLY"; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/H2PagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/H2PagingQueryProvider.java index 5f358b7cd2..3de7e01f9a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/H2PagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/H2PagingQueryProvider.java @@ -38,7 +38,7 @@ public String generateRemainingPagesQuery(int pageSize) { } private String buildLimitClause(int pageSize) { - return new StringBuilder().append("FETCH NEXT ").append(pageSize).append(" ROWS ONLY").toString(); + return "FETCH NEXT " + pageSize + " ROWS ONLY"; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HanaPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HanaPagingQueryProvider.java index 54bd06d23d..c74298b300 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HanaPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HanaPagingQueryProvider.java @@ -44,7 +44,7 @@ public String generateRemainingPagesQuery(int pageSize) { } private String buildLimitClause(int pageSize) { - return new StringBuilder().append("LIMIT ").append(pageSize).toString(); + return "LIMIT " + pageSize; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HsqlPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HsqlPagingQueryProvider.java index 49e3741a4f..94d17b3257 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HsqlPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HsqlPagingQueryProvider.java @@ -46,7 +46,7 @@ public String generateRemainingPagesQuery(int pageSize) { } private String buildTopClause(int pageSize) { - return new StringBuilder().append("TOP ").append(pageSize).toString(); + return "TOP " + pageSize; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/MariaDBPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/MariaDBPagingQueryProvider.java index 25f47b1506..cdbf4eb9d2 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/MariaDBPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/MariaDBPagingQueryProvider.java @@ -44,7 +44,7 @@ public String generateRemainingPagesQuery(int pageSize) { } private String buildLimitClause(int pageSize) { - return new StringBuilder().append("LIMIT ").append(pageSize).toString(); + return "LIMIT " + pageSize; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/MySqlPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/MySqlPagingQueryProvider.java index ad2eba7cf4..0b8448d4ca 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/MySqlPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/MySqlPagingQueryProvider.java @@ -45,7 +45,7 @@ public String generateRemainingPagesQuery(int pageSize) { } private String buildLimitClause(int pageSize) { - return new StringBuilder().append("LIMIT ").append(pageSize).toString(); + return "LIMIT " + pageSize; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/OraclePagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/OraclePagingQueryProvider.java index 9958727437..5fd902821d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/OraclePagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/OraclePagingQueryProvider.java @@ -38,7 +38,7 @@ public String generateRemainingPagesQuery(int pageSize) { } private String buildRowNumClause(int pageSize) { - return new StringBuilder().append("ROWNUM <= ").append(pageSize).toString(); + return "ROWNUM <= " + pageSize; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/PostgresPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/PostgresPagingQueryProvider.java index 4b65d2e3d9..fb3406180f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/PostgresPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/PostgresPagingQueryProvider.java @@ -50,7 +50,7 @@ public String generateRemainingPagesQuery(int pageSize) { } private String buildLimitClause(int pageSize) { - return new StringBuilder().append("LIMIT ").append(pageSize).toString(); + return "LIMIT " + pageSize; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryProviderFactoryBean.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryProviderFactoryBean.java index 608e0f2e5b..48cb9c4393 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryProviderFactoryBean.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryProviderFactoryBean.java @@ -33,6 +33,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; import javax.sql.DataSource; @@ -91,49 +92,49 @@ public class SqlPagingQueryProviderFactoryBean implements FactoryBean sortKeys) { this.sortKeys = sortKeys; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProvider.java index b1c79763b1..5d0989f73d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProvider.java @@ -46,7 +46,7 @@ public String generateRemainingPagesQuery(int pageSize) { } private String buildTopClause(int pageSize) { - return new StringBuilder().append("TOP ").append(pageSize).toString(); + return "TOP " + pageSize; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProvider.java index 00e0d04711..207d99109d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProvider.java @@ -18,6 +18,8 @@ import org.springframework.util.StringUtils; +import java.util.Locale; + /** * Generic Paging Query Provider using standard SQL:2003 windowing functions. These * features are supported by DB2, Oracle, SQL Server 2005, Sybase and Apache Derby version @@ -103,11 +105,7 @@ public String generateRemainingPagesQuery(int pageSize) { } protected String getOverClause() { - StringBuilder sql = new StringBuilder(); - - sql.append(" ORDER BY ").append(buildSortClause(this)); - - return sql.toString(); + return " ORDER BY " + buildSortClause(this); } protected String getOverSubstituteClauseStart() { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlitePagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlitePagingQueryProvider.java index cc44ef6a4a..01406388a6 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlitePagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlitePagingQueryProvider.java @@ -45,7 +45,7 @@ public String generateRemainingPagesQuery(int pageSize) { } private String buildLimitClause(int pageSize) { - return new StringBuilder().append("LIMIT ").append(pageSize).toString(); + return "LIMIT " + pageSize; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SybasePagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SybasePagingQueryProvider.java index ade0af5266..26261d1246 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SybasePagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SybasePagingQueryProvider.java @@ -46,7 +46,7 @@ public String generateRemainingPagesQuery(int pageSize) { } private String buildTopClause(int pageSize) { - return new StringBuilder().append("TOP ").append(pageSize).toString(); + return "TOP " + pageSize; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/DefaultBufferedReaderFactory.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/DefaultBufferedReaderFactory.java index 01c5995509..8308f79b77 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/DefaultBufferedReaderFactory.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/DefaultBufferedReaderFactory.java @@ -22,6 +22,8 @@ import org.springframework.core.io.Resource; /** + * The default {@link BufferedReaderFactory} implementation. + * * @author Dave Syer * @author Mahmoud Ben Hassine * @since 2.1 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 c990d97708..bc380c87d1 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 @@ -19,6 +19,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -98,8 +99,7 @@ public void setStrict(boolean strict) { } /** - * @param skippedLinesCallback will be called for each one of the initial skipped - * lines before any items are read. + * Set the callback for the initially skipped lines before any items are read. */ public void setSkippedLinesCallback(LineCallbackHandler skippedLinesCallback) { this.skippedLinesCallback = skippedLinesCallback; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemReader.java index 341f4222eb..8f4048f530 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemReader.java @@ -141,8 +141,8 @@ private T readNextItem() throws Exception { private T readFromDelegate() throws Exception { T item = delegate.read(); - if (item instanceof ResourceAware) { - ((ResourceAware) item).setResource(resources[currentResource]); + if (item instanceof ResourceAware resourceAware) { + resourceAware.setResource(resources[currentResource]); } return item; } @@ -215,14 +215,14 @@ public void update(ExecutionContext executionContext) throws ItemStreamException } /** - * @param delegate reads items from single {@link Resource}. + * Set the delegate that reads items from a single {@link Resource}. */ public void setDelegate(ResourceAwareItemReaderItemStream delegate) { this.delegate = delegate; } /** - * Set the boolean indicating whether or not state should be saved in the provided + * Set the boolean indicating whether state should be saved in the provided * {@link ExecutionContext} during the {@link ItemStream} call to update. * @param saveState true to update ExecutionContext. False do not update * ExecutionContext. @@ -232,15 +232,16 @@ public void setSaveState(boolean saveState) { } /** - * @param comparator used to order the injected resources, by default compares - * {@link Resource#getFilename()} values. + * Set the {@link Comparator} used to order the injected resources. + *

+ * The default behavior compares {@link Resource#getFilename()} values. */ public void setComparator(Comparator comparator) { this.comparator = comparator; } /** - * @param resources input resources + * Set the input resources. */ public void setResources(Resource[] resources) { Assert.notNull(resources, "The resources must not be null"); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/SimpleBinaryBufferedReaderFactory.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/SimpleBinaryBufferedReaderFactory.java index 6b8fede984..ca5b0922a7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/SimpleBinaryBufferedReaderFactory.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/SimpleBinaryBufferedReaderFactory.java @@ -46,14 +46,14 @@ public class SimpleBinaryBufferedReaderFactory implements BufferedReaderFactory private String lineEnding = DEFAULT_LINE_ENDING; /** - * @param lineEnding {@link String} indicating what defines the end of a "line". + * Set the {@link String} indicating what defines the end of a "line". */ public void setLineEnding(String lineEnding) { this.lineEnding = lineEnding; } @Override - public BufferedReader create(Resource resource, String encoding) throws UnsupportedEncodingException, IOException { + public BufferedReader create(Resource resource, String encoding) throws IOException { return new BinaryBufferedReader(new InputStreamReader(resource.getInputStream(), encoding), lineEnding); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java index 1364f71445..81bfa97739 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java @@ -291,7 +291,7 @@ private String findPropertyName(Object bean, String key) { // looking for a match. if (index > 0) { prefix = key.substring(0, index); - suffix = key.substring(index + 1, key.length()); + suffix = key.substring(index + 1); String nestedName = findPropertyName(bean, prefix); if (nestedName == null) { return null; @@ -424,9 +424,7 @@ public boolean equals(Object obj) { } else if (!cls.equals(other.cls)) return false; - if (distance != other.distance) - return false; - return true; + return distance == other.distance; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/AbstractLineTokenizer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/AbstractLineTokenizer.java index 5f53e851d7..97ef0ab0d8 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/AbstractLineTokenizer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/AbstractLineTokenizer.java @@ -96,7 +96,7 @@ public void setNames(String... names) { } /** - * @return true if column names have been specified + * Return true if column names have been specified. * @see #setNames(String[]) */ public boolean hasNames() { @@ -121,7 +121,7 @@ public FieldSet tokenize(@Nullable String line) { List tokens = new ArrayList<>(doTokenize(line)); // if names are set and strict flag is false - if ((names.length != 0) && (!strict)) { + if (names.length != 0 && !strict) { adjustTokenCountIfNecessary(tokens); } 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 083839d2ca..f6a15099e6 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 @@ -37,7 +37,7 @@ public class BeanWrapperFieldExtractor implements FieldExtractor, Initiali private String[] names; /** - * @param names field names to be extracted by the {@link #extract(Object)} method. + * Set the field names to be extracted by the {@link #extract(Object)} method. */ public void setNames(String[] names) { Assert.notNull(names, "Names must be non-null"); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/ConversionException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/ConversionException.java index 1f59b0174d..e5884e3e1a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/ConversionException.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/ConversionException.java @@ -16,10 +16,13 @@ package org.springframework.batch.item.file.transform; /** + * Exception to report conversion errors. + * * @author Dave Syer * @author Mahmoud Ben Hassine * */ +@SuppressWarnings("unused") // FIXME public class ConversionException extends RuntimeException { /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSet.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSet.java index 540a8236aa..c1c1d1b489 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSet.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSet.java @@ -67,9 +67,9 @@ public class DefaultFieldSet implements FieldSet { */ public final void setNumberFormat(NumberFormat numberFormat) { this.numberFormat = numberFormat; - if (numberFormat instanceof DecimalFormat) { - grouping = String.valueOf(((DecimalFormat) numberFormat).getDecimalFormatSymbols().getGroupingSeparator()); - decimal = String.valueOf(((DecimalFormat) numberFormat).getDecimalFormatSymbols().getDecimalSeparator()); + if (numberFormat instanceof DecimalFormat decimalFormat) { + grouping = String.valueOf(decimalFormat.getDecimalFormatSymbols().getGroupingSeparator()); + decimal = String.valueOf(decimalFormat.getDecimalFormatSymbols().getDecimalSeparator()); } } @@ -533,8 +533,8 @@ private Date parseDate(String readAndTrim, DateFormat dateFormat) { } catch (ParseException e) { String pattern; - if (dateFormat instanceof SimpleDateFormat) { - pattern = ((SimpleDateFormat) dateFormat).toPattern(); + if (dateFormat instanceof SimpleDateFormat simpleDateFormat) { + pattern = simpleDateFormat.toPattern(); } else { pattern = dateFormat.toString(); 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 7fdf1fe7e6..bb14e462dd 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 @@ -168,7 +168,7 @@ else if (!isEnd) { fieldCount++; - if (isEnd && (isDelimiter)) { + if (isEnd && isDelimiter) { if (includedFields == null || includedFields.contains(fieldCount)) { tokens.add(""); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FieldExtractor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FieldExtractor.java index b9c48ce0f8..d701c58d10 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FieldExtractor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FieldExtractor.java @@ -25,6 +25,7 @@ public interface FieldExtractor { /** + * Extract the item's parts. * @param item the object that contains the information to be extracted. * @return an array containing item's parts */ diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FieldSet.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FieldSet.java index 42c9153f52..1bedfd1e8d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FieldSet.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FieldSet.java @@ -45,7 +45,7 @@ public interface FieldSet { boolean hasNames(); /** - * @return fields wrapped by this 'FieldSet' instance as String values. + * Return fields wrapped by this 'FieldSet' instance as String values. */ String[] getValues(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PassThroughFieldExtractor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PassThroughFieldExtractor.java index 98630c0216..f3b683a333 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PassThroughFieldExtractor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PassThroughFieldExtractor.java @@ -59,8 +59,8 @@ public Object[] extract(T item) { return ((Map) item).values().toArray(); } - if (item instanceof FieldSet) { - return ((FieldSet) item).getValues(); + if (item instanceof FieldSet fieldSet) { + return fieldSet.getValues(); } return new Object[] { item }; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/RangeArrayPropertyEditor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/RangeArrayPropertyEditor.java index 67afcb946c..e382bfca8c 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/RangeArrayPropertyEditor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/RangeArrayPropertyEditor.java @@ -76,12 +76,12 @@ public void setAsText(String text) throws IllegalArgumentException { int min; int max; - if ((range.length == 1) && (StringUtils.hasText(range[0]))) { + if (range.length == 1 && StringUtils.hasText(range[0])) { min = Integer.parseInt(range[0].trim()); // correct max value will be assigned later ranges[i] = new Range(min); } - else if ((range.length == 2) && (StringUtils.hasText(range[0])) && (StringUtils.hasText(range[1]))) { + else if (range.length == 2 && StringUtils.hasText(range[0]) && StringUtils.hasText(range[1])) { min = Integer.parseInt(range[0].trim()); max = Integer.parseInt(range[1].trim()); ranges[i] = new Range(min, max); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodArgumentsKeyGenerator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodArgumentsKeyGenerator.java index 7cd35de364..45669fab80 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodArgumentsKeyGenerator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodArgumentsKeyGenerator.java @@ -43,9 +43,9 @@ public class JmsMethodArgumentsKeyGenerator implements MethodArgumentsKeyGenerat @Override public Object getKey(Object[] items) { for (Object item : items) { - if (item instanceof Message) { + if (item instanceof Message message) { try { - return ((Message) item).getJMSMessageID(); + return message.getJMSMessageID(); } catch (JMSException e) { throw new UnexpectedInputException("Could not extract message ID", e); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodInvocationRecoverer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodInvocationRecoverer.java index 2afb4399eb..5383363018 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodInvocationRecoverer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsMethodInvocationRecoverer.java @@ -24,6 +24,8 @@ import org.springframework.jms.core.JmsOperations; /** + * {@link MethodInvocationRecoverer} implementation for JMS. + * * @author Dave Syer * @author Mahmoud Ben Hassine * diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsNewMethodArgumentsIdentifier.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsNewMethodArgumentsIdentifier.java index d5090673a1..6385e6d17f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsNewMethodArgumentsIdentifier.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsNewMethodArgumentsIdentifier.java @@ -42,9 +42,9 @@ public class JmsNewMethodArgumentsIdentifier implements NewMethodArgumentsIde public boolean isNew(Object[] args) { for (Object item : args) { - if (item instanceof Message) { + if (item instanceof Message message) { try { - return !((Message) item).getJMSRedelivered(); + return !message.getJMSRedelivered(); } catch (JMSException e) { throw new UnexpectedInputException("Could not extract message ID", e); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/json/GsonJsonObjectReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/json/GsonJsonObjectReader.java index c1b49fb4bd..d1bdec5e99 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/json/GsonJsonObjectReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/json/GsonJsonObjectReader.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.Charset; import com.google.gson.Gson; import com.google.gson.JsonIOException; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java index c3d3a00bbb..0fab2a7f10 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java @@ -404,14 +404,12 @@ protected class OutputState { * @throws IOException If unable to get the offset position */ public long position() throws IOException { - long pos = 0; - if (fileChannel == null) { return 0; } outputBufferedWriter.flush(); - pos = fileChannel.position(); + long pos = fileChannel.position(); if (transactional) { pos += ((TransactionAwareBufferedWriter) outputBufferedWriter).getBufferSize(); } @@ -421,14 +419,14 @@ public long position() throws IOException { } /** - * @param append if true, append to previously created file + * Set whether it should append to a previously created file. */ public void setAppendAllowed(boolean append) { this.append = append; } /** - * @param executionContext state from which to restore writing from + * Set the {@link ExecutionContext} state from which to restore writing from. */ public void restoreFrom(ExecutionContext executionContext) { lastMarkedByteOffsetPosition = executionContext.getLong(getExecutionContextKey(RESTART_DATA_NAME)); @@ -445,14 +443,14 @@ public void restoreFrom(ExecutionContext executionContext) { } /** - * @param shouldDeleteIfExists indicator + * Set whether the file should be deleted, if existing. */ public void setDeleteIfExists(boolean shouldDeleteIfExists) { this.shouldDeleteIfExists = shouldDeleteIfExists; } /** - * @param encoding file encoding + * Set the file encoding. */ public void setEncoding(String encoding) { this.encoding = encoding; @@ -510,8 +508,9 @@ private void closeStream() { } /** - * @param line String to be written to the file - * @throws IOException If unable to write the String to the file + * Write a line to the file. + * @param line line to be written + * @throws IOException If unable to write the line */ public void write(String line) throws IOException { if (!initialized) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractItemCountingItemStreamItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractItemCountingItemStreamItemReader.java index c25fc437ce..d289404c47 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractItemCountingItemStreamItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractItemCountingItemStreamItemReader.java @@ -91,8 +91,8 @@ public T read() throws Exception { } currentItemCount++; T item = doRead(); - if (item instanceof ItemCountAware) { - ((ItemCountAware) item).setItemCount(currentItemCount); + if (item instanceof ItemCountAware itemCountAware) { + itemCountAware.setItemCount(currentItemCount); } return item; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ClassifierCompositeItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ClassifierCompositeItemWriter.java index 7b82bab5e7..079ab52768 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ClassifierCompositeItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ClassifierCompositeItemWriter.java @@ -41,7 +41,7 @@ public class ClassifierCompositeItemWriter implements ItemWriter { private Classifier> classifier = new ClassifierSupport<>(null); /** - * @param classifier the classifier to set + * Set the {@link Classifier}. */ public void setClassifier(Classifier> classifier) { Assert.notNull(classifier, "A classifier is required."); 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 730213c965..74b5c64878 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 @@ -116,9 +116,9 @@ public void close() throws ItemStreamException { List exceptions = new ArrayList<>(); for (ItemWriter writer : delegates) { - if (!ignoreItemStream && (writer instanceof ItemStream)) { + if (!ignoreItemStream && (writer instanceof ItemStream itemStream)) { try { - ((ItemStream) writer).close(); + itemStream.close(); } catch (Exception e) { exceptions.add(e); @@ -137,8 +137,8 @@ public void close() throws ItemStreamException { @Override public void open(ExecutionContext executionContext) throws ItemStreamException { for (ItemWriter writer : delegates) { - if (!ignoreItemStream && (writer instanceof ItemStream)) { - ((ItemStream) writer).open(executionContext); + if (!ignoreItemStream && (writer instanceof ItemStream itemStream)) { + itemStream.open(executionContext); } } } @@ -146,8 +146,8 @@ public void open(ExecutionContext executionContext) throws ItemStreamException { @Override public void update(ExecutionContext executionContext) throws ItemStreamException { for (ItemWriter writer : delegates) { - if (!ignoreItemStream && (writer instanceof ItemStream)) { - ((ItemStream) writer).update(executionContext); + if (!ignoreItemStream && (writer instanceof ItemStream itemStream)) { + itemStream.update(executionContext); } } } 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 44e563beed..8b86d78f13 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 @@ -138,11 +138,11 @@ public void afterPropertiesSet() throws Exception { Assert.state(scriptSource == null || script == null, "Either a script source or script file must be provided, not both"); - if (scriptSource != null && scriptEvaluator instanceof StandardScriptEvaluator) { + if (scriptSource != null && scriptEvaluator instanceof StandardScriptEvaluator standardScriptEvaluator) { Assert.state(StringUtils.hasLength(language), "Language must be provided when using the default ScriptEvaluator and raw source code"); - ((StandardScriptEvaluator) scriptEvaluator).setLanguage(language); + standardScriptEvaluator.setLanguage(language); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SingleItemPeekableItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SingleItemPeekableItemReader.java index 84e751e7f6..e1d25c8f0b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SingleItemPeekableItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SingleItemPeekableItemReader.java @@ -101,10 +101,10 @@ public T peek() throws Exception { @Override public void close() throws ItemStreamException { next = null; - if (delegate instanceof ItemStream) { - ((ItemStream) delegate).close(); + if (delegate instanceof ItemStream itemStream) { + itemStream.close(); } - executionContext = new ExecutionContext(); + this.executionContext = new ExecutionContext(); } /** @@ -117,10 +117,10 @@ public void close() throws ItemStreamException { @Override public void open(ExecutionContext executionContext) throws ItemStreamException { next = null; - if (delegate instanceof ItemStream) { - ((ItemStream) delegate).open(executionContext); + if (delegate instanceof ItemStream itemStream) { + itemStream.open(executionContext); } - executionContext = new ExecutionContext(); + this.executionContext = new ExecutionContext(); } /** @@ -144,8 +144,8 @@ public void update(ExecutionContext executionContext) throws ItemStreamException } private void updateDelegate(ExecutionContext executionContext) { - if (delegate instanceof ItemStream) { - ((ItemStream) delegate).update(executionContext); + if (delegate instanceof ItemStream itemStream) { + itemStream.update(executionContext); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/util/ExecutionContextUserSupport.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/util/ExecutionContextUserSupport.java index 661ab42b88..ac9a84ea1c 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/util/ExecutionContextUserSupport.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/util/ExecutionContextUserSupport.java @@ -39,14 +39,15 @@ public ExecutionContextUserSupport(String name) { } /** - * @return name used to uniquely identify this instance's entries in shared context. + * Return the name used to uniquely identify this instance's entries in shared + * context. */ public String getName() { return this.name; } /** - * @param name unique name used to create execution context keys. + * Set the unique name used to create execution context keys. */ public void setName(String name) { this.name = name; 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 c10cb1e75c..6f2ff1196b 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 @@ -108,22 +108,23 @@ public void setResource(Resource resource) { } /** - * @param unmarshaller maps xml fragments corresponding to records to objects + * Set the unmarshaller mapping xml fragments corresponding to records to objects */ public void setUnmarshaller(Unmarshaller unmarshaller) { this.unmarshaller = unmarshaller; } /** - * @param fragmentRootElementName name of the root element of the fragment + * Set the name of the fragment's root element. + * @param fragmentRootElementName the name of the root element */ public void setFragmentRootElementName(String fragmentRootElementName) { setFragmentRootElementNames(new String[] { fragmentRootElementName }); } /** - * @param fragmentRootElementNames list of the names of the root element of the - * fragment + * Set the names of the fragment's root element. + * @param fragmentRootElementNames the names of the root element */ public void setFragmentRootElementNames(String[] fragmentRootElementNames) { this.fragmentRootElementNames = new ArrayList<>(); 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 2c6e803773..5422c96c9d 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 @@ -813,8 +813,8 @@ private long getPosition() { try { eventWriter.flush(); position = channel.position(); - if (bufferedWriter instanceof TransactionAwareBufferedWriter) { - position += ((TransactionAwareBufferedWriter) bufferedWriter).getBufferSize(); + if (bufferedWriter instanceof TransactionAwareBufferedWriter transactionAwareBufferedWriter) { + position += transactionAwareBufferedWriter.getBufferSize(); } } catch (Exception e) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/NoStartEndDocumentStreamWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/NoStartEndDocumentStreamWriter.java index cd44345f06..9879a26b43 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/NoStartEndDocumentStreamWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/stax/NoStartEndDocumentStreamWriter.java @@ -35,7 +35,7 @@ public NoStartEndDocumentStreamWriter(XMLEventWriter wrappedEventWriter) { @Override public void add(XMLEvent event) throws XMLStreamException { - if ((!event.isStartDocument()) && (!event.isEndDocument())) { + if (!event.isStartDocument() && !event.isEndDocument()) { wrappedEventWriter.add(event); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/context/RepeatContextCounter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/context/RepeatContextCounter.java index f18c193e69..84b96818da 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/context/RepeatContextCounter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/context/RepeatContextCounter.java @@ -99,7 +99,7 @@ public RepeatContextCounter(RepeatContext context, String countKey, boolean useP } /** - * @return the current value of the counter + * Return the current value of the counter. */ public int getCount() { return getCounter().intValue(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/context/SynchronizedAttributeAccessor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/context/SynchronizedAttributeAccessor.java index af6bbe8c3d..0413baa10e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/context/SynchronizedAttributeAccessor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/context/SynchronizedAttributeAccessor.java @@ -53,11 +53,11 @@ public boolean equals(Object other) { return true; } AttributeAccessorSupport that; - if (other instanceof SynchronizedAttributeAccessor) { - that = ((SynchronizedAttributeAccessor) other).support; + if (other instanceof SynchronizedAttributeAccessor synchronizedAttributeAccessor) { + that = synchronizedAttributeAccessor.support; } - else if (other instanceof AttributeAccessorSupport) { - that = (AttributeAccessorSupport) other; + else if (other instanceof AttributeAccessorSupport attributeAccessorSupport) { + that = attributeAccessorSupport; } else { return false; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptor.java index b390e7b3f2..de3df9427a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptor.java @@ -74,9 +74,9 @@ public Object invoke(final MethodInvocation invocation) throws Throwable { repeatOperations.iterate(context -> { try { - MethodInvocation clone = invocation; - if (invocation instanceof ProxyMethodInvocation) { - clone = ((ProxyMethodInvocation) invocation).invocableClone(); + MethodInvocation clone; + if (invocation instanceof ProxyMethodInvocation proxyMethodInvocation) { + clone = proxyMethodInvocation.invocableClone(); } else { throw new IllegalStateException( @@ -97,12 +97,12 @@ public Object invoke(final MethodInvocation invocation) throws Throwable { return RepeatStatus.FINISHED; } } - catch (Throwable e) { - if (e instanceof Exception) { - throw (Exception) e; + catch (Throwable t) { + if (t instanceof Exception e) { + throw e; } else { - throw new RepeatOperationsInterceptorException("Unexpected error in batch interceptor", e); + throw new RepeatOperationsInterceptorException("Unexpected error in batch interceptor", t); } } }); @@ -122,7 +122,7 @@ public Object invoke(final MethodInvocation invocation) throws Throwable { } private boolean isComplete(Object result) { - return result == null || (result instanceof Boolean) && !(Boolean) result; + return (result == null) || ((result instanceof Boolean b) && !b); } /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompletionPolicySupport.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompletionPolicySupport.java index a5acaf9358..9e375b0def 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompletionPolicySupport.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompletionPolicySupport.java @@ -73,8 +73,8 @@ public RepeatContext start(RepeatContext context) { */ @Override public void update(RepeatContext context) { - if (context instanceof RepeatContextSupport) { - ((RepeatContextSupport) context).increment(); + if (context instanceof RepeatContextSupport repeatContextSupport) { + repeatContextSupport.increment(); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java index 7b7af3fc68..1fc00e8bbb 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java @@ -309,11 +309,11 @@ private void doHandle(Throwable throwable, RepeatContext context, Collection { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java index 44dba5b449..1c024db9a6 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java @@ -96,6 +96,7 @@ public void setTaskExecutor(TaskExecutor taskExecutor) { * need to synchronize access. * */ + @SuppressWarnings("removal") @Override protected RepeatStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state) throws Throwable { @@ -153,6 +154,7 @@ protected RepeatStatus getNextResult(RepeatContext context, RepeatCallback callb * * @see org.springframework.batch.repeat.support.RepeatTemplate#waitForResults(org.springframework.batch.repeat.support.RepeatInternalState) */ + @SuppressWarnings("removal") @Override protected boolean waitForResults(RepeatInternalState state) { @@ -204,6 +206,7 @@ protected RepeatInternalState createInternalState(RepeatContext context) { * @author Dave Syer * */ + @SuppressWarnings("removal") private class ExecutingRunnable implements Runnable, ResultHolder { private final RepeatCallback callback; @@ -307,6 +310,7 @@ public RepeatContext getContext() { * @author Dave Syer * */ + @SuppressWarnings("removal") private static class ResultQueueInternalState extends RepeatInternalStateSupport { private final ResultQueue results; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueue.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueue.java index 0fd0c215c9..6637f7951b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueue.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueue.java @@ -29,6 +29,7 @@ * @author Mahmoud Ben Hassine * @deprecated since 5.0 with no replacement. Scheduled for removal in 6.0. */ +@SuppressWarnings("removal") @Deprecated(since = "5.0", forRemoval = true) public class ThrottleLimitResultQueue implements ResultQueue { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/MethodInvokerUtils.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/MethodInvokerUtils.java index b824b36aea..10603064fa 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/MethodInvokerUtils.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/MethodInvokerUtils.java @@ -116,7 +116,7 @@ public static MethodInvoker getMethodInvokerForInterface(Class cls, String me public static MethodInvoker getMethodInvokerByAnnotation(final Class annotationType, final Object target, final Class... expectedParamTypes) { MethodInvoker mi = MethodInvokerUtils.getMethodInvokerByAnnotation(annotationType, target); - final Class targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource().getTargetClass() + final Class targetClass = (target instanceof Advised advised) ? advised.getTargetSource().getTargetClass() : target.getClass(); if (mi != null) { ReflectionUtils.doWithMethods(targetClass, method -> { @@ -156,7 +156,7 @@ public static MethodInvoker getMethodInvokerByAnnotation(final Class targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource().getTargetClass() + final Class targetClass = (target instanceof Advised advised) ? advised.getTargetSource().getTargetClass() : target.getClass(); if (targetClass == null) { // Proxy with no target cannot have annotations diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/PatternMatcher.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/PatternMatcher.java index f5f5434401..c7765c99ce 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/PatternMatcher.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/PatternMatcher.java @@ -23,6 +23,8 @@ import org.springframework.util.Assert; /** + * A utility class for pattern matching. + * * @author Dave Syer * @author Dan Garrette * @author Marten Deinum @@ -46,8 +48,8 @@ public PatternMatcher(Map map) { } /** - * Lifted from AntPathMatcher in Spring Core. Tests whether or not a string matches - * against a pattern. The pattern may contain two special characters:
+ * Lifted from AntPathMatcher in Spring Core. Tests whether a string matches against a + * pattern. The pattern may contain two special characters:
* '*' means zero or more characters
* '?' means one and only one character * @param pattern pattern to match against. Must not be null. diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SimpleMethodInvoker.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SimpleMethodInvoker.java index a7d0856239..926dca6284 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SimpleMethodInvoker.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SimpleMethodInvoker.java @@ -135,7 +135,7 @@ public boolean equals(Object obj) { if (obj == this) { return true; } - return (rhs.method.equals(this.method)) && (rhs.object.equals(this.object)); + return rhs.method.equals(this.method) && rhs.object.equals(this.object); } @Override diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java index c7ffbc5e3c..3a1db67527 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java @@ -86,26 +86,26 @@ private TransactionAwareProxyFactory(T target, boolean appendOnly) { */ @SuppressWarnings({ "unchecked", "rawtypes" }) protected final T begin(T target) { - // Unfortunately in Java 5 this method has to synchronized + // Unfortunately in Java 5 this method has to be synchronized // (works OK without in Java 6). synchronized (target) { - if (target instanceof List) { + if (target instanceof List list) { if (appendOnly) { return (T) new ArrayList(); } - return (T) new ArrayList((List) target); + return (T) new ArrayList(list); } - else if (target instanceof Set) { + else if (target instanceof Set set) { if (appendOnly) { return (T) new HashSet(); } - return (T) new HashSet((Set) target); + return (T) new HashSet(set); } - else if (target instanceof Map) { + else if (target instanceof Map map) { if (appendOnly) { return (T) new HashMap(); } - return (T) new HashMap((Map) target); + return (T) new HashMap(map); } else { throw new UnsupportedOperationException("Cannot copy target for this type: " + target.getClass()); @@ -124,11 +124,11 @@ protected void commit(T copy, T target) { // Unfortunately in Java 5 this method has to be synchronized // (works OK without in Java 6). synchronized (target) { - if (target instanceof Collection) { + if (target instanceof Collection collection) { if (!appendOnly) { - ((Collection) target).clear(); + collection.clear(); } - ((Collection) target).addAll((Collection) copy); + collection.addAll((Collection) copy); } else { if (!appendOnly) { @@ -239,11 +239,11 @@ public Object invoke(MethodInvocation invocation) throws Throwable { if (appendOnly) { String methodName = invocation.getMethod().getName(); - if ((result == null && methodName.equals("get")) - || (Boolean.FALSE.equals(result) && (methodName.startsWith("contains")) + if (((result == null) && methodName.equals("get")) + || ((Boolean.FALSE.equals(result) && methodName.startsWith("contains")) || (Boolean.TRUE.equals(result) && methodName.startsWith("isEmpty")))) { - // In appendOnly mode the result of a get might not be - // in the cache... + // In appendOnly mode, the result of a get might not be in the + // cache... return invocation.proceed(); } if (result instanceof Collection) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainer.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainer.java index df3c584f8c..5fab1c2686 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainer.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainer.java @@ -103,15 +103,15 @@ protected void handleListenerException(Throwable ex) { return; } logger.debug("Re-throwing exception in container."); - if (ex instanceof RuntimeException) { + if (ex instanceof RuntimeException runtimeException) { // We need to re-throw so that an enclosing non-JMS transaction can // rollback... - throw (RuntimeException) ex; + throw runtimeException; } - else if (ex instanceof Error) { - // Just re-throw Error instances because otherwise unit tests just - // swallow exceptions from EasyMock and JUnit. - throw (Error) ex; + else if (ex instanceof Error error) { + // Just re-throw Error instances because otherwise unit tests just swallow + // exceptions from EasyMock and JUnit. + throw error; } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java index 8ad90b66b8..fdc8769288 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java @@ -121,8 +121,7 @@ void testNonTransactionalReceiveAndExecuteWithCallbackThrowingError() throws Exc private BatchMessageListenerContainer getContainer(RepeatTemplate template) { ConnectionFactory connectionFactory = mock(); // Yuck: we need to turn these method in base class to no-ops because the invoker - // is a private class - // we can't create for test purposes... + // is a private class we can't create for test purposes... BatchMessageListenerContainer container = new BatchMessageListenerContainer() { @Override protected void messageReceived(Object invoker, Session session) { @@ -141,12 +140,12 @@ protected void noMessageReceived(Object invoker, Session session) { return container; } - private boolean doTestWithException(final Throwable t, boolean expectRollback, int expectGetTransactionCount) + private boolean doTestWithException(Throwable t, boolean expectRollback, int expectGetTransactionCount) throws JMSException, IllegalAccessException { container.setAcceptMessagesWhileStopping(true); container.setMessageListener((MessageListener) arg0 -> { - if (t instanceof RuntimeException) - throw (RuntimeException) t; + if (t instanceof RuntimeException runtimeException) + throw runtimeException; else throw (Error) t; }); @@ -159,16 +158,14 @@ private boolean doTestWithException(final Throwable t, boolean expectRollback, i when(session.getTransacted()).thenReturn(true); } - // Expect only one call to consumer (chunk size is 2, but first one - // rolls back terminating batch)... + // Expect only one call to consumer (chunk size is 2, but first one rolls back + // terminating batch)... when(consumer.receive(1000)).thenReturn(message); if (expectRollback) { session.rollback(); } - boolean received = doExecute(session, consumer); - - return received; + return doExecute(session, consumer); } private boolean doExecute(Session session, MessageConsumer consumer) throws IllegalAccessException { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/example/User.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/example/User.java index 0416ff9ec8..d1acddb9ca 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/example/User.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/example/User.java @@ -119,15 +119,18 @@ public User(CharSequence name, Integer favorite_number, CharSequence favorite_co this.favorite_color = favorite_color; } + @Override public SpecificData getSpecificData() { return MODEL$; } + @Override public org.apache.avro.Schema getSchema() { return SCHEMA$; } // Used by DatumWriter. Applications should not call. + @Override public Object get(int field$) { return switch (field$) { case 0 -> name; @@ -138,7 +141,7 @@ public Object get(int field$) { } // Used by DatumReader. Applications should not call. - @SuppressWarnings(value = "unchecked") + @Override public void put(int field$, Object value$) { switch (field$) { case 0 -> name = (CharSequence) value$; @@ -515,8 +518,7 @@ public void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io. this.favorite_color = null; } else { - this.favorite_color = in - .readString(this.favorite_color instanceof Utf8 ? (Utf8) this.favorite_color : null); + this.favorite_color = in.readString(this.favorite_color instanceof Utf8 utf8 ? utf8 : null); } } default -> throw new java.io.IOException("Corrupt ResolvingDecoder."); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoCursorItemReaderTest.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoCursorItemReaderTest.java index 8cb6bf84c7..f76f0fed13 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoCursorItemReaderTest.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoCursorItemReaderTest.java @@ -204,7 +204,7 @@ void testQueryWithLimit() throws Exception { @Test void testQueryWithMaxTime() throws Exception { - reader.setMaxTime(Duration.ofMillis(3000)); + reader.setMaxTime(Duration.ofSeconds(3)); ArgumentCaptor queryContainer = ArgumentCaptor.forClass(Query.class); when(template.stream(queryContainer.capture(), eq(String.class))).thenReturn(Stream.of()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoCursorItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoCursorItemReaderBuilderTests.java index f8dcfa6e32..94937673e4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoCursorItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoCursorItemReaderBuilderTests.java @@ -45,7 +45,7 @@ void testBuild() { Map sorts = mock(); int batchSize = 100; int limit = 10000; - Duration maxTime = Duration.ofMillis(1000); + Duration maxTime = Duration.ofSeconds(1); // when MongoCursorItemReader reader = new MongoCursorItemReaderBuilder().name("reader") diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaNativeQueryProviderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaNativeQueryProviderIntegrationTests.java index 959db5e22e..f8373e7de4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaNativeQueryProviderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaNativeQueryProviderIntegrationTests.java @@ -71,7 +71,7 @@ void shouldRetrieveAndMapAllFoos() throws Exception { @SuppressWarnings("unchecked") List actualFoos = query.getResultList(); - assertEquals(actualFoos, expectedFoos); + assertEquals(expectedFoos, actualFoos); } @Test @@ -96,7 +96,7 @@ void shouldExecuteParameterizedQuery() throws Exception { @SuppressWarnings("unchecked") List actualFoos = query.getResultList(); - assertEquals(actualFoos, expectedFoos); + assertEquals(expectedFoos, actualFoos); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/SimpleBinaryBufferedReaderFactoryTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/SimpleBinaryBufferedReaderFactoryTests.java index 202fcc6476..49700060bc 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/SimpleBinaryBufferedReaderFactoryTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/SimpleBinaryBufferedReaderFactoryTests.java @@ -93,7 +93,7 @@ void testCreateWithFalseMixedCharacterLineEnding() throws Exception { SimpleBinaryBufferedReaderFactory factory = new SimpleBinaryBufferedReaderFactory(); factory.setLineEnding("#@"); @SuppressWarnings("resource") - BufferedReader reader = factory.create(new ByteArrayResource(("a##@").getBytes()), "UTF-8"); + BufferedReader reader = factory.create(new ByteArrayResource("a##@".getBytes()), "UTF-8"); assertEquals("a#", reader.readLine()); assertNull(reader.readLine()); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java index e6c6f6c2de..d1890ef383 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java @@ -44,6 +44,7 @@ import org.springframework.test.util.ReflectionTestUtils; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -579,15 +580,16 @@ record Person(int id, String name) { // then Object lineMapper = ReflectionTestUtils.getField(reader, "lineMapper"); assertNotNull(lineMapper); - assertTrue(lineMapper instanceof DefaultLineMapper); + assertInstanceOf(DefaultLineMapper.class, lineMapper); Object fieldSetMapper = ReflectionTestUtils.getField(lineMapper, "fieldSetMapper"); assertNotNull(fieldSetMapper); - assertTrue(fieldSetMapper instanceof RecordFieldSetMapper); + assertInstanceOf(RecordFieldSetMapper.class, fieldSetMapper); } @Test void testSetupWithClassTargetType() { // given + @SuppressWarnings("unused") class Person { int id; @@ -607,10 +609,10 @@ class Person { // then Object lineMapper = ReflectionTestUtils.getField(reader, "lineMapper"); assertNotNull(lineMapper); - assertTrue(lineMapper instanceof DefaultLineMapper); + assertInstanceOf(DefaultLineMapper.class, lineMapper); Object fieldSetMapper = ReflectionTestUtils.getField(lineMapper, "fieldSetMapper"); assertNotNull(fieldSetMapper); - assertTrue(fieldSetMapper instanceof BeanWrapperFieldSetMapper); + assertInstanceOf(BeanWrapperFieldSetMapper.class, fieldSetMapper); } private Resource getResource(String contents) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilderTests.java index 0b37305559..ad8083c4d2 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilderTests.java @@ -38,6 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -347,16 +348,18 @@ record Person(int id, String name) { // then Object lineAggregator = ReflectionTestUtils.getField(writer, "lineAggregator"); assertNotNull(lineAggregator); - assertTrue(lineAggregator instanceof DelimitedLineAggregator); + assertInstanceOf(DelimitedLineAggregator.class, lineAggregator); Object fieldExtractor = ReflectionTestUtils.getField(lineAggregator, "fieldExtractor"); assertNotNull(fieldExtractor); - assertTrue(fieldExtractor instanceof RecordFieldExtractor); + assertInstanceOf(RecordFieldExtractor.class, fieldExtractor); } @Test void testSetupDelimitedLineAggregatorWithClassItemType() throws IOException { // given WritableResource output = new FileSystemResource(File.createTempFile("foo", "txt")); + + @SuppressWarnings("unused") class Person { int id; @@ -376,10 +379,10 @@ class Person { // then Object lineAggregator = ReflectionTestUtils.getField(writer, "lineAggregator"); assertNotNull(lineAggregator); - assertTrue(lineAggregator instanceof DelimitedLineAggregator); + assertInstanceOf(DelimitedLineAggregator.class, lineAggregator); Object fieldExtractor = ReflectionTestUtils.getField(lineAggregator, "fieldExtractor"); assertNotNull(fieldExtractor); - assertTrue(fieldExtractor instanceof BeanWrapperFieldExtractor); + assertInstanceOf(BeanWrapperFieldExtractor.class, fieldExtractor); } @Test @@ -388,7 +391,7 @@ void testSetupDelimitedLineAggregatorWithNoItemType() throws IOException { WritableResource output = new FileSystemResource(File.createTempFile("foo", "txt")); // when - FlatFileItemWriter writer = new FlatFileItemWriterBuilder<>().name("personWriter") + FlatFileItemWriter writer = new FlatFileItemWriterBuilder<>().name("personWriter") .resource(output) .delimited() .names("id", "name") @@ -397,10 +400,10 @@ void testSetupDelimitedLineAggregatorWithNoItemType() throws IOException { // then Object lineAggregator = ReflectionTestUtils.getField(writer, "lineAggregator"); assertNotNull(lineAggregator); - assertTrue(lineAggregator instanceof DelimitedLineAggregator); + assertInstanceOf(DelimitedLineAggregator.class, lineAggregator); Object fieldExtractor = ReflectionTestUtils.getField(lineAggregator, "fieldExtractor"); assertNotNull(fieldExtractor); - assertTrue(fieldExtractor instanceof BeanWrapperFieldExtractor); + assertInstanceOf(BeanWrapperFieldExtractor.class, fieldExtractor); } @Test @@ -422,16 +425,18 @@ record Person(int id, String name) { // then Object lineAggregator = ReflectionTestUtils.getField(writer, "lineAggregator"); assertNotNull(lineAggregator); - assertTrue(lineAggregator instanceof FormatterLineAggregator); + assertInstanceOf(FormatterLineAggregator.class, lineAggregator); Object fieldExtractor = ReflectionTestUtils.getField(lineAggregator, "fieldExtractor"); assertNotNull(fieldExtractor); - assertTrue(fieldExtractor instanceof RecordFieldExtractor); + assertInstanceOf(RecordFieldExtractor.class, fieldExtractor); } @Test void testSetupFormatterLineAggregatorWithClassItemType() throws IOException { // given WritableResource output = new FileSystemResource(File.createTempFile("foo", "txt")); + + @SuppressWarnings("unused") class Person { int id; @@ -452,10 +457,10 @@ class Person { // then Object lineAggregator = ReflectionTestUtils.getField(writer, "lineAggregator"); assertNotNull(lineAggregator); - assertTrue(lineAggregator instanceof FormatterLineAggregator); + assertInstanceOf(FormatterLineAggregator.class, lineAggregator); Object fieldExtractor = ReflectionTestUtils.getField(lineAggregator, "fieldExtractor"); assertNotNull(fieldExtractor); - assertTrue(fieldExtractor instanceof BeanWrapperFieldExtractor); + assertInstanceOf(BeanWrapperFieldExtractor.class, fieldExtractor); } @Test @@ -474,10 +479,10 @@ void testSetupFormatterLineAggregatorWithNoItemType() throws IOException { // then Object lineAggregator = ReflectionTestUtils.getField(writer, "lineAggregator"); assertNotNull(lineAggregator); - assertTrue(lineAggregator instanceof FormatterLineAggregator); + assertInstanceOf(FormatterLineAggregator.class, lineAggregator); Object fieldExtractor = ReflectionTestUtils.getField(lineAggregator, "fieldExtractor"); assertNotNull(fieldExtractor); - assertTrue(fieldExtractor instanceof BeanWrapperFieldExtractor); + assertInstanceOf(BeanWrapperFieldExtractor.class, fieldExtractor); } private void validateBuilderFlags(FlatFileItemWriter writer, String encoding) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandlerTests.java index e064c604c5..d5cd02e00c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandlerTests.java @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -152,19 +154,14 @@ void testExceptionNotThrownBelowLimit() throws Throwable { handler.setLimit(EXCEPTION_LIMIT); handler.afterPropertiesSet(); - @SuppressWarnings("serial") - List throwables = new ArrayList<>() { - { - for (int i = 0; i < (EXCEPTION_LIMIT); i++) { - add(new RuntimeException("below exception limit")); - } - } - }; + List exceptions = IntStream.range(0, EXCEPTION_LIMIT) + .mapToObj(__ -> new RuntimeException("below exception limit")) + .toList(); RepeatContextSupport context = new RepeatContextSupport(null); - for (Throwable throwable : throwables) { - assertDoesNotThrow(() -> handler.handleException(context, throwable)); + for (RuntimeException exception : exceptions) { + assertDoesNotThrow(() -> handler.handleException(context, exception)); } } @@ -180,22 +177,17 @@ void testExceptionThrownAboveLimit() throws Throwable { handler.setLimit(EXCEPTION_LIMIT); handler.afterPropertiesSet(); - @SuppressWarnings("serial") - List throwables = new ArrayList<>() { - { - for (int i = 0; i < (EXCEPTION_LIMIT); i++) { - add(new RuntimeException("below exception limit")); - } - } - }; + List exceptions = IntStream.range(0, EXCEPTION_LIMIT) + .mapToObj(__ -> new RuntimeException("below exception limit")) + .collect(Collectors.toCollection(ArrayList::new)); - throwables.add(new RuntimeException("above exception limit")); + exceptions.add(new RuntimeException("above exception limit")); RepeatContextSupport context = new RepeatContextSupport(null); Exception expected = assertThrows(RuntimeException.class, () -> { - for (Throwable throwable : throwables) { - handler.handleException(context, throwable); + for (Throwable exception : exceptions) { + handler.handleException(context, exception); } }); assertEquals("above exception limit", expected.getMessage()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/ConcurrentTransactionAwareProxyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/ConcurrentTransactionAwareProxyTests.java index baef448a31..ba3480023b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/ConcurrentTransactionAwareProxyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/ConcurrentTransactionAwareProxyTests.java @@ -108,7 +108,7 @@ void testConcurrentTransactionalMap() { @Test void testTransactionalContains() { final Map> map = TransactionAwareProxyFactory.createAppendOnlyTransactionalMap(); - boolean result = new TransactionTemplate(transactionManager).execute(status -> map.containsKey("foo")); + boolean result = new TransactionTemplate(transactionManager).execute(status -> map.containsKey(0L)); assertFalse(result); } diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkHandlerFactoryBean.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkHandlerFactoryBean.java index 9def1ae7c3..882607fce5 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkHandlerFactoryBean.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkHandlerFactoryBean.java @@ -139,8 +139,8 @@ public ChunkHandler getObject() throws Exception { + "] because it already has a remote chunk writer. Use a local writer in the step."); replaceChunkProcessor((ChunkOrientedTasklet) tasklet, chunkWriter, stepContributionSource); - if (chunkWriter instanceof StepExecutionListener) { - step.registerStepExecutionListener((StepExecutionListener) chunkWriter); + if (chunkWriter instanceof StepExecutionListener stepExecutionListener) { + step.registerStepExecutionListener(stepExecutionListener); } ChunkProcessorChunkHandler handler = new ChunkProcessorChunkHandler<>(); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/samples/chunking/ManagerConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/samples/chunking/ManagerConfiguration.java index d4e53aa5df..61e54f8ed6 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/samples/chunking/ManagerConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/samples/chunking/ManagerConfiguration.java @@ -110,7 +110,7 @@ public ListItemReader itemReader() { @Bean public TaskletStep managerStep() { return this.managerStepBuilderFactory.get("managerStep") - .chunk(3) + .chunk(3) .reader(itemReader()) .outputChannel(requests()) .inputChannel(replies()) diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/compositewriter/CompositeItemWriterSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/compositewriter/CompositeItemWriterSampleFunctionalTests.java index 5b909167da..1f49b10b23 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/compositewriter/CompositeItemWriterSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/compositewriter/CompositeItemWriterSampleFunctionalTests.java @@ -74,15 +74,12 @@ void testJobLaunch() throws Exception { } private void checkOutputTable(int before) { - final List trades = new ArrayList<>() { - { - add(new Trade("UK21341EAH41", 211, new BigDecimal("31.11"), "customer1")); - add(new Trade("UK21341EAH42", 212, new BigDecimal("32.11"), "customer2")); - add(new Trade("UK21341EAH43", 213, new BigDecimal("33.11"), "customer3")); - add(new Trade("UK21341EAH44", 214, new BigDecimal("34.11"), "customer4")); - add(new Trade("UK21341EAH45", 215, new BigDecimal("35.11"), "customer5")); - } - }; + final List trades = List.of( // + new Trade("UK21341EAH41", 211, new BigDecimal("31.11"), "customer1"), + new Trade("UK21341EAH42", 212, new BigDecimal("32.11"), "customer2"), + new Trade("UK21341EAH43", 213, new BigDecimal("33.11"), "customer3"), + new Trade("UK21341EAH44", 214, new BigDecimal("34.11"), "customer4"), + new Trade("UK21341EAH45", 215, new BigDecimal("35.11"), "customer5")); int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE"); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/file/PartitionFileJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/file/PartitionFileJobFunctionalTests.java index 7b02c19379..2e9b5246b3 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/file/PartitionFileJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/file/PartitionFileJobFunctionalTests.java @@ -85,7 +85,6 @@ void testUpdateCredit() throws Exception { int itemCount = inputs.size(); assertTrue(itemCount > 0, "No entries were available in the input"); - inputs.iterator(); for (int i = 0; i < itemCount; i++) { assertEquals(inputs.get(i).getCredit().add(CustomerCreditIncreaseProcessor.FIXED_AMOUNT).intValue(), outputs.get(i).getCredit().intValue()); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/jdbc/PartitionJdbcJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/jdbc/PartitionJdbcJobFunctionalTests.java index 97719a96d7..cfddee187f 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/jdbc/PartitionJdbcJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/jdbc/PartitionJdbcJobFunctionalTests.java @@ -85,7 +85,6 @@ void testUpdateCredit() throws Exception { int itemCount = inputs.size(); assertTrue(itemCount > 0, "Input from reader has no entries."); - inputs.iterator(); for (int i = 0; i < itemCount; i++) { assertEquals(inputs.get(i).getCredit().add(CustomerCreditIncreaseProcessor.FIXED_AMOUNT).intValue(), outputs.get(i).getCredit().intValue()); diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java index 3887f71ec1..5e74ded039 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java @@ -16,6 +16,7 @@ package org.springframework.batch.test; import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.List; @@ -82,7 +83,7 @@ void testRemoveJobExecutionsWithSameJobInstance() throws Exception { utils = new JobRepositoryTestUtils(jobRepository); List list = new ArrayList<>(); JobExecution jobExecution = jobRepository.createJobExecution("job", new JobParameters()); - jobExecution.setEndTime(LocalDateTime.now()); + jobExecution.setEndTime(LocalDateTime.now(ZoneId.systemDefault())); jobExecution.setStatus(BatchStatus.COMPLETED); list.add(jobExecution); jobRepository.update(jobExecution); diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/jmx/SimpleMessageApplicationEvent.java b/spring-batch-test/src/test/java/org/springframework/batch/test/jmx/SimpleMessageApplicationEvent.java index fd92280d7e..e4a48b9d9e 100755 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/jmx/SimpleMessageApplicationEvent.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/jmx/SimpleMessageApplicationEvent.java @@ -20,10 +20,9 @@ /** * @author Dave Syer * @author Mahmoud Ben Hassine - * */ @SuppressWarnings("serial") -public class SimpleMessageApplicationEvent extends ApplicationEvent { +class SimpleMessageApplicationEvent extends ApplicationEvent { private final String message;