Fix compiler warnings

- Add `@Nullable` where needed
- Suppress warnings where appropriate
- Add generic type definitions
This commit is contained in:
Mahmoud Ben Hassine
2023-07-12 20:55:18 +02:00
parent f4c663c452
commit 4763480c57
12 changed files with 22 additions and 8 deletions

View File

@@ -153,6 +153,7 @@ public class DefaultJobParametersConverter implements JobParametersConverter {
* @param encodedJobParameter the encoded job parameter
* @return the decoded job parameter
*/
@SuppressWarnings(value = { "unchecked", "rawtypes" })
protected JobParameter<?> decode(String encodedJobParameter) {
String parameterStringValue = parseValue(encodedJobParameter);
Class<?> parameterType = parseType(encodedJobParameter);

View File

@@ -100,6 +100,7 @@ public class JsonJobParametersConverter extends DefaultJobParametersConverter {
}
}
@SuppressWarnings(value = { "unchecked", "rawtypes" })
@Override
protected JobParameter decode(String encodedJobParameter) {
try {

View File

@@ -212,6 +212,7 @@ public class Jackson2ExecutionContextStringSerializer implements ExecutionContex
super(JobParameter.class);
}
@SuppressWarnings(value = { "unchecked", "rawtypes" })
@Override
public JobParameter deserialize(JsonParser parser, DeserializationContext context) throws IOException {
JsonNode node = parser.readValueAsTree();

View File

@@ -414,6 +414,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
* Convenience method that inserts all parameters from the provided JobParameters.
*
*/
@SuppressWarnings(value = { "unchecked", "rawtypes" })
private void insertJobParameters(Long executionId, JobParameters jobParameters) {
if (jobParameters.isEmpty()) {
@@ -450,6 +451,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
* @param executionId {@link Long} containing the id for the execution.
* @return job parameters for the requested execution id
*/
@SuppressWarnings(value = { "unchecked", "rawtypes" })
protected JobParameters getJobParameters(Long executionId) {
final Map<String, JobParameter<?>> map = new HashMap<>();
RowCallbackHandler handler = rs -> {

View File

@@ -189,6 +189,7 @@ public class FaultTolerantStepBuilder<I, O> extends SimpleStepBuilder<I, O> {
* @param listener the object that has a method configured with listener annotation
* @return this for fluent chaining
*/
@SuppressWarnings("unchecked")
@Override
public FaultTolerantStepBuilder<I, O> listener(Object listener) {
super.listener(listener);
@@ -201,7 +202,7 @@ public class FaultTolerantStepBuilder<I, O> extends SimpleStepBuilder<I, O> {
if (skipListenerMethods.size() > 0) {
StepListenerFactoryBean factory = new StepListenerFactoryBean();
factory.setDelegate(listener);
skipListeners.add((SkipListener) factory.getObject());
skipListeners.add((SkipListener<I, O>) factory.getObject());
}
return this;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.lang.Nullable;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.Assert;
@@ -113,6 +114,7 @@ public class MongoItemWriter<T> implements ItemWriter<T>, InitializingBean {
*
* @see org.springframework.batch.item.ItemWriter#write(Chunk)
*/
@SuppressWarnings(value = { "unchecked", "rawtypes" })
@Override
public void write(Chunk<? extends T> chunk) throws Exception {
if (!transactionActive()) {
@@ -184,6 +186,8 @@ public class MongoItemWriter<T> implements ItemWriter<T>, InitializingBean {
return TransactionSynchronizationManager.isActualTransactionActive();
}
@SuppressWarnings("unchecked")
@Nullable
private Chunk<T> getCurrentBuffer() {
if (!TransactionSynchronizationManager.hasResource(bufferKey)) {
TransactionSynchronizationManager.bindResource(bufferKey, new Chunk<T>());

View File

@@ -99,6 +99,7 @@ public class RepositoryItemWriterBuilder<T> {
* Builds the {@link RepositoryItemWriter}.
* @return a {@link RepositoryItemWriter}
*/
@SuppressWarnings("unchecked")
public RepositoryItemWriter<T> build() {
if (this.repositoryMethodReference != null) {
this.methodName = this.repositoryMethodReference.getMethodName();

View File

@@ -91,7 +91,7 @@ public class FlatFileItemReaderBuilder<T> {
private FixedLengthBuilder<T> fixedLengthBuilder;
private Class<? extends T> targetType;
private Class<T> targetType;
private String prototypeBeanName;
@@ -339,7 +339,7 @@ public class FlatFileItemReaderBuilder<T> {
* @return The current instance of the builder.
* @see BeanWrapperFieldSetMapper#setTargetType(Class)
*/
public FlatFileItemReaderBuilder<T> targetType(Class<? extends T> targetType) {
public FlatFileItemReaderBuilder<T> targetType(Class<T> targetType) {
this.targetType = targetType;
return this;
}
@@ -461,7 +461,7 @@ public class FlatFileItemReaderBuilder<T> {
if (this.targetType != null || StringUtils.hasText(this.prototypeBeanName)) {
if (this.targetType != null && this.targetType.isRecord()) {
RecordFieldSetMapper<T> mapper = new RecordFieldSetMapper(this.targetType);
RecordFieldSetMapper<T> mapper = new RecordFieldSetMapper<>(this.targetType);
lineMapper.setFieldSetMapper(mapper);
}
else {

View File

@@ -163,6 +163,7 @@ public class KafkaItemReader<K, V> extends AbstractItemStreamItemReader<V> {
this.partitionOffsets = partitionOffsets;
}
@SuppressWarnings("unchecked")
@Override
public void open(ExecutionContext executionContext) {
this.kafkaConsumer = new KafkaConsumer<>(this.consumerProperties);

View File

@@ -99,6 +99,7 @@ public class ChunkProcessorChunkHandler<S> implements ChunkHandler<S>, Initializ
* @param stepContribution the step contribution to update
* @throws Exception if there is a fatal exception
*/
@SuppressWarnings(value = { "unchecked", "rawtypes" })
private Throwable process(ChunkRequest<S> chunkRequest, StepContribution stepContribution) throws Exception {
Chunk chunk = chunkRequest.getItems();

View File

@@ -34,7 +34,7 @@ import org.springframework.transaction.PlatformTransactionManager;
* @author Mahmoud Ben Hassine
*/
@Configuration(proxyBeanMethods = false)
public class BatchIntegrationConfiguration implements InitializingBean {
public class BatchIntegrationConfiguration<I, O> implements InitializingBean {
private final JobExplorer jobExplorer;
@@ -44,7 +44,7 @@ public class BatchIntegrationConfiguration implements InitializingBean {
private RemoteChunkingManagerStepBuilderFactory remoteChunkingManagerStepBuilderFactory;
private RemoteChunkingWorkerBuilder remoteChunkingWorkerBuilder;
private RemoteChunkingWorkerBuilder<I, O> remoteChunkingWorkerBuilder;
private RemotePartitioningManagerStepBuilderFactory remotePartitioningManagerStepBuilderFactory;
@@ -65,7 +65,7 @@ public class BatchIntegrationConfiguration implements InitializingBean {
}
@Bean
public <I, O> RemoteChunkingWorkerBuilder<I, O> remoteChunkingWorkerBuilder() {
public RemoteChunkingWorkerBuilder<I, O> remoteChunkingWorkerBuilder() {
return remoteChunkingWorkerBuilder;
}

View File

@@ -286,6 +286,7 @@ public class MessageChannelPartitionHandler extends AbstractPartitionHandler imp
}
}
@SuppressWarnings("unchecked")
private Set<StepExecution> receiveReplies(PollableChannel currentReplyChannel) {
Message<Set<StepExecution>> message = (Message<Set<StepExecution>>) messagingGateway
.receive(currentReplyChannel);