fix build warnings

This commit is contained in:
Mahmoud Ben Hassine
2018-08-10 12:02:23 +02:00
parent e5ac0e9975
commit 76c34c7f72
26 changed files with 71 additions and 42 deletions

View File

@@ -51,7 +51,7 @@ public class DefaultBatchConfigurer implements BatchConfigurer {
* values are passed are ignored (to prevent {@code}@Autowired{@code} from overwriting
* the value).
*
* @param dataSource
* @param dataSource The data source to use
*/
@Autowired(required = false)
public void setDataSource(DataSource dataSource) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,6 @@ import org.springframework.batch.core.repository.dao.JdbcStepExecutionDao;
import org.springframework.batch.core.repository.dao.JobExecutionDao;
import org.springframework.batch.core.repository.dao.JobInstanceDao;
import org.springframework.batch.core.repository.dao.StepExecutionDao;
import org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
@@ -47,6 +46,7 @@ import org.springframework.util.Assert;
* to describe what kind of database they are using.
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
* @since 2.0
*/
public class JobExplorerFactoryBean extends AbstractJobExplorerFactoryBean
@@ -71,7 +71,7 @@ implements InitializingBean {
/**
* A custom implementation of the {@link ExecutionContextSerializer}.
* The default, if not injected, is the {@link XStreamExecutionContextStringSerializer}.
* The default, if not injected, is the {@link Jackson2ExecutionContextStringSerializer}.
*
* @param serializer used to serialize/deserialize an {@link org.springframework.batch.item.ExecutionContext}
* @see ExecutionContextSerializer
@@ -124,7 +124,7 @@ implements InitializingBean {
Assert.notNull(dataSource, "DataSource must not be null.");
if (jdbcOperations == null) {
jdbcOperations = new JdbcTemplate(dataSource);
jdbcOperations = new JdbcTemplate(dataSource);
}
if(serializer == null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2018 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.
@@ -248,10 +248,10 @@ class SpringAutowiredAnnotationBeanPostProcessor extends InstantiationAwareBeanP
if (requiredConstructor == null && defaultConstructor != null) {
candidates.add(defaultConstructor);
}
candidateConstructors = candidates.toArray(new Constructor[candidates.size()]);
candidateConstructors = candidates.toArray(new Constructor<?>[candidates.size()]);
}
else {
candidateConstructors = new Constructor[0];
candidateConstructors = new Constructor<?>[0];
}
this.candidateConstructorsCache.put(beanClass, candidateConstructors);
}

View File

@@ -47,7 +47,7 @@ public class RunIdIncrementer implements JobParametersIncrementer {
JobParameters params = (parameters == null) ? new JobParameters() : parameters;
long id = params.getLong(key, 0L) + 1;
long id = params.getLong(key, new Long(0)) + 1;
return new JobParametersBuilder(params).addLong(key, id).toJobParameters();
}

View File

@@ -23,7 +23,6 @@ import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.partition.PartitionHandler;
import org.springframework.batch.core.step.StepHolder;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.core.task.TaskRejectedException;
@@ -55,6 +54,7 @@ public class TaskExecutorPartitionHandler extends AbstractPartitionHandler imple
@Override
public void afterPropertiesSet() throws Exception {
Assert.state(step != null, "A Step must be provided.");
}
/**
@@ -74,7 +74,6 @@ public class TaskExecutorPartitionHandler extends AbstractPartitionHandler imple
*
* @param step the {@link Step} instance to use to execute business logic
*/
@Required
public void setStep(Step step) {
this.step = step;
}

View File

@@ -85,6 +85,8 @@ public class Jackson2ExecutionContextStringSerializer implements ExecutionContex
*/
private class JobParametersModule extends SimpleModule {
private static final long serialVersionUID = 1L;
private JobParametersModule() {
super("Job parameters module");
setMixInAnnotation(JobParameters.class, JobParametersMixIn.class);
@@ -98,6 +100,7 @@ public class Jackson2ExecutionContextStringSerializer implements ExecutionContex
private class JobParameterDeserializer extends StdDeserializer<JobParameter> {
private static final long serialVersionUID = 1L;
private static final String IDENTIFYING_KEY_NAME = "identifying";
private static final String TYPE_KEY_NAME = "type";
private static final String VALUE_KEY_NAME = "value";

View File

@@ -76,6 +76,20 @@ public class TaskExecutorPartitionHandlerTests {
handler.afterPropertiesSet();
}
@Test
public void testConfiguration() throws Exception {
handler = new TaskExecutorPartitionHandler();
try {
handler.afterPropertiesSet();
fail("Expected IllegalStateException when no step is set");
}
catch (IllegalStateException e) {
// expected
String message = e.getMessage();
assertEquals("Wrong message: " + message, "A Step must be provided.", message);
}
}
@Test
public void testNullStep() throws Exception {
handler = new TaskExecutorPartitionHandler();

View File

@@ -28,6 +28,7 @@ public class XStreamExecutionContextStringSerializerTests extends AbstractExecut
@Before
public void onSetUp() throws Exception {
@SuppressWarnings("deprecation")
XStreamExecutionContextStringSerializer serializerDeserializer = new XStreamExecutionContextStringSerializer();
(serializerDeserializer).afterPropertiesSet();

View File

@@ -118,7 +118,7 @@ public class StepBuilderTests {
StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step");
jobRepository.add(execution);
PlatformTransactionManager transactionManager = new ResourcelessTransactionManager();
SimpleStepBuilder builder = new StepBuilder("step")
SimpleStepBuilder<Object, Object> builder = new StepBuilder("step")
.repository(jobRepository)
.transactionManager(transactionManager)
.chunk(5)
@@ -137,7 +137,7 @@ public class StepBuilderTests {
StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step");
jobRepository.add(execution);
PlatformTransactionManager transactionManager = new ResourcelessTransactionManager();
SimpleStepBuilder builder = new StepBuilder("step")
SimpleStepBuilder<Object, Object> builder = new StepBuilder("step")
.repository(jobRepository)
.transactionManager(transactionManager)
.chunk(5)

View File

@@ -17,14 +17,14 @@ package org.springframework.batch.item.xml;
import org.springframework.core.io.ClassPathResource;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.castor.CastorMarshaller;
public class CastorMarshallingTests extends AbstractStaxEventWriterItemWriterTests {
@Override
protected Marshaller getMarshaller() throws Exception {
CastorMarshaller marshaller = new CastorMarshaller();
@SuppressWarnings("deprecation")
org.springframework.oxm.castor.CastorMarshaller marshaller = new org.springframework.oxm.castor.CastorMarshaller();
// marshaller.setTargetClass(Trade.class);
marshaller.setMappingLocation(new ClassPathResource("mapping-castor.xml", getClass()));
// there is no way to call

View File

@@ -17,13 +17,13 @@ package org.springframework.batch.item.xml;
import org.springframework.core.io.ClassPathResource;
import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.castor.CastorMarshaller;
public class CastorUnmarshallingTests extends AbstractStaxEventReaderItemReaderTests {
@Override
protected Unmarshaller getUnmarshaller() throws Exception {
CastorMarshaller unmarshaller = new CastorMarshaller();
@SuppressWarnings("deprecation")
org.springframework.oxm.castor.CastorMarshaller unmarshaller = new org.springframework.oxm.castor.CastorMarshaller();
unmarshaller.setMappingLocation(new ClassPathResource("mapping-castor.xml", getClass()));
// alternatively target class can be set
//unmarshaller.setTargetClass(Trade.class);

View File

@@ -53,7 +53,7 @@ public class RepositoryItemReaderBuilder<T> {
private String methodName;
private RepositoryMethodReference repositoryMethodReference;
private RepositoryMethodReference<?> repositoryMethodReference;
private boolean saveState = true;
@@ -213,7 +213,7 @@ public class RepositoryItemReaderBuilder<T> {
* @see RepositoryItemReader#setRepository(PagingAndSortingRepository)
*
*/
public RepositoryItemReaderBuilder<T> repository(RepositoryMethodReference repositoryMethodReference) {
public RepositoryItemReaderBuilder<T> repository(RepositoryMethodReference<?> repositoryMethodReference) {
this.repositoryMethodReference = repositoryMethodReference;
return this;
@@ -275,6 +275,7 @@ public class RepositoryItemReaderBuilder<T> {
* information about the method.
* @return T is a proxy of the object passed in in the constructor
*/
@SuppressWarnings("unchecked")
public T methodIs() {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(this.repository.getClass());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 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.
@@ -18,9 +18,6 @@ package org.springframework.batch.item.data.builder;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.batch.item.data.RepositoryItemWriter;
import org.springframework.cglib.proxy.Enhancer;
@@ -33,6 +30,7 @@ import org.springframework.util.Assert;
* A builder implementation for the {@link RepositoryItemWriter}.
*
* @author Glenn Renfro
* @author Mahmoud Ben Hassine
* @since 4.0
* @see RepositoryItemWriter
*/
@@ -136,6 +134,7 @@ public class RepositoryItemWriterBuilder<T> {
* information about the method.
* @return T is a proxy of the object passed in in the constructor
*/
@SuppressWarnings("unchecked")
public T methodIs() {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(this.repository.getClass());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2013 the original author or authors.
* Copyright 2006-2018 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.
@@ -38,9 +38,10 @@ import org.springframework.util.StringUtils;
* queries.
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
@SuppressWarnings("rawtype")
@SuppressWarnings("rawtypes")
public class HibernateItemReaderHelper<T> implements InitializingBean {
private SessionFactory sessionFactory;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 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.
@@ -37,6 +37,7 @@ import org.springframework.util.StringUtils;
*
* @author Michael Minella
* @author Glenn Renfro
* @author Mahmoud Ben Hassine
* @since 4.0
* @see HibernateCursorItemReader
*/
@@ -58,7 +59,7 @@ public class HibernateCursorItemReaderBuilder<T> {
private String nativeQuery;
private Class nativeClass;
private Class<T> nativeClass;
private boolean saveState = true;
@@ -232,7 +233,7 @@ public class HibernateCursorItemReaderBuilder<T> {
return this;
}
public HibernateCursorItemReaderBuilder<T> entityClass(Class nativeClass) {
public HibernateCursorItemReaderBuilder<T> entityClass(Class<T> nativeClass) {
this.nativeClass = nativeClass;
return this;
@@ -267,7 +268,7 @@ public class HibernateCursorItemReaderBuilder<T> {
reader.setQueryString(this.queryString);
}
else if(StringUtils.hasText(this.nativeQuery) && this.nativeClass != null) {
HibernateNativeQueryProvider provider = new HibernateNativeQueryProvider();
HibernateNativeQueryProvider<T> provider = new HibernateNativeQueryProvider<>();
provider.setSqlQuery(this.nativeQuery);
provider.setEntityClass(this.nativeClass);

View File

@@ -183,7 +183,7 @@ public class HibernatePagingItemReaderBuilder<T> {
* @return this instance for method chaining
* @see HibernatePagingItemReader#setQueryProvider(HibernateQueryProvider)
*/
public HibernatePagingItemReaderBuilder<T> queryProvider(HibernateQueryProvider queryProvider) {
public HibernatePagingItemReaderBuilder<T> queryProvider(HibernateQueryProvider<T> queryProvider) {
this.queryProvider = queryProvider;
return this;

View File

@@ -412,6 +412,8 @@ public abstract class AbstractFileItemWriter<T> extends AbstractItemStreamItemWr
/**
* Return the byte offset position of the cursor in the output file as a
* long integer.
* @return the byte offset position of the cursor in the output file
* @throws IOException If unable to get the offset position
*/
public long position() throws IOException {
long pos = 0;
@@ -519,7 +521,7 @@ public abstract class AbstractFileItemWriter<T> extends AbstractItemStreamItemWr
/**
* @param line String to be written to the file
* @throws IOException
* @throws IOException If unable to write the String to the file
*/
public void write(String line) throws IOException {
if (!initialized) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 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.
@@ -35,7 +35,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
public class MongoItemReaderTests {

View File

@@ -22,7 +22,10 @@ import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.core.io.FileSystemResource;
@@ -31,16 +34,17 @@ import org.springframework.core.io.Resource;
/**
* @author Mahmoud Ben Hassine
*/
@RunWith(MockitoJUnitRunner.class)
public class JsonFileItemWriterTests {
private Resource resource;
@Mock
private JsonObjectMarshaller<String> jsonObjectMarshaller;
@Before
public void setUp() throws Exception {
File file = Files.createTempFile("test", "json").toFile();
this.resource = new FileSystemResource(file);
this.jsonObjectMarshaller = Mockito.mock(JsonObjectMarshaller.class);
}
@Test(expected = IllegalArgumentException.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2018 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.
@@ -28,7 +28,7 @@ import javax.xml.transform.Source;
public final class StaxTestUtils {
public static XMLEventWriter getXmlEventWriter(Result r) throws Exception {
Method m = r.getClass().getDeclaredMethod("getXMLEventWriter", new Class[]{});
Method m = r.getClass().getDeclaredMethod("getXMLEventWriter");
boolean accessible = m.isAccessible();
m.setAccessible(true);
Object result = m.invoke(r);
@@ -37,7 +37,7 @@ public final class StaxTestUtils {
}
public static XMLEventReader getXmlEventReader(Source s) throws Exception {
Method m = s.getClass().getDeclaredMethod("getXMLEventReader", new Class[]{});
Method m = s.getClass().getDeclaredMethod("getXMLEventReader");
boolean accessible = m.isAccessible();
m.setAccessible(true);
Object result = m.invoke(s);

View File

@@ -22,7 +22,6 @@ import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.ChannelInterceptor;
import org.springframework.messaging.support.ChannelInterceptorAdapter;
/**
* A {@link ChannelInterceptor} that adds the current {@link StepExecution} (if
@@ -34,7 +33,7 @@ import org.springframework.messaging.support.ChannelInterceptorAdapter;
* @author Dave Syer
*
*/
public class StepExecutionInterceptor extends ChannelInterceptorAdapter {
public class StepExecutionInterceptor implements ChannelInterceptor {
/**
* The name of the header

View File

@@ -7,7 +7,6 @@ import org.springframework.integration.core.MessageSource;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.ChannelInterceptor;
import org.springframework.messaging.support.ChannelInterceptorAdapter;
import org.springframework.util.Assert;
@@ -20,7 +19,7 @@ import org.springframework.util.Assert;
* @author Dave Syer
*
*/
public class MessageSourcePollerInterceptor extends ChannelInterceptorAdapter implements InitializingBean {
public class MessageSourcePollerInterceptor implements ChannelInterceptor, InitializingBean {
private static Log logger = LogFactory.getLog(MessageSourcePollerInterceptor.class);
@@ -70,7 +69,7 @@ public class MessageSourcePollerInterceptor extends ChannelInterceptorAdapter im
* Receive from the {@link MessageSource} and send immediately to the input channel, so that the call that we are
* intercepting always a message to receive.
*
* @see ChannelInterceptorAdapter#preReceive(MessageChannel)
* @see ChannelInterceptor#preReceive(MessageChannel)
*/
@Override
public boolean preReceive(MessageChannel channel) {

View File

@@ -139,6 +139,7 @@ public class RemoteChunkingMasterStepBuilder<I, O> extends FaultTolerantStepBuil
* slow workers time to finish, and responsiveness if there is a dead worker. Defaults to 40.
*
* @param maxWaitTimeouts the maximum number of wait timeouts
* @return this builder instance for fluent chaining
* @see ChunkMessageChannelItemWriter#setMaxWaitTimeouts(int)
*/
public RemoteChunkingMasterStepBuilder<I, O> maxWaitTimeouts(int maxWaitTimeouts) {
@@ -152,6 +153,7 @@ public class RemoteChunkingMasterStepBuilder<I, O> extends FaultTolerantStepBuil
* overwhelming the receivers.
*
* @param throttleLimit the throttle limit to set
* @return this builder instance for fluent chaining
* @see ChunkMessageChannelItemWriter#setThrottleLimit(long)
*/
public RemoteChunkingMasterStepBuilder<I, O> throttleLimit(long throttleLimit) {

View File

@@ -50,6 +50,8 @@ public class RemoteChunkingMasterStepBuilderFactory {
* repository and transaction manager.
*
* @param name the name of the step
* @param <I> type of input items
* @param <O> type of output items
* @return a {@link RemoteChunkingMasterStepBuilder}
*/
public <I, O> RemoteChunkingMasterStepBuilder<I, O> get(String name) {

View File

@@ -108,6 +108,7 @@ public class RemoteChunkingWorkerBuilder<I, O> {
*
* @return the integration flow
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public IntegrationFlow build() {
Assert.notNull(this.itemWriter, "An ItemWriter must be provided");
Assert.notNull(this.inputChannel, "An InputChannel must be provided");

View File

@@ -235,6 +235,7 @@ public class RemoteChunkingMasterStepBuilderTest {
* The following test is to cover setters that override those from parent builders.
*/
@Test
@SuppressWarnings({"unchecked", "rawtypes"})
public void testSetters() throws Exception {
// when
DefaultTransactionAttribute transactionAttribute = new DefaultTransactionAttribute();