Deal with compiler warnings

This commit is contained in:
Dave Syer
2010-11-22 14:44:37 +00:00
parent 28eb5b02d3
commit 3dd0c7f776
26 changed files with 74 additions and 99 deletions

1
.gitignore vendored
View File

@@ -3,4 +3,5 @@ bin
integration-repo
derby-home
derby.log
derbydb
com.springsource.sts.config.flow.prefs

View File

@@ -16,9 +16,6 @@
package example;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.BatchStatus;

View File

@@ -117,7 +117,6 @@ public class CoreNamespacePostProcessor implements BeanPostProcessor, BeanFactor
* @param bean
* @return
*/
@SuppressWarnings("unchecked")
private Object injectDefaults(Object bean) {
if (bean instanceof JobParserJobFactoryBean) {
JobParserJobFactoryBean fb = (JobParserJobFactoryBean) bean;

View File

@@ -16,7 +16,6 @@
package org.springframework.batch.core.configuration.xml;
import java.util.Map;
import java.util.Set;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -93,14 +92,13 @@ public class CoreNamespaceUtils {
}
}
@SuppressWarnings("unchecked")
private static boolean rangeArrayEditorAlreadyDefined(BeanDefinitionRegistry registry) {
for (String beanName : registry.getBeanDefinitionNames()) {
BeanDefinition bd = registry.getBeanDefinition(beanName);
if (CUSTOM_EDITOR_CONFIGURER_CLASS_NAME.equals(bd.getBeanClassName())) {
PropertyValue pv = bd.getPropertyValues().getPropertyValue("customEditors");
if (pv != null) {
for (Map.Entry entry : (Set<Map.Entry>) ((Map) pv.getValue()).entrySet()) {
for (Map.Entry<?, ?> entry : ((Map<?, ?>) pv.getValue()).entrySet()) {
if (entry.getKey() instanceof TypedStringValue) {
if (RANGE_ARRAY_CLASS_NAME.equals(((TypedStringValue) entry.getKey()).getValue())) {
return true;
@@ -172,9 +170,10 @@ public class CoreNamespaceUtils {
* @return true if we find a schema declaration that matches
*/
public static boolean namespaceMatchesVersion(Element element) {
return matchesVersionInternal(element) && matchesVersionInternal(element.getOwnerDocument().getDocumentElement());
return matchesVersionInternal(element)
&& matchesVersionInternal(element.getOwnerDocument().getDocumentElement());
}
private static boolean matchesVersionInternal(Element element) {
String schemaLocation = element.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
return schemaLocation.matches("(?m).*spring-batch-2.1.xsd.*")

View File

@@ -41,8 +41,7 @@ public class JobListenerFactoryBean extends AbstractListenerFactoryBean {
return JobExecutionListener.class;
}
@SuppressWarnings("unchecked")
public Class getObjectType() {
public Class<?> getObjectType() {
return JobExecutionListener.class;
}

View File

@@ -33,7 +33,7 @@ import org.springframework.batch.item.ItemStream;
*
*/
public class MulticasterBatchListener<T, S> implements StepExecutionListener, ChunkListener, ItemReadListener<T>,
ItemProcessListener<T, S>, ItemWriteListener<S>, SkipListener<T,S> {
ItemProcessListener<T, S>, ItemWriteListener<S>, SkipListener<T, S> {
private CompositeStepExecutionListener stepListener = new CompositeStepExecutionListener();
@@ -45,7 +45,7 @@ public class MulticasterBatchListener<T, S> implements StepExecutionListener, Ch
private CompositeItemWriteListener<S> itemWriteListener = new CompositeItemWriteListener<S>();
private CompositeSkipListener<T,S> skipListener = new CompositeSkipListener<T,S>();
private CompositeSkipListener<T, S> skipListener = new CompositeSkipListener<T, S>();
/**
* Initialise the listener instance.
@@ -80,22 +80,22 @@ public class MulticasterBatchListener<T, S> implements StepExecutionListener, Ch
}
if (listener instanceof ItemReadListener<?>) {
@SuppressWarnings("unchecked")
ItemReadListener<T> itemReadListener = (ItemReadListener) listener;
ItemReadListener<T> itemReadListener = (ItemReadListener<T>) listener;
this.itemReadListener.register(itemReadListener);
}
if (listener instanceof ItemProcessListener<?,?>) {
if (listener instanceof ItemProcessListener<?, ?>) {
@SuppressWarnings("unchecked")
ItemProcessListener<T,S> itemProcessListener = (ItemProcessListener) listener;
ItemProcessListener<T, S> itemProcessListener = (ItemProcessListener<T, S>) listener;
this.itemProcessListener.register(itemProcessListener);
}
if (listener instanceof ItemWriteListener<?>) {
@SuppressWarnings("unchecked")
ItemWriteListener<S> itemWriteListener = (ItemWriteListener) listener;
ItemWriteListener<S> itemWriteListener = (ItemWriteListener<S>) listener;
this.itemWriteListener.register(itemWriteListener);
}
if (listener instanceof SkipListener<?,?>) {
if (listener instanceof SkipListener<?, ?>) {
@SuppressWarnings("unchecked")
SkipListener<T,S> skipListener = (SkipListener) listener;
SkipListener<T, S> skipListener = (SkipListener<T, S>) listener;
this.skipListener.register(skipListener);
}
}
@@ -294,7 +294,8 @@ public class MulticasterBatchListener<T, S> implements StepExecutionListener, Ch
/**
* @param item
* @param t
* @see org.springframework.batch.core.listener.CompositeSkipListener#onSkipInProcess(Object, Throwable)
* @see org.springframework.batch.core.listener.CompositeSkipListener#onSkipInProcess(Object,
* Throwable)
*/
public void onSkipInProcess(T item, Throwable t) {
skipListener.onSkipInProcess(item, t);

View File

@@ -41,7 +41,7 @@ public class StepListenerFactoryBean extends AbstractListenerFactoryBean {
return StepListener.class;
}
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
public Class getObjectType() {
return StepListener.class;
}

View File

@@ -116,7 +116,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
beanFactory.copyConfigurationFrom(listableBeanFactory);
final TypeConverter contextTypeConverter = new TypeConverter() {
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object convertIfNecessary(Object value, Class requiredType, MethodParameter methodParam)
throws TypeMismatchException {
Object result = null;
@@ -158,7 +158,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
return result != null ? result : typeConverter.convertIfNecessary(value, requiredType, methodParam);
}
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
public Object convertIfNecessary(Object value, Class requiredType) throws TypeMismatchException {
return convertIfNecessary(value, requiredType, null);
}
@@ -309,7 +309,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
super(new PlaceholderStringValueResolver(typeConverter));
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object resolveValue(Object value) {
if (value instanceof TypedStringValue) {

View File

@@ -55,7 +55,6 @@ import org.springframework.util.StringUtils;
public class ChunkElementParserTests {
@Test
@SuppressWarnings("unchecked")
public void testSimpleAttributes() throws Exception {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/ChunkElementSimpleAttributeParserTests-context.xml");

View File

@@ -81,7 +81,7 @@ public class StepParserTests {
public void testTaskletStepAttributes() throws Exception {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml");
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
Map<String, StepParserStepFactoryBean> beans = ctx.getBeansOfType(StepParserStepFactoryBean.class);
String factoryName = (String) beans.keySet().toArray()[0];
@SuppressWarnings("unchecked")

View File

@@ -62,9 +62,8 @@ public class StepWithBasicProcessTaskJobParserTests {
@Autowired
private TestWriter writer;
@SuppressWarnings("unchecked")
@Autowired
private StepParserStepFactoryBean factory;
private StepParserStepFactoryBean<?,?> factory;
@Test
public void testStepWithTask() throws Exception {

View File

@@ -68,9 +68,8 @@ public class StepWithFaultTolerantProcessTaskJobParserTests {
@Autowired
private TestWriter writer;
@SuppressWarnings("unchecked")
@Autowired
private StepParserStepFactoryBean factory;
private StepParserStepFactoryBean<?, ?> factory;
@Test
public void testStepWithTask() throws Exception {
@@ -83,10 +82,10 @@ public class StepWithFaultTolerantProcessTaskJobParserTests {
assertEquals("wrong retry-limit:", 3, rl);
Object cc = ReflectionTestUtils.getField(factory, "cacheCapacity");
assertEquals("wrong cache-capacity:", 100, cc);
assertEquals("wrong transaction-attribute:", Propagation.REQUIRED, ReflectionTestUtils.getField(factory,
"propagation"));
assertEquals("wrong transaction-attribute:", Isolation.DEFAULT, ReflectionTestUtils.getField(factory,
"isolation"));
assertEquals("wrong transaction-attribute:", Propagation.REQUIRED,
ReflectionTestUtils.getField(factory, "propagation"));
assertEquals("wrong transaction-attribute:", Isolation.DEFAULT,
ReflectionTestUtils.getField(factory, "isolation"));
assertEquals("wrong transaction-attribute:", 10, ReflectionTestUtils.getField(factory, "transactionTimeout"));
Object txq = ReflectionTestUtils.getField(factory, "readerTransactionalQueue");
assertEquals("wrong reader-transactional-queue:", true, txq);

View File

@@ -99,7 +99,7 @@ public class StepListenerFactoryBeanTests {
((ChunkListener) listener).afterChunk();
((ItemReadListener<String>) listener).beforeRead();
((ItemReadListener<String>) listener).afterRead(readItem);
((ItemReadListener) listener).onReadError(new Exception());
((ItemReadListener<String>) listener).onReadError(new Exception());
((ItemProcessListener<String, Integer>) listener).beforeProcess(readItem);
((ItemProcessListener<String, Integer>) listener).afterProcess(readItem, writeItem);
((ItemProcessListener<String, Integer>) listener).onProcessError(readItem, new Exception());

View File

@@ -23,8 +23,7 @@ import org.springframework.util.ReflectionUtils;
public class StepSynchronizationManagerTests {
private StepExecution stepExecution = new StepExecution("step",
new JobExecution(0L));
private StepExecution stepExecution = new StepExecution("step", new JobExecution(0L));
@Before
@After
@@ -44,8 +43,7 @@ public class StepSynchronizationManagerTests {
@Test
public void testClose() throws Exception {
final List<String> list = new ArrayList<String>();
StepContext context = StepSynchronizationManager
.register(stepExecution);
StepContext context = StepSynchronizationManager.register(stepExecution);
context.registerDestructionCallback("foo", new Runnable() {
public void run() {
list.add("foo");
@@ -54,51 +52,45 @@ public class StepSynchronizationManagerTests {
StepSynchronizationManager.close();
assertNull(StepSynchronizationManager.getContext());
assertEquals(0, list.size());
// check for possible memory leak
// check for possible memory leak
assertEquals(0, extractStaticMap("counts").size());
assertEquals(0, extractStaticMap("contexts").size());
}
@SuppressWarnings("unchecked")
private Map extractStaticMap(String name) throws IllegalAccessException {
Field field = ReflectionUtils.findField(
StepSynchronizationManager.class, name);
private Map<?, ?> extractStaticMap(String name) throws IllegalAccessException {
Field field = ReflectionUtils.findField(StepSynchronizationManager.class, name);
ReflectionUtils.makeAccessible(field);
Map map = (Map) field.get(StepSynchronizationManager.class);
Map<?, ?> map = (Map<?, ?>) field.get(StepSynchronizationManager.class);
return map;
}
@Test
public void testMultithreaded() throws Exception {
StepContext context = StepSynchronizationManager
.register(stepExecution);
StepContext context = StepSynchronizationManager.register(stepExecution);
ExecutorService executorService = Executors.newFixedThreadPool(2);
FutureTask<StepContext> task = new FutureTask<StepContext>(
new Callable<StepContext>() {
public StepContext call() throws Exception {
try {
StepSynchronizationManager.register(stepExecution);
StepContext context = StepSynchronizationManager
.getContext();
context.setAttribute("foo", "bar");
return context;
} finally {
StepSynchronizationManager.close();
}
}
});
FutureTask<StepContext> task = new FutureTask<StepContext>(new Callable<StepContext>() {
public StepContext call() throws Exception {
try {
StepSynchronizationManager.register(stepExecution);
StepContext context = StepSynchronizationManager.getContext();
context.setAttribute("foo", "bar");
return context;
}
finally {
StepSynchronizationManager.close();
}
}
});
executorService.execute(task);
executorService.awaitTermination(1, TimeUnit.SECONDS);
assertEquals(context.attributeNames().length, task.get()
.attributeNames().length);
assertEquals(context.attributeNames().length, task.get().attributeNames().length);
StepSynchronizationManager.close();
assertNull(StepSynchronizationManager.getContext());
}
@Test
public void testRelease() {
StepContext context = StepSynchronizationManager
.register(stepExecution);
StepContext context = StepSynchronizationManager.register(stepExecution);
final List<String> list = new ArrayList<String>();
context.registerDestructionCallback("foo", new Runnable() {
public void run() {

View File

@@ -86,7 +86,7 @@ public class TransactionAwareProxyFactory<T> {
* @param target the target object (List, Set or Map)
* @return an independent copy
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
protected final T begin(T target) {
// Unfortunately in Java 5 this method has to synchronized
// (works OK without in Java 6).
@@ -123,7 +123,7 @@ public class TransactionAwareProxyFactory<T> {
* @param copy the working copy.
* @param target the original target of the factory.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void commit(T copy, T target) {
// Unfortunately in Java 5 this method has to be synchronized
// (works OK without in Java 6).
@@ -157,49 +157,40 @@ public class TransactionAwareProxyFactory<T> {
}
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> createTransactionalMap() {
return (Map<K, V>) new TransactionAwareProxyFactory(new ConcurrentHashMap<K, V>()).createInstance();
return (Map<K, V>) new TransactionAwareProxyFactory<ConcurrentHashMap<K, V>>(new ConcurrentHashMap<K, V>()).createInstance();
}
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> createTransactionalMap(Map<K, V> map) {
return (Map<K, V>) new TransactionAwareProxyFactory(new ConcurrentHashMap<K, V>(map)).createInstance();
return (Map<K, V>) new TransactionAwareProxyFactory<ConcurrentHashMap<K, V>>(new ConcurrentHashMap<K, V>(map)).createInstance();
}
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> createAppendOnlyTransactionalMap() {
return (Map<K, V>) new TransactionAwareProxyFactory(new ConcurrentHashMap<K, V>(), true).createInstance();
return (Map<K, V>) new TransactionAwareProxyFactory<ConcurrentHashMap<K, V>>(new ConcurrentHashMap<K, V>(), true).createInstance();
}
@SuppressWarnings("unchecked")
public static <T> Set<T> createAppendOnlyTransactionalSet() {
return (Set<T>) new TransactionAwareProxyFactory(new CopyOnWriteArraySet<T>(), true).createInstance();
return (Set<T>) new TransactionAwareProxyFactory<CopyOnWriteArraySet<T>>(new CopyOnWriteArraySet<T>(), true).createInstance();
}
@SuppressWarnings("unchecked")
public static <T> Set<T> createTransactionalSet() {
return (Set<T>) new TransactionAwareProxyFactory(new CopyOnWriteArraySet<T>()).createInstance();
return (Set<T>) new TransactionAwareProxyFactory<CopyOnWriteArraySet<T>>(new CopyOnWriteArraySet<T>()).createInstance();
}
@SuppressWarnings("unchecked")
public static <T> Set<T> createTransactionalSet(Set<T> set) {
return (Set<T>) new TransactionAwareProxyFactory(new CopyOnWriteArraySet<T>(set)).createInstance();
return (Set<T>) new TransactionAwareProxyFactory<CopyOnWriteArraySet<T>>(new CopyOnWriteArraySet<T>(set)).createInstance();
}
@SuppressWarnings("unchecked")
public static <T> List<T> createAppendOnlyTransactionalList() {
return (List<T>) new TransactionAwareProxyFactory(new CopyOnWriteArrayList<T>(), true).createInstance();
return (List<T>) new TransactionAwareProxyFactory<CopyOnWriteArrayList<T>>(new CopyOnWriteArrayList<T>(), true).createInstance();
}
@SuppressWarnings("unchecked")
public static <T> List<T> createTransactionalList() {
return (List<T>) new TransactionAwareProxyFactory(new CopyOnWriteArrayList<T>()).createInstance();
return (List<T>) new TransactionAwareProxyFactory<CopyOnWriteArrayList<T>>(new CopyOnWriteArrayList<T>()).createInstance();
}
@SuppressWarnings("unchecked")
public static <T> List<T> createTransactionalList(List<T> list) {
return (List<T>) new TransactionAwareProxyFactory(new CopyOnWriteArrayList<T>(list)).createInstance();
return (List<T>) new TransactionAwareProxyFactory<CopyOnWriteArrayList<T>>(new CopyOnWriteArrayList<T>(list)).createInstance();
}
private class TargetSynchronization extends TransactionSynchronizationAdapter {

View File

@@ -10,7 +10,6 @@ import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
import com.ibatis.sqlmap.client.SqlMapClient;
@SuppressWarnings("unchecked")
@RunWith(JUnit4ClassRunner.class)
public class IbatisPagingItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests {
@@ -21,7 +20,7 @@ public class IbatisPagingItemReaderCommonTests extends AbstractDatabaseItemStrea
factory.afterPropertiesSet();
SqlMapClient sqlMapClient = createSqlMapClient();
IbatisPagingItemReader reader = new IbatisPagingItemReader();
IbatisPagingItemReader<Foo> reader = new IbatisPagingItemReader<Foo>();
reader.setQueryId("getPagedFoos");
reader.setPageSize(2);
reader.setSqlMapClient(sqlMapClient);
@@ -41,7 +40,7 @@ public class IbatisPagingItemReaderCommonTests extends AbstractDatabaseItemStrea
}
protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception {
IbatisPagingItemReader reader = (IbatisPagingItemReader) tested;
IbatisPagingItemReader<Foo> reader = (IbatisPagingItemReader<Foo>) tested;
reader.close();
reader.setQueryId("getNoFoos");

View File

@@ -11,7 +11,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.ibatis.sqlmap.client.SqlMapClient;
@SuppressWarnings("unchecked")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/org/springframework/batch/item/database/data-source-context.xml")
public class IbatisPagingItemReaderParameterTests extends AbstractPagingItemReaderParameterTests {
@@ -23,7 +22,7 @@ public class IbatisPagingItemReaderParameterTests extends AbstractPagingItemRead
factory.afterPropertiesSet();
SqlMapClient sqlMapClient = createSqlMapClient();
IbatisPagingItemReader reader = new IbatisPagingItemReader();
IbatisPagingItemReader<Foo> reader = new IbatisPagingItemReader<Foo>();
reader.setQueryId("getPagedFoos3AndUp");
reader.setParameterValues(Collections.<String, Object>singletonMap("limit", 3));
reader.setSqlMapClient(sqlMapClient);

View File

@@ -51,7 +51,7 @@ public class MultiResourceItemReaderXmlTests extends AbstractItemStreamItemReade
return foo;
}
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
public boolean supports(Class clazz) {
return true;
}

View File

@@ -59,7 +59,7 @@ public class MultiResourceItemWriterXmlTests extends AbstractMultiResourceItemWr
}
}
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
public boolean supports(Class clazz) {
return true;
}

View File

@@ -111,7 +111,7 @@ public class SpringValidatorTests {
public static final TestBean REJECT_MULTI_VALUE = new TestBean("foo", "bar");
@SuppressWarnings("unchecked")
@SuppressWarnings({ "rawtypes", "unchecked" })
public boolean supports(Class clazz) {
return clazz.isAssignableFrom(TestBean.class);
}

View File

@@ -49,7 +49,7 @@ public class StaxEventItemReaderCommonTests extends AbstractItemStreamItemReader
return foo;
}
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
public boolean supports(Class clazz) {
return true;
}

View File

@@ -374,7 +374,7 @@ public class StaxEventItemReaderTests {
return events;
}
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
public boolean supports(Class clazz) {
return true;
}

View File

@@ -418,7 +418,7 @@ public class StaxEventItemWriterTests {
}
}
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
public boolean supports(Class clazz) {
return true;
}

View File

@@ -226,7 +226,7 @@ public class TransactionalStaxEventItemWriterTests {
}
}
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
public boolean supports(Class clazz) {
return true;
}

View File

@@ -28,7 +28,7 @@ import org.springframework.batch.item.ItemReaderException;
*/
public class AggregateItem<T> {
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
private static final AggregateItem FOOTER = new AggregateItem<Object>(false, true) {
@Override
public Object getItem() throws ItemReaderException {
@@ -45,7 +45,7 @@ public class AggregateItem<T> {
return FOOTER;
}
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
private static final AggregateItem HEADER = new AggregateItem<Object>(true, false) {
@Override
public Object getItem() throws ItemReaderException {

View File

@@ -78,6 +78,7 @@ public class OrderItemReaderTests {
LineItem item = new LineItem();
// create mock mapper
@SuppressWarnings("rawtypes")
FieldSetMapper mapper = createMock(FieldSetMapper.class);
// set how mapper should respond - set return values for mapper
expect(mapper.mapFieldSet(headerFS)).andReturn(order);