Enable unchecked compilation warnings

See gh-21271
pull/21985/head
Andy Wilkinson 5 years ago
parent 47874d8c6a
commit c64649a6d9

@ -157,7 +157,7 @@ class JavaConventions {
args.add("-parameters");
}
if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
args.add("-Werror");
args.addAll(Arrays.asList("-Werror", "-Xlint:unchecked"));
}
});
}

@ -89,9 +89,10 @@ class HttpTraceWebFilterTests {
executeFilter(new ServerWebExchangeDecorator(
MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com"))) {
@SuppressWarnings("unchecked")
@Override
public Mono<Principal> getPrincipal() {
return Mono.just(principal);
public <T extends Principal> Mono<T> getPrincipal() {
return Mono.just((T) principal);
}
}, (exchange) -> {

@ -42,6 +42,7 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.cache.support.MockCachingProvider;
import org.springframework.boot.autoconfigure.cache.support.MockCachingProvider.MockCacheManager;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
@ -354,8 +355,9 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests {
assertThat(cacheManager.getCacheNames()).containsOnly("one", "two");
CompleteConfiguration<?, ?> defaultCacheConfiguration = context
.getBean(CompleteConfiguration.class);
verify(cacheManager.getCacheManager()).createCache("one", defaultCacheConfiguration);
verify(cacheManager.getCacheManager()).createCache("two", defaultCacheConfiguration);
MockCacheManager mockCacheManager = (MockCacheManager) cacheManager.getCacheManager();
assertThat(mockCacheManager.getConfigurations()).containsEntry("one", defaultCacheConfiguration)
.containsEntry("two", defaultCacheConfiguration);
});
}

@ -27,8 +27,6 @@ import javax.cache.configuration.Configuration;
import javax.cache.configuration.OptionalFeature;
import javax.cache.spi.CachingProvider;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@ -41,25 +39,8 @@ import static org.mockito.Mockito.mock;
public class MockCachingProvider implements CachingProvider {
@Override
@SuppressWarnings("rawtypes")
public CacheManager getCacheManager(URI uri, ClassLoader classLoader, Properties properties) {
CacheManager cacheManager = mock(CacheManager.class);
given(cacheManager.getURI()).willReturn(uri);
given(cacheManager.getClassLoader()).willReturn(classLoader);
final Map<String, Cache> caches = new HashMap<>();
given(cacheManager.getCacheNames()).willReturn(caches.keySet());
given(cacheManager.getCache(anyString())).willAnswer((invocation) -> {
String cacheName = invocation.getArgument(0);
return caches.get(cacheName);
});
given(cacheManager.createCache(anyString(), any(Configuration.class))).will((invocation) -> {
String cacheName = invocation.getArgument(0);
Cache cache = mock(Cache.class);
given(cache.getName()).willReturn(cacheName);
caches.put(cacheName, cache);
return cache;
});
return cacheManager;
return new MockCacheManager(uri, classLoader, properties);
}
@Override
@ -104,4 +85,108 @@ public class MockCachingProvider implements CachingProvider {
return false;
}
public static class MockCacheManager implements CacheManager {
private final Map<String, Configuration<?, ?>> configurations = new HashMap<>();
private final Map<String, Cache<?, ?>> caches = new HashMap<>();
private final URI uri;
private final ClassLoader classLoader;
private final Properties properties;
private boolean closed;
public MockCacheManager(URI uri, ClassLoader classLoader, Properties properties) {
this.uri = uri;
this.classLoader = classLoader;
this.properties = properties;
}
@Override
public CachingProvider getCachingProvider() {
throw new UnsupportedOperationException();
}
@Override
public URI getURI() {
return this.uri;
}
@Override
public ClassLoader getClassLoader() {
return this.classLoader;
}
@Override
public Properties getProperties() {
return this.properties;
}
@Override
@SuppressWarnings("unchecked")
public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(String cacheName, C configuration)
throws IllegalArgumentException {
this.configurations.put(cacheName, configuration);
Cache<K, V> cache = mock(Cache.class);
given(cache.getName()).willReturn(cacheName);
this.caches.put(cacheName, cache);
return cache;
}
@Override
@SuppressWarnings("unchecked")
public <K, V> Cache<K, V> getCache(String cacheName, Class<K> keyType, Class<V> valueType) {
return (Cache<K, V>) this.caches.get(cacheName);
}
@Override
@SuppressWarnings("unchecked")
public <K, V> Cache<K, V> getCache(String cacheName) {
return (Cache<K, V>) this.caches.get(cacheName);
}
@Override
public Iterable<String> getCacheNames() {
return this.caches.keySet();
}
@Override
public void destroyCache(String cacheName) {
this.caches.remove(cacheName);
}
@Override
public void enableManagement(String cacheName, boolean enabled) {
throw new UnsupportedOperationException();
}
@Override
public void enableStatistics(String cacheName, boolean enabled) {
throw new UnsupportedOperationException();
}
@Override
public void close() {
this.closed = true;
}
@Override
public boolean isClosed() {
return this.closed;
}
@Override
public <T> T unwrap(Class<T> clazz) {
throw new UnsupportedOperationException();
}
public Map<String, Configuration<?, ?>> getConfigurations() {
return this.configurations;
}
}
}

@ -46,11 +46,10 @@ public abstract class DependencyFilter extends AbstractArtifactsFilter {
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Set filter(Set artifacts) throws ArtifactFilterException {
Set result = new HashSet();
for (Object artifact : artifacts) {
if (!filter((Artifact) artifact)) {
public Set<Artifact> filter(Set<Artifact> artifacts) throws ArtifactFilterException {
Set<Artifact> result = new HashSet<>();
for (Artifact artifact : artifacts) {
if (!filter(artifact)) {
result.add(artifact);
}
}

Loading…
Cancel
Save