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

@@ -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);