diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/environment/DefaultEnvironment.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/environment/DefaultEnvironment.java index 64126c6aa..36403c12f 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/environment/DefaultEnvironment.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/environment/DefaultEnvironment.java @@ -63,14 +63,16 @@ public DefaultEnvironment(EnvironmentType environmentType) throws IOException { private void loadAndPut(String environment) throws IOException { String name = "/" + environment + ".properties"; - InputStream stream = DefaultEnvironment.class.getResourceAsStream(name); - Properties properties = new Properties(); - if (stream != null) { - properties.load(stream); - this.properties.putAll(properties); - } else { - LOG.warn("Could not find the file '{}.properties' to load.", environment); + try (InputStream stream = DefaultEnvironment.class.getResourceAsStream(name)) { + Properties properties = new Properties(); + + if (stream != null) { + properties.load(stream); + this.properties.putAll(properties); + } else { + LOG.warn("Could not find the file '{}.properties' to load.", environment); + } } } diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/http/VRaptorRequest.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/http/VRaptorRequest.java index d29f1f020..cbfc6af76 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/http/VRaptorRequest.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/http/VRaptorRequest.java @@ -22,7 +22,6 @@ import java.util.Enumeration; import java.util.HashMap; -import java.util.Hashtable; import java.util.Map; import javax.enterprise.inject.Vetoed; @@ -43,7 +42,7 @@ public class VRaptorRequest extends HttpServletRequestWrapper implements Mutable private static final Logger logger = LoggerFactory.getLogger(VRaptorRequest.class); - private final Hashtable extraParameters = new Hashtable<>(); + private final Map extraParameters = new HashMap<>(); public VRaptorRequest(HttpServletRequest request) { super(request); diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/http/route/DefaultParametersControl.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/http/route/DefaultParametersControl.java index e8ab2d069..2c25fe0e3 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/http/route/DefaultParametersControl.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/http/route/DefaultParametersControl.java @@ -96,7 +96,9 @@ private Pattern compilePattern(String originalPattern, Map param @Override public String fillUri(Parameter[] paramNames, Object... paramValues) { if (paramNames.length != paramValues.length) { - throw new IllegalArgumentException("paramNames must have the same length as paramValues. Names: " + paramNames + " Values: " + Arrays.toString(paramValues)); + String message = String.format("paramNames must have the same length as paramValues. Names: %s Values: %s", + Arrays.toString(paramNames), Arrays.toString(paramValues)); + throw new IllegalArgumentException(message); } String[] splittedPatterns = StringUtils.extractParameters(originalPattern); diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/serialization/DefaultRepresentationResult.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/serialization/DefaultRepresentationResult.java index 4fee2fd7e..6160fcf93 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/serialization/DefaultRepresentationResult.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/serialization/DefaultRepresentationResult.java @@ -19,6 +19,7 @@ import static com.google.common.collect.Lists.newArrayList; import static java.util.Collections.sort; +import java.io.Serializable; import java.util.Comparator; import java.util.List; @@ -102,12 +103,14 @@ public Serializer from(T object, String alias) { * @author A.C de Souza * @since 3.4.0 */ - static final class ApplicationPackageFirst implements Comparator { + static final class ApplicationPackageFirst implements Comparator, Serializable { + + public static final long serialVersionUID = 1L; private static final String VRAPTOR_PACKAGE = "br.com.caelum.vraptor.serialization"; private int priority(Serialization s) { - return s.getClass().getPackage().getName().startsWith(VRAPTOR_PACKAGE)? 1 : 0; + return s.getClass().getPackage().getName().startsWith(VRAPTOR_PACKAGE) ? 1 : 0; } @Override diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/serialization/gson/GsonDeserialization.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/serialization/gson/GsonDeserialization.java index 3be5eccd0..4c51078c4 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/serialization/gson/GsonDeserialization.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/serialization/gson/GsonDeserialization.java @@ -23,6 +23,7 @@ import java.io.InputStreamReader; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import java.nio.charset.Charset; import javax.enterprise.inject.Instance; import javax.inject.Inject; @@ -156,7 +157,7 @@ public Object[] deserialize(InputStream inputStream, ControllerMethod method) { } private String getContentOfStream(InputStream input) throws IOException { - String charset = getRequestCharset(); + Charset charset = Charset.forName(getRequestCharset()); logger.debug("Using charset {}", charset); return CharStreams.toString(new InputStreamReader(input, charset)); diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/validator/I18nParam.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/validator/I18nParam.java index 20724ff54..8891e546e 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/validator/I18nParam.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/validator/I18nParam.java @@ -15,6 +15,7 @@ */ package br.com.caelum.vraptor.validator; +import java.io.Serializable; import java.util.ResourceBundle; import javax.enterprise.inject.Vetoed; @@ -29,8 +30,10 @@ * @since 3.4.0 */ @Vetoed -public class I18nParam { - +public class I18nParam implements Serializable { + + public static final long serialVersionUID = 1L; + private final String key; public I18nParam(String key) { diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/view/DefaultAcceptHeaderToFormat.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/view/DefaultAcceptHeaderToFormat.java index 9c9c0afd8..7d9c847a4 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/view/DefaultAcceptHeaderToFormat.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/view/DefaultAcceptHeaderToFormat.java @@ -17,6 +17,7 @@ package br.com.caelum.vraptor.view; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; @@ -99,8 +100,8 @@ private String chooseMimeType(String acceptHeader) { } private static class MimeType implements Comparable { - String type; - double qualifier; + private final String type; + private final double qualifier; public MimeType(String type, double qualifier) { this.type = type; @@ -113,6 +114,21 @@ public int compareTo(MimeType mime) { return Double.compare(mime.qualifier, this.qualifier); } + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + + MimeType other = (MimeType) obj; + return Objects.equals(type, other.type) && Objects.equals(qualifier, other.qualifier); + } + + @Override + public int hashCode() { + return Objects.hash(type, qualifier); + } + public String getType() { return type; } diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/view/LinkToHandler.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/view/LinkToHandler.java index 089cadf6d..da9cada06 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/view/LinkToHandler.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/view/LinkToHandler.java @@ -20,6 +20,7 @@ import static java.util.Collections.sort; import static javassist.CtNewMethod.abstractMethod; +import java.io.Serializable; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; @@ -210,7 +211,9 @@ private List getMethods(Class controller) { return methods; } - private final class SortByArgumentsLengthDesc implements Comparator { + private static final class SortByArgumentsLengthDesc implements Comparator, Serializable { + public static final long serialVersionUID = 1L; + @Override public int compare(Method o1, Method o2) { return Integer.compare(o2.getParameterTypes().length, o1.getParameterTypes().length); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/VRaptorRequestTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/VRaptorRequestTest.java index fdfd1b2b9..e63eb4590 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/VRaptorRequestTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/VRaptorRequestTest.java @@ -17,6 +17,7 @@ package br.com.caelum.vraptor.http; +import static java.util.Collections.enumeration; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -24,7 +25,7 @@ import static org.mockito.Mockito.when; import java.util.Enumeration; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -43,11 +44,11 @@ public class VRaptorRequestTest { public void setup() { MockitoAnnotations.initMocks(this); - final Hashtable t = new Hashtable<>(); + final Map t = new HashMap<>(); t.put("name", new String[] { "guilherme" }); t.put("age", new String[] { "27" }); - when(request.getParameterNames()).thenReturn(t.keys()); + when(request.getParameterNames()).thenReturn(enumeration(t.keySet())); when(request.getParameterMap()).thenReturn(t); when(request.getParameter("name")).thenReturn("guilherme"); when(request.getParameter("minimum")).thenReturn(null);