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

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() {