Fix remaining compiler warnings
Fix remaining Java compiler warnings, mainly around missing generics or deprecated code. Also add the `-Werror` compiler option to ensure that any future warnings will fail the build. Issue: SPR-11064
This commit is contained in:
@@ -18,11 +18,6 @@ package org.springframework.mock.web;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.PageContext;
|
||||
import javax.servlet.jsp.el.ELException;
|
||||
import javax.servlet.jsp.el.Expression;
|
||||
import javax.servlet.jsp.el.ExpressionEvaluator;
|
||||
import javax.servlet.jsp.el.FunctionMapper;
|
||||
import javax.servlet.jsp.el.VariableResolver;
|
||||
|
||||
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
|
||||
|
||||
@@ -42,7 +37,7 @@ import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
|
||||
* @see org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MockExpressionEvaluator extends ExpressionEvaluator {
|
||||
public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEvaluator {
|
||||
|
||||
private final PageContext pageContext;
|
||||
|
||||
@@ -58,13 +53,13 @@ public class MockExpressionEvaluator extends ExpressionEvaluator {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Expression parseExpression(final String expression, final Class expectedType,
|
||||
final FunctionMapper functionMapper) throws ELException {
|
||||
public javax.servlet.jsp.el.Expression parseExpression(final String expression, final Class expectedType,
|
||||
final javax.servlet.jsp.el.FunctionMapper functionMapper) throws javax.servlet.jsp.el.ELException {
|
||||
|
||||
return new Expression() {
|
||||
return new javax.servlet.jsp.el.Expression() {
|
||||
|
||||
@Override
|
||||
public Object evaluate(VariableResolver variableResolver) throws ELException {
|
||||
public Object evaluate(javax.servlet.jsp.el.VariableResolver variableResolver) throws javax.servlet.jsp.el.ELException {
|
||||
return doEvaluate(expression, expectedType, functionMapper);
|
||||
}
|
||||
};
|
||||
@@ -72,8 +67,8 @@ public class MockExpressionEvaluator extends ExpressionEvaluator {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object evaluate(String expression, Class expectedType, VariableResolver variableResolver,
|
||||
FunctionMapper functionMapper) throws ELException {
|
||||
public Object evaluate(String expression, Class expectedType, javax.servlet.jsp.el.VariableResolver variableResolver,
|
||||
javax.servlet.jsp.el.FunctionMapper functionMapper) throws javax.servlet.jsp.el.ELException {
|
||||
|
||||
if (variableResolver != null) {
|
||||
throw new IllegalArgumentException("Custom VariableResolver not supported");
|
||||
@@ -82,8 +77,8 @@ public class MockExpressionEvaluator extends ExpressionEvaluator {
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected Object doEvaluate(String expression, Class expectedType, FunctionMapper functionMapper)
|
||||
throws ELException {
|
||||
protected Object doEvaluate(String expression, Class expectedType, javax.servlet.jsp.el.FunctionMapper functionMapper)
|
||||
throws javax.servlet.jsp.el.ELException {
|
||||
|
||||
if (functionMapper != null) {
|
||||
throw new IllegalArgumentException("Custom FunctionMapper not supported");
|
||||
@@ -92,7 +87,7 @@ public class MockExpressionEvaluator extends ExpressionEvaluator {
|
||||
return ExpressionEvaluatorManager.evaluate("JSP EL expression", expression, expectedType, this.pageContext);
|
||||
}
|
||||
catch (JspException ex) {
|
||||
throw new ELException("Parsing of JSP EL expression \"" + expression + "\" failed", ex);
|
||||
throw new javax.servlet.jsp.el.ELException("Parsing of JSP EL expression \"" + expression + "\" failed", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -647,6 +647,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String getRealPath(String path) {
|
||||
return this.servletContext.getRealPath(path);
|
||||
}
|
||||
@@ -1026,6 +1027,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isRequestedSessionIdFromUrl() {
|
||||
return isRequestedSessionIdFromURL();
|
||||
}
|
||||
|
||||
@@ -416,11 +416,13 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String encodeUrl(String url) {
|
||||
return encodeURL(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String encodeRedirectUrl(String url) {
|
||||
return encodeRedirectURL(url);
|
||||
}
|
||||
@@ -540,6 +542,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setStatus(int status, String errorMessage) {
|
||||
if(!this.isCommitted()) {
|
||||
this.status = status;
|
||||
|
||||
@@ -28,7 +28,6 @@ import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.http.HttpSessionBindingEvent;
|
||||
import javax.servlet.http.HttpSessionBindingListener;
|
||||
import javax.servlet.http.HttpSessionContext;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -138,7 +137,7 @@ public class MockHttpSession implements HttpSession {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpSessionContext getSessionContext() {
|
||||
public javax.servlet.http.HttpSessionContext getSessionContext() {
|
||||
throw new UnsupportedOperationException("getSessionContext");
|
||||
}
|
||||
|
||||
@@ -235,7 +234,7 @@ public class MockHttpSession implements HttpSession {
|
||||
/**
|
||||
* Convenience method for asserting that this session has not been
|
||||
* {@linkplain #invalidate() invalidated}.
|
||||
*
|
||||
*
|
||||
* @throws IllegalStateException if this session has been invalidated
|
||||
*/
|
||||
private void assertIsValid() {
|
||||
|
||||
@@ -35,8 +35,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.jsp.JspWriter;
|
||||
import javax.servlet.jsp.PageContext;
|
||||
import javax.servlet.jsp.el.ExpressionEvaluator;
|
||||
import javax.servlet.jsp.el.VariableResolver;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -289,7 +287,7 @@ public class MockPageContext extends PageContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionEvaluator getExpressionEvaluator() {
|
||||
public javax.servlet.jsp.el.ExpressionEvaluator getExpressionEvaluator() {
|
||||
return new MockExpressionEvaluator(this);
|
||||
}
|
||||
|
||||
@@ -299,7 +297,7 @@ public class MockPageContext extends PageContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public VariableResolver getVariableResolver() {
|
||||
public javax.servlet.jsp.el.VariableResolver getVariableResolver() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.activation.FileTypeMap;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterRegistration;
|
||||
@@ -44,7 +45,6 @@ import javax.servlet.descriptor.JspConfigDescriptor;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
@@ -408,16 +408,19 @@ public class MockServletContext implements ServletContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Servlet getServlet(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Enumeration<Servlet> getServlets() {
|
||||
return Collections.enumeration(new HashSet<Servlet>());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Enumeration<String> getServletNames() {
|
||||
return Collections.enumeration(new HashSet<String>());
|
||||
}
|
||||
@@ -428,6 +431,7 @@ public class MockServletContext implements ServletContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void log(Exception ex, String message) {
|
||||
logger.info(message, ex);
|
||||
}
|
||||
|
||||
@@ -588,7 +588,6 @@ abstract class ContextLoaderUtils {
|
||||
* taking into account context hierarchies declared via
|
||||
* {@link ContextHierarchy @ContextHierarchy} and
|
||||
* {@link ContextConfiguration @ContextConfiguration}.
|
||||
*
|
||||
* @param testClass the test class for which the {@code MergedContextConfiguration}
|
||||
* should be built (must not be {@code null})
|
||||
* @param defaultContextLoaderClassName the name of the default {@code ContextLoader}
|
||||
@@ -599,7 +598,7 @@ abstract class ContextLoaderUtils {
|
||||
* @see #buildContextHierarchyMap(Class)
|
||||
* @see #buildMergedContextConfiguration(Class, List, String, MergedContextConfiguration, CacheAwareContextLoaderDelegate)
|
||||
*/
|
||||
@SuppressWarnings({ "javadoc", "unchecked" })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
static MergedContextConfiguration buildMergedContextConfiguration(Class<?> testClass,
|
||||
String defaultContextLoaderClassName, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) {
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import static org.springframework.core.annotation.AnnotationUtils.*;
|
||||
|
||||
/**
|
||||
* TODO Document MetaAnnotationUtils.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 4.0
|
||||
*/
|
||||
@@ -148,7 +148,7 @@ abstract class MetaAnnotationUtils {
|
||||
* Given the following example, if we are searching for the {@code @Transactional}
|
||||
* annotation <em>on</em> the {@code UserRepositoryTests} class, then the
|
||||
* properties of the {@code AnnotationDescriptor} would be as follows.
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
* <li>declaringClass: {@code UserRepositoryTests} class object</li>
|
||||
* <li>stereotype: instance of the {@code RepositoryTests} annotation</li>
|
||||
@@ -238,7 +238,7 @@ abstract class MetaAnnotationUtils {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
|
||||
for (Class clazz : annotationTypes) {
|
||||
for (Class<?> clazz : annotationTypes) {
|
||||
if (!Annotation.class.isAssignableFrom(clazz)) {
|
||||
throw new IllegalArgumentException("Array elements must be of type Annotation");
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.test.context.junit4.statements;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.internal.runners.model.MultipleFailureException;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.springframework.test.context.TestContextManager;
|
||||
|
||||
@@ -87,6 +86,6 @@ public class RunAfterTestClassCallbacks extends Statement {
|
||||
if (errors.size() == 1) {
|
||||
throw errors.get(0);
|
||||
}
|
||||
throw new MultipleFailureException(errors);
|
||||
throw new org.junit.internal.runners.model.MultipleFailureException(errors);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.internal.runners.model.MultipleFailureException;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.springframework.test.context.TestContextManager;
|
||||
|
||||
@@ -100,6 +99,6 @@ public class RunAfterTestMethodCallbacks extends Statement {
|
||||
if (errors.size() == 1) {
|
||||
throw errors.get(0);
|
||||
}
|
||||
throw new MultipleFailureException(errors);
|
||||
throw new org.junit.internal.runners.model.MultipleFailureException(errors);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,6 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
|
||||
* @see #setUpRequestContextIfNecessary(TestContext)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("javadoc")
|
||||
public void prepareTestInstance(TestContext testContext) throws Exception {
|
||||
setUpRequestContextIfNecessary(testContext);
|
||||
}
|
||||
@@ -83,7 +82,6 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
|
||||
* @see #setUpRequestContextIfNecessary(TestContext)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("javadoc")
|
||||
public void beforeTestMethod(TestContext testContext) throws Exception {
|
||||
setUpRequestContextIfNecessary(testContext);
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ public abstract class MockRestRequestMatchers {
|
||||
/**
|
||||
* Assert request header values with the given Hamcrest matcher.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static RequestMatcher header(final String name, final Matcher<? super String>... matchers) {
|
||||
return new RequestMatcher() {
|
||||
@Override
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||
* @author Rob Winch
|
||||
* @since 3.2
|
||||
*/
|
||||
public class DefaultMockMvcBuilder<Self extends DefaultMockMvcBuilder> extends MockMvcBuilderSupport
|
||||
public class DefaultMockMvcBuilder<B extends DefaultMockMvcBuilder<B>> extends MockMvcBuilderSupport
|
||||
implements MockMvcBuilder {
|
||||
|
||||
private final WebApplicationContext webAppContext;
|
||||
@@ -89,7 +89,7 @@ public class DefaultMockMvcBuilder<Self extends DefaultMockMvcBuilder> extends M
|
||||
* @param filters the filters to add
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final <T extends Self> T addFilters(Filter... filters) {
|
||||
public final <T extends B> T addFilters(Filter... filters) {
|
||||
Assert.notNull(filters, "filters cannot be null");
|
||||
|
||||
for(Filter f : filters) {
|
||||
@@ -121,7 +121,7 @@ public class DefaultMockMvcBuilder<Self extends DefaultMockMvcBuilder> extends M
|
||||
* @param urlPatterns URL patterns to map to; if empty, "/*" is used by default
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final <T extends Self> T addFilter(Filter filter, String... urlPatterns) {
|
||||
public final <T extends B> T addFilter(Filter filter, String... urlPatterns) {
|
||||
|
||||
Assert.notNull(filter, "filter cannot be null");
|
||||
Assert.notNull(urlPatterns, "urlPatterns cannot be null");
|
||||
@@ -148,7 +148,7 @@ public class DefaultMockMvcBuilder<Self extends DefaultMockMvcBuilder> extends M
|
||||
* .
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final <T extends Self> T defaultRequest(RequestBuilder requestBuilder) {
|
||||
public final <T extends B> T defaultRequest(RequestBuilder requestBuilder) {
|
||||
this.defaultRequestBuilder = requestBuilder;
|
||||
return (T) this;
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class DefaultMockMvcBuilder<Self extends DefaultMockMvcBuilder> extends M
|
||||
* {@link org.springframework.test.web.servlet.result.MockMvcResultMatchers}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final <T extends Self> T alwaysExpect(ResultMatcher resultMatcher) {
|
||||
public final <T extends B> T alwaysExpect(ResultMatcher resultMatcher) {
|
||||
this.globalResultMatchers.add(resultMatcher);
|
||||
return (T) this;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ public class DefaultMockMvcBuilder<Self extends DefaultMockMvcBuilder> extends M
|
||||
* {@link org.springframework.test.web.servlet.result.MockMvcResultHandlers}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final <T extends Self> T alwaysDo(ResultHandler resultHandler) {
|
||||
public final <T extends B> T alwaysDo(ResultHandler resultHandler) {
|
||||
this.globalResultHandlers.add(resultHandler);
|
||||
return (T) this;
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public class DefaultMockMvcBuilder<Self extends DefaultMockMvcBuilder> extends M
|
||||
* @see DispatcherServlet#setDispatchOptionsRequest(boolean)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final <T extends Self> T dispatchOptions(boolean dispatchOptions) {
|
||||
public final <T extends B> T dispatchOptions(boolean dispatchOptions) {
|
||||
this.dispatchOptions = dispatchOptions;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ public class MockMvcBuilders {
|
||||
* application controllers in it. The context must have been configured with
|
||||
* a {@link ServletContext}.
|
||||
*/
|
||||
public static DefaultMockMvcBuilder<DefaultMockMvcBuilder<?>> webAppContextSetup(WebApplicationContext context) {
|
||||
return new DefaultMockMvcBuilder<DefaultMockMvcBuilder<?>>(context);
|
||||
public static <B extends DefaultMockMvcBuilder<B>> DefaultMockMvcBuilder<B> webAppContextSetup(WebApplicationContext context) {
|
||||
return new DefaultMockMvcBuilder<B>(context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user