language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptFactory.java | @@ -132,7 +132,7 @@ public Object getScriptedObject(ScriptSource scriptSource, Class<?>... actualInt
if (result instanceof Class) {
// A Class: We'll cache the Class here and create an instance
// outside of the synchronized block.
- this.scriptClass = (Class) result;
+ this.scriptClass = (Class<?>) result;
}
else {
// Not a Class: OK, we'll simply create BeanShell objects | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptUtils.java | @@ -89,7 +89,7 @@ public static Object createBshObject(String scriptSource, Class<?>[] scriptInter
Object result = evaluateBshScript(scriptSource, scriptInterfaces, classLoader);
if (result instanceof Class) {
- Class clazz = (Class) result;
+ Class<?> clazz = (Class<?>) result;
try {
return clazz.newInstance();
}
@@ -120,7 +120,7 @@ static Class<?> determineBshObjectType(String scriptSource, ClassLoader classLoa
interpreter.setClassLoader(classLoader);
Object result = interpreter.eval(scriptSource);
if (result instanceof Class) {
- return (Class) result;
+ return (Class<?>) result;
}
else if (result != null) {
return result.getClass(); | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-context/src/main/java/org/springframework/scripting/config/ScriptBeanDefinitionParser.java | @@ -213,7 +213,7 @@ else if (beanDefinitionDefaults.getDestroyMethodName() != null) {
*/
private String resolveScriptSource(Element element, XmlReaderContext readerContext) {
boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE);
- List elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT);
+ List<Element> elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT);
if (hasScriptSource && !elements.isEmpty()) {
readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element);
return null;
@@ -222,7 +222,7 @@ else if (hasScriptSource) {
return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE);
}
else if (!elements.isEmpty()) {
- Element inlineElement = (Element) elements.get(0);
+ Element inlineElement = elements.get(0);
return "inline:" + DomUtils.getTextValue(inlineElement);
}
else { | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-context/src/main/java/org/springframework/scripting/jruby/JRubyScriptUtils.java | @@ -206,16 +206,16 @@ private IRubyObject[] convertToRuby(Object[] javaArgs) {
return rubyArgs;
}
- private Object convertFromRuby(IRubyObject rubyResult, Class returnType) {
+ private Object convertFromRuby(IRubyObject rubyResult, Class<?> returnType) {
Object result = JavaEmbedUtils.rubyToJava(this.ruby, rubyResult, returnType);
if (result instanceof RubyArray && returnType.isArray()) {
result = convertFromRubyArray(((RubyArray) result).toJavaArray(), returnType);
}
return result;
}
- private Object convertFromRubyArray(IRubyObject[] rubyArray, Class returnType) {
- Class targetType = returnType.getComponentType();
+ private Object convertFromRubyArray(IRubyObject[] rubyArray, Class<?> returnType) {
+ Class<?> targetType = returnType.getComponentType();
Object javaArray = Array.newInstance(targetType, rubyArray.length);
for (int i = 0; i < rubyArray.length; i++) {
IRubyObject rubyObject = rubyArray[i]; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java | @@ -239,7 +239,7 @@ public int getOrder() {
}
@Override
- public Class predictBeanType(Class beanClass, String beanName) {
+ public Class<?> predictBeanType(Class<?> beanClass, String beanName) {
// We only apply special treatment to ScriptFactory implementations here.
if (!ScriptFactory.class.isAssignableFrom(beanClass)) {
return null;
@@ -254,9 +254,9 @@ public Class predictBeanType(Class beanClass, String beanName) {
ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
- Class[] interfaces = scriptFactory.getScriptInterfaces();
+ Class<?>[] interfaces = scriptFactory.getScriptInterfaces();
- Class scriptedType = scriptFactory.getScriptedObjectType(scriptSource);
+ Class<?> scriptedType = scriptFactory.getScriptedObjectType(scriptSource);
if (scriptedType != null) {
return scriptedType;
} else if (!ObjectUtils.isEmpty(interfaces)) {
@@ -287,7 +287,7 @@ public Class predictBeanType(Class beanClass, String beanName) {
}
@Override
- public Object postProcessBeforeInstantiation(Class beanClass, String beanName) {
+ public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) {
// We only apply special treatment to ScriptFactory implementations here.
if (!ScriptFactory.class.isAssignableFrom(beanClass)) {
return null;
@@ -302,7 +302,7 @@ public Object postProcessBeforeInstantiation(Class beanClass, String beanName) {
ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
boolean isFactoryBean = false;
try {
- Class scriptedObjectType = scriptFactory.getScriptedObjectType(scriptSource);
+ Class<?> scriptedObjectType = scriptFactory.getScriptedObjectType(scriptSource);
// Returned type may be null if the factory is unable to determine the type.
if (scriptedObjectType != null) {
isFactoryBean = FactoryBean.class.isAssignableFrom(scriptedObjectType);
@@ -314,7 +314,7 @@ public Object postProcessBeforeInstantiation(Class beanClass, String beanName) {
long refreshCheckDelay = resolveRefreshCheckDelay(bd);
if (refreshCheckDelay >= 0) {
- Class[] interfaces = scriptFactory.getScriptInterfaces();
+ Class<?>[] interfaces = scriptFactory.getScriptInterfaces();
RefreshableScriptTargetSource ts = new RefreshableScriptTargetSource(this.scriptBeanFactory,
scriptedObjectBeanName, scriptFactory, scriptSource, isFactoryBean);
boolean proxyTargetClass = resolveProxyTargetClass(bd);
@@ -482,12 +482,12 @@ protected ScriptSource convertToScriptSource(String beanName, String scriptSourc
* @see org.springframework.cglib.proxy.InterfaceMaker
* @see org.springframework.beans.BeanUtils#findPropertyType
*/
- protected Class createConfigInterface(BeanDefinition bd, Class[] interfaces) {
+ protected Class<?> createConfigInterface(BeanDefinition bd, Class<?>[] interfaces) {
InterfaceMaker maker = new InterfaceMaker();
PropertyValue[] pvs = bd.getPropertyValues().getPropertyValues();
for (PropertyValue pv : pvs) {
String propertyName = pv.getName();
- Class propertyType = BeanUtils.findPropertyType(propertyName, interfaces);
+ Class<?> propertyType = BeanUtils.findPropertyType(propertyName, interfaces);
String setterName = "set" + StringUtils.capitalize(propertyName);
Signature signature = new Signature(setterName, Type.VOID_TYPE, new Type[] { Type.getType(propertyType) });
maker.add(signature, new Type[0]);
@@ -515,7 +515,7 @@ protected Class createConfigInterface(BeanDefinition bd, Class[] interfaces) {
* @return the merged interface as Class
* @see java.lang.reflect.Proxy#getProxyClass
*/
- protected Class createCompositeInterface(Class[] interfaces) {
+ protected Class<?> createCompositeInterface(Class<?>[] interfaces) {
return ClassUtils.createCompositeInterface(interfaces, this.beanClassLoader);
}
@@ -531,7 +531,7 @@ protected Class createCompositeInterface(Class[] interfaces) {
* @see org.springframework.scripting.ScriptFactory#getScriptedObject
*/
protected BeanDefinition createScriptedObjectBeanDefinition(BeanDefinition bd, String scriptFactoryBeanName,
- ScriptSource scriptSource, Class[] interfaces) {
+ ScriptSource scriptSource, Class<?>[] interfaces) {
GenericBeanDefinition objectBd = new GenericBeanDefinition(bd);
objectBd.setFactoryBeanName(scriptFactoryBeanName);
@@ -550,7 +550,7 @@ protected BeanDefinition createScriptedObjectBeanDefinition(BeanDefinition bd, S
* @return the generated proxy
* @see RefreshableScriptTargetSource
*/
- protected Object createRefreshableProxy(TargetSource ts, Class[] interfaces, boolean proxyTargetClass) {
+ protected Object createRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTargetSource(ts);
ClassLoader classLoader = this.beanClassLoader; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-context/src/main/java/org/springframework/ui/ModelMap.java | @@ -89,7 +89,7 @@ public ModelMap addAttribute(String attributeName, Object attributeValue) {
*/
public ModelMap addAttribute(Object attributeValue) {
Assert.notNull(attributeValue, "Model object must not be null");
- if (attributeValue instanceof Collection && ((Collection) attributeValue).isEmpty()) {
+ if (attributeValue instanceof Collection && ((Collection<?>) attributeValue).isEmpty()) {
return this;
}
return addAttribute(Conventions.getVariableName(attributeValue), attributeValue); | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java | @@ -261,7 +261,7 @@ public void afterPropertiesSet() {
setTargetValidator(this.validatorFactory.getValidator());
}
- private void configureParameterNameProviderIfPossible(Configuration configuration) {
+ private void configureParameterNameProviderIfPossible(Configuration<?> configuration) {
try {
Class<?> parameterNameProviderClass =
ClassUtils.forName("javax.validation.ParameterNameProvider", getClass().getClassLoader());
@@ -271,13 +271,13 @@ private void configureParameterNameProviderIfPossible(Configuration configuratio
Configuration.class.getMethod("getDefaultParameterNameProvider"), configuration);
final ParameterNameDiscoverer discoverer = this.parameterNameDiscoverer;
Object parameterNameProvider = Proxy.newProxyInstance(getClass().getClassLoader(),
- new Class[] {parameterNameProviderClass}, new InvocationHandler() {
+ new Class<?>[] {parameterNameProviderClass}, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getName().equals("getParameterNames")) {
String[] result = null;
if (args[0] instanceof Constructor) {
- result = discoverer.getParameterNames((Constructor) args[0]);
+ result = discoverer.getParameterNames((Constructor<?>) args[0]);
}
else if (args[0] instanceof Method) {
result = discoverer.getParameterNames((Method) args[0]);
@@ -320,7 +320,7 @@ else if (args[0] instanceof Method) {
* @param configuration the Configuration object, pre-populated with
* settings driven by LocalValidatorFactoryBean's properties
*/
- protected void postProcessConfiguration(Configuration configuration) {
+ protected void postProcessConfiguration(Configuration<?> configuration) {
}
| true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java | @@ -18,6 +18,7 @@
import java.lang.reflect.Method;
import java.util.Set;
+
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
@@ -27,10 +28,6 @@
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.hibernate.validator.HibernateValidator;
-import org.hibernate.validator.method.MethodConstraintViolation;
-import org.hibernate.validator.method.MethodConstraintViolationException;
-import org.hibernate.validator.method.MethodValidator;
-
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.validation.annotation.Validated;
@@ -113,7 +110,7 @@ public MethodValidationInterceptor(Validator validator) {
@Override
@SuppressWarnings("unchecked")
public Object invoke(MethodInvocation invocation) throws Throwable {
- Class[] groups = determineValidationGroups(invocation);
+ Class<?>[] groups = determineValidationGroups(invocation);
if (forExecutablesMethod != null) {
Object executableValidator = ReflectionUtils.invokeMethod(forExecutablesMethod, this.validator);
Set<ConstraintViolation<?>> result = (Set<ConstraintViolation<?>>)
@@ -143,9 +140,9 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
* @param invocation the current MethodInvocation
* @return the applicable validation groups as a Class array
*/
- protected Class[] determineValidationGroups(MethodInvocation invocation) {
+ protected Class<?>[] determineValidationGroups(MethodInvocation invocation) {
Validated valid = AnnotationUtils.findAnnotation(invocation.getThis().getClass(), Validated.class);
- return (valid != null ? valid.value() : new Class[0]);
+ return (valid != null ? valid.value() : new Class<?>[0]);
}
@@ -158,23 +155,23 @@ public static ValidatorFactory buildValidatorFactory() {
return Validation.byProvider(HibernateValidator.class).configure().buildValidatorFactory();
}
- public static Object invokeWithinValidation(MethodInvocation invocation, Validator validator, Class[] groups)
+ @SuppressWarnings("deprecation")
+ public static Object invokeWithinValidation(MethodInvocation invocation, Validator validator, Class<?>[] groups)
throws Throwable {
- MethodValidator methodValidator = validator.unwrap(MethodValidator.class);
- Set<MethodConstraintViolation<Object>> result = methodValidator.validateAllParameters(
+ org.hibernate.validator.method.MethodValidator methodValidator = validator.unwrap(org.hibernate.validator.method.MethodValidator.class);
+ Set<org.hibernate.validator.method.MethodConstraintViolation<Object>> result = methodValidator.validateAllParameters(
invocation.getThis(), invocation.getMethod(), invocation.getArguments(), groups);
if (!result.isEmpty()) {
- throw new MethodConstraintViolationException(result);
+ throw new org.hibernate.validator.method.MethodConstraintViolationException(result);
}
Object returnValue = invocation.proceed();
result = methodValidator.validateReturnValue(
invocation.getThis(), invocation.getMethod(), returnValue, groups);
if (!result.isEmpty()) {
- throw new MethodConstraintViolationException(result);
+ throw new org.hibernate.validator.method.MethodConstraintViolationException(result);
}
return returnValue;
}
}
-
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-context/src/main/java/org/springframework/validation/support/BindingAwareModelMap.java | @@ -44,7 +44,7 @@ public Object put(String key, Object value) {
@Override
public void putAll(Map<? extends String, ?> map) {
- for (Map.Entry entry : map.entrySet()) {
+ for (Map.Entry<? extends String, ?> entry : map.entrySet()) {
removeBindingResultIfNecessary(entry.getKey(), entry.getValue());
}
super.putAll(map); | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java | @@ -193,6 +193,11 @@ public MethodMatcher getMethodMatcher() {
return MethodMatcher.TRUE;
}
+ @Override
+ public int hashCode() {
+ return 0;
+ }
+
@Override
public boolean equals(Object obj) {
return true; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-context/src/test/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurerTests.java | @@ -177,6 +177,7 @@ public void ignoreUnresolvablePlaceholders_true() {
}
@Test(expected=BeanDefinitionStoreException.class)
+ @SuppressWarnings("serial")
public void nestedUnresolvablePlaceholder() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean",
@@ -192,6 +193,7 @@ public void nestedUnresolvablePlaceholder() {
}
@Test
+ @SuppressWarnings("serial")
public void ignoredNestedUnresolvablePlaceholder() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean", | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-context/src/test/java/org/springframework/scheduling/support/CronSequenceGeneratorTests.java | @@ -25,6 +25,7 @@
/**
* @author Juergen Hoeller
*/
+@SuppressWarnings("deprecation")
public class CronSequenceGeneratorTests {
@Test | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/cglib/transform/impl/MemorySafeUndeclaredThrowableStrategy.java | @@ -38,10 +38,10 @@ public boolean accept(int access, String name, String desc, String signature,
};
- private Class wrapper;
+ private Class<?> wrapper;
- public MemorySafeUndeclaredThrowableStrategy(Class wrapper) {
+ public MemorySafeUndeclaredThrowableStrategy(Class<?> wrapper) {
this.wrapper = wrapper;
}
| true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java | @@ -140,7 +140,7 @@ static boolean isBridgeMethodFor(Method bridgeMethod, Method candidateMethod, Cl
*/
private static Method findGenericDeclaration(Method bridgeMethod) {
// Search parent types for method that has same signature as bridge.
- Class superclass = bridgeMethod.getDeclaringClass().getSuperclass();
+ Class<?> superclass = bridgeMethod.getDeclaringClass().getSuperclass();
while (superclass != null && !Object.class.equals(superclass)) {
Method method = searchForMatch(superclass, bridgeMethod);
if (method != null && !method.isBridge()) {
@@ -150,8 +150,8 @@ private static Method findGenericDeclaration(Method bridgeMethod) {
}
// Search interfaces.
- Class[] interfaces = ClassUtils.getAllInterfacesForClass(bridgeMethod.getDeclaringClass());
- for (Class ifc : interfaces) {
+ Class<?>[] interfaces = ClassUtils.getAllInterfacesForClass(bridgeMethod.getDeclaringClass());
+ for (Class<?> ifc : interfaces) {
Method method = searchForMatch(ifc, bridgeMethod);
if (method != null && !method.isBridge()) {
return method;
@@ -170,13 +170,13 @@ private static Method findGenericDeclaration(Method bridgeMethod) {
private static boolean isResolvedTypeMatch(
Method genericMethod, Method candidateMethod, Class<?> declaringClass) {
Type[] genericParameters = genericMethod.getGenericParameterTypes();
- Class[] candidateParameters = candidateMethod.getParameterTypes();
+ Class<?>[] candidateParameters = candidateMethod.getParameterTypes();
if (genericParameters.length != candidateParameters.length) {
return false;
}
for (int i = 0; i < candidateParameters.length; i++) {
ResolvableType genericParameter = ResolvableType.forMethodParameter(genericMethod, i, declaringClass);
- Class candidateParameter = candidateParameters[i];
+ Class<?> candidateParameter = candidateParameters[i];
if (candidateParameter.isArray()) {
// An array type: compare the component type.
if (!candidateParameter.getComponentType().equals(genericParameter.getComponentType().resolve(Object.class))) {
@@ -196,7 +196,7 @@ private static boolean isResolvedTypeMatch(
* that of the supplied {@link Method}, then this matching {@link Method} is returned,
* otherwise {@code null} is returned.
*/
- private static Method searchForMatch(Class type, Method bridgeMethod) {
+ private static Method searchForMatch(Class<?> type, Method bridgeMethod) {
return ReflectionUtils.findMethod(type, bridgeMethod.getName(), bridgeMethod.getParameterTypes());
}
| true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/CollectionFactory.java | @@ -50,13 +50,13 @@
*/
public abstract class CollectionFactory {
- private static Class navigableSetClass = null;
+ private static Class<?> navigableSetClass = null;
- private static Class navigableMapClass = null;
+ private static Class<?> navigableMapClass = null;
- private static final Set<Class> approximableCollectionTypes = new HashSet<Class>(10);
+ private static final Set<Class<?>> approximableCollectionTypes = new HashSet<Class<?>>(10);
- private static final Set<Class> approximableMapTypes = new HashSet<Class>(6);
+ private static final Set<Class<?>> approximableMapTypes = new HashSet<Class<?>>(6);
static {
@@ -105,18 +105,18 @@ public static boolean isApproximableCollectionType(Class<?> collectionType) {
* @see java.util.LinkedHashSet
*/
@SuppressWarnings("unchecked")
- public static Collection createApproximateCollection(Object collection, int initialCapacity) {
+ public static <E> Collection<E> createApproximateCollection(Object collection, int initialCapacity) {
if (collection instanceof LinkedList) {
- return new LinkedList();
+ return new LinkedList<E>();
}
else if (collection instanceof List) {
- return new ArrayList(initialCapacity);
+ return new ArrayList<E>(initialCapacity);
}
else if (collection instanceof SortedSet) {
- return new TreeSet(((SortedSet) collection).comparator());
+ return new TreeSet<E>(((SortedSet<E>) collection).comparator());
}
else {
- return new LinkedHashSet(initialCapacity);
+ return new LinkedHashSet<E>(initialCapacity);
}
}
@@ -131,16 +131,17 @@ else if (collection instanceof SortedSet) {
* @see java.util.TreeSet
* @see java.util.LinkedHashSet
*/
- public static Collection createCollection(Class<?> collectionType, int initialCapacity) {
+ @SuppressWarnings("unchecked")
+ public static <E> Collection<E> createCollection(Class<?> collectionType, int initialCapacity) {
if (collectionType.isInterface()) {
if (List.class.equals(collectionType)) {
- return new ArrayList(initialCapacity);
+ return new ArrayList<E>(initialCapacity);
}
else if (SortedSet.class.equals(collectionType) || collectionType.equals(navigableSetClass)) {
- return new TreeSet();
+ return new TreeSet<E>();
}
else if (Set.class.equals(collectionType) || Collection.class.equals(collectionType)) {
- return new LinkedHashSet(initialCapacity);
+ return new LinkedHashSet<E>(initialCapacity);
}
else {
throw new IllegalArgumentException("Unsupported Collection interface: " + collectionType.getName());
@@ -151,7 +152,7 @@ else if (Set.class.equals(collectionType) || Collection.class.equals(collectionT
throw new IllegalArgumentException("Unsupported Collection type: " + collectionType.getName());
}
try {
- return (Collection) collectionType.newInstance();
+ return (Collection<E>) collectionType.newInstance();
}
catch (Exception ex) {
throw new IllegalArgumentException("Could not instantiate Collection type: " +
@@ -181,12 +182,12 @@ public static boolean isApproximableMapType(Class<?> mapType) {
* @see java.util.LinkedHashMap
*/
@SuppressWarnings("unchecked")
- public static Map createApproximateMap(Object map, int initialCapacity) {
+ public static <K, V> Map<K, V> createApproximateMap(Object map, int initialCapacity) {
if (map instanceof SortedMap) {
- return new TreeMap(((SortedMap) map).comparator());
+ return new TreeMap<K, V>(((SortedMap<K, V>) map).comparator());
}
else {
- return new LinkedHashMap(initialCapacity);
+ return new LinkedHashMap<K, V>(initialCapacity);
}
}
@@ -199,13 +200,14 @@ public static Map createApproximateMap(Object map, int initialCapacity) {
* @see java.util.TreeMap
* @see java.util.LinkedHashMap
*/
- public static Map createMap(Class<?> mapType, int initialCapacity) {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static <K, V> Map<K, V> createMap(Class<?> mapType, int initialCapacity) {
if (mapType.isInterface()) {
if (Map.class.equals(mapType)) {
- return new LinkedHashMap(initialCapacity);
+ return new LinkedHashMap<K, V>(initialCapacity);
}
else if (SortedMap.class.equals(mapType) || mapType.equals(navigableMapClass)) {
- return new TreeMap();
+ return new TreeMap<K, V>();
}
else if (MultiValueMap.class.equals(mapType)) {
return new LinkedMultiValueMap();
@@ -219,7 +221,7 @@ else if (MultiValueMap.class.equals(mapType)) {
throw new IllegalArgumentException("Unsupported Map type: " + mapType.getName());
}
try {
- return (Map) mapType.newInstance();
+ return (Map<K, V>) mapType.newInstance();
}
catch (Exception ex) {
throw new IllegalArgumentException("Could not instantiate Map type: " + | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/ConfigurableObjectInputStream.java | @@ -68,7 +68,7 @@ public ConfigurableObjectInputStream(
@Override
- protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException {
+ protected Class<?> resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException {
try {
if (this.classLoader != null) {
// Use the specified ClassLoader to resolve local classes.
@@ -85,13 +85,13 @@ protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, Cl
}
@Override
- protected Class resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException {
+ protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException {
if (!this.acceptProxyClasses) {
throw new NotSerializableException("Not allowed to accept serialized proxy classes");
}
if (this.classLoader != null) {
// Use the specified ClassLoader to resolve local proxy classes.
- Class[] resolvedInterfaces = new Class[interfaces.length];
+ Class<?>[] resolvedInterfaces = new Class<?>[interfaces.length];
for (int i = 0; i < interfaces.length; i++) {
try {
resolvedInterfaces[i] = ClassUtils.forName(interfaces[i], this.classLoader);
@@ -113,7 +113,7 @@ protected Class resolveProxyClass(String[] interfaces) throws IOException, Class
return super.resolveProxyClass(interfaces);
}
catch (ClassNotFoundException ex) {
- Class[] resolvedInterfaces = new Class[interfaces.length];
+ Class<?>[] resolvedInterfaces = new Class<?>[interfaces.length];
for (int i = 0; i < interfaces.length; i++) {
resolvedInterfaces[i] = resolveFallbackIfPossible(interfaces[i], ex);
}
@@ -131,7 +131,7 @@ protected Class resolveProxyClass(String[] interfaces) throws IOException, Class
* @param ex the original exception thrown when attempting to load the class
* @return the newly resolved class (never {@code null})
*/
- protected Class resolveFallbackIfPossible(String className, ClassNotFoundException ex)
+ protected Class<?> resolveFallbackIfPossible(String className, ClassNotFoundException ex)
throws IOException, ClassNotFoundException{
throw ex; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/ControlFlow.java | @@ -31,15 +31,15 @@ public interface ControlFlow {
* according to the current stack trace.
* @param clazz the clazz to look for
*/
- boolean under(Class clazz);
+ boolean under(Class<?> clazz);
/**
* Detect whether we're under the given class and method,
* according to the current stack trace.
* @param clazz the clazz to look for
* @param methodName the name of the method to look for
*/
- boolean under(Class clazz, String methodName);
+ boolean under(Class<?> clazz, String methodName);
/**
* Detect whether the current stack trace contains the given token. | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/ControlFlowFactory.java | @@ -62,7 +62,7 @@ public Jdk14ControlFlow() {
* Searches for class name match in a StackTraceElement.
*/
@Override
- public boolean under(Class clazz) {
+ public boolean under(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
String className = clazz.getName();
for (int i = 0; i < stack.length; i++) {
@@ -78,7 +78,7 @@ public boolean under(Class clazz) {
* in a StackTraceElement.
*/
@Override
- public boolean under(Class clazz, String methodName) {
+ public boolean under(Class<?> clazz, String methodName) {
Assert.notNull(clazz, "Class must not be null");
Assert.notNull(methodName, "Method name must not be null");
String className = clazz.getName(); | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/Conventions.java | @@ -20,7 +20,9 @@
import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
@@ -43,18 +45,18 @@ public abstract class Conventions {
*/
private static final String PLURAL_SUFFIX = "List";
-
/**
* Set of interfaces that are supposed to be ignored
* when searching for the 'primary' interface of a proxy.
*/
- private static final Set<Class> ignoredInterfaces = new HashSet<Class>();
-
+ private static final Set<Class<?>> IGNORED_INTERFACES;
static {
- ignoredInterfaces.add(Serializable.class);
- ignoredInterfaces.add(Externalizable.class);
- ignoredInterfaces.add(Cloneable.class);
- ignoredInterfaces.add(Comparable.class);
+ IGNORED_INTERFACES = Collections.unmodifiableSet(
+ new HashSet<Class<?>>(Arrays.<Class<?>> asList(
+ Serializable.class,
+ Externalizable.class,
+ Cloneable.class,
+ Comparable.class)));
}
@@ -75,15 +77,15 @@ public abstract class Conventions {
*/
public static String getVariableName(Object value) {
Assert.notNull(value, "Value must not be null");
- Class valueClass;
+ Class<?> valueClass;
boolean pluralize = false;
if (value.getClass().isArray()) {
valueClass = value.getClass().getComponentType();
pluralize = true;
}
else if (value instanceof Collection) {
- Collection collection = (Collection) value;
+ Collection<?> collection = (Collection<?>) value;
if (collection.isEmpty()) {
throw new IllegalArgumentException("Cannot generate variable name for an empty Collection");
}
@@ -107,7 +109,7 @@ else if (value instanceof Collection) {
*/
public static String getVariableNameForParameter(MethodParameter parameter) {
Assert.notNull(parameter, "MethodParameter must not be null");
- Class valueClass;
+ Class<?> valueClass;
boolean pluralize = false;
if (parameter.getParameterType().isArray()) {
@@ -163,7 +165,7 @@ public static String getVariableNameForReturnType(Method method, Object value) {
* @param value the return value (may be {@code null} if not available)
* @return the generated variable name
*/
- public static String getVariableNameForReturnType(Method method, Class resolvedType, Object value) {
+ public static String getVariableNameForReturnType(Method method, Class<?> resolvedType, Object value) {
Assert.notNull(method, "Method must not be null");
if (Object.class.equals(resolvedType)) {
@@ -173,7 +175,7 @@ public static String getVariableNameForReturnType(Method method, Class resolvedT
return getVariableName(value);
}
- Class valueClass;
+ Class<?> valueClass;
boolean pluralize = false;
if (resolvedType.isArray()) {
@@ -187,7 +189,7 @@ else if (Collection.class.isAssignableFrom(resolvedType)) {
throw new IllegalArgumentException(
"Cannot generate variable name for non-typed Collection return type and a non-Collection value");
}
- Collection collection = (Collection) value;
+ Collection<?> collection = (Collection<?>) value;
if (collection.isEmpty()) {
throw new IllegalArgumentException(
"Cannot generate variable name for non-typed Collection return type and an empty Collection value");
@@ -239,7 +241,7 @@ else if (upperCaseNext) {
* the attribute name '{@code foo}' qualified by {@link Class} '{@code com.myapp.SomeClass}'
* would be '{@code com.myapp.SomeClass.foo}'
*/
- public static String getQualifiedAttributeName(Class enclosingClass, String attributeName) {
+ public static String getQualifiedAttributeName(Class<?> enclosingClass, String attributeName) {
Assert.notNull(enclosingClass, "'enclosingClass' must not be null");
Assert.notNull(attributeName, "'attributeName' must not be null");
return enclosingClass.getName() + "." + attributeName;
@@ -255,12 +257,12 @@ public static String getQualifiedAttributeName(Class enclosingClass, String attr
* @param value the value to check
* @return the class to use for naming a variable
*/
- private static Class getClassForValue(Object value) {
- Class valueClass = value.getClass();
+ private static Class<?> getClassForValue(Object value) {
+ Class<?> valueClass = value.getClass();
if (Proxy.isProxyClass(valueClass)) {
- Class[] ifcs = valueClass.getInterfaces();
- for (Class ifc : ifcs) {
- if (!ignoredInterfaces.contains(ifc)) {
+ Class<?>[] ifcs = valueClass.getInterfaces();
+ for (Class<?> ifc : ifcs) {
+ if (!IGNORED_INTERFACES.contains(ifc)) {
return ifc;
}
}
@@ -285,13 +287,13 @@ private static String pluralize(String name) {
* The exact element for which the {@code Class} is retreived will depend
* on the concrete {@code Collection} implementation.
*/
- private static Object peekAhead(Collection collection) {
- Iterator it = collection.iterator();
+ private static <E> E peekAhead(Collection<E> collection) {
+ Iterator<E> it = collection.iterator();
if (!it.hasNext()) {
throw new IllegalStateException(
"Unable to peek ahead in non-empty collection - no element found");
}
- Object value = it.next();
+ E value = it.next();
if (value == null) {
throw new IllegalStateException(
"Unable to peek ahead in non-empty collection - only null element found"); | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/ExceptionDepthComparator.java | @@ -62,7 +62,7 @@ public int compare(Class<? extends Throwable> o1, Class<? extends Throwable> o2)
return (depth1 - depth2);
}
- private int getDepth(Class declaredException, Class exceptionToMatch, int depth) {
+ private int getDepth(Class<?> declaredException, Class<?> exceptionToMatch, int depth) {
if (declaredException.equals(exceptionToMatch)) {
// Found it!
return depth; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/GenericCollectionTypeResolver.java | @@ -41,6 +41,7 @@ public abstract class GenericCollectionTypeResolver {
* @param collectionClass the collection class to introspect
* @return the generic type, or {@code null} if none
*/
+ @SuppressWarnings("rawtypes")
public static Class<?> getCollectionType(Class<? extends Collection> collectionClass) {
return ResolvableType.forClass(collectionClass).asCollection().resolveGeneric();
}
@@ -51,6 +52,7 @@ public static Class<?> getCollectionType(Class<? extends Collection> collectionC
* @param mapClass the map class to introspect
* @return the generic type, or {@code null} if none
*/
+ @SuppressWarnings("rawtypes")
public static Class<?> getMapKeyType(Class<? extends Map> mapClass) {
return ResolvableType.forClass(mapClass).asMap().resolveGeneric(0);
}
@@ -61,6 +63,7 @@ public static Class<?> getMapKeyType(Class<? extends Map> mapClass) {
* @param mapClass the map class to introspect
* @return the generic type, or {@code null} if none
*/
+ @SuppressWarnings("rawtypes")
public static Class<?> getMapValueType(Class<? extends Map> mapClass) {
return ResolvableType.forClass(mapClass).asMap().resolveGeneric(1);
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java | @@ -44,8 +44,9 @@
public abstract class GenericTypeResolver {
/** Cache from Class to TypeVariable Map */
- private static final Map<Class, Map<TypeVariable, Type>> typeVariableCache =
- new ConcurrentReferenceHashMap<Class, Map<TypeVariable,Type>>();
+ @SuppressWarnings("rawtypes")
+ private static final Map<Class<?>, Map<TypeVariable, Type>> typeVariableCache =
+ new ConcurrentReferenceHashMap<Class<?>, Map<TypeVariable, Type>>();
/**
@@ -256,6 +257,7 @@ public static Class<?>[] resolveTypeArguments(Class<?> clazz, Class<?> genericIf
* @deprecated as of Spring 4.0 in favor of {@link ResolvableType}
*/
@Deprecated
+ @SuppressWarnings("rawtypes")
public static Class<?> resolveType(Type genericType, Map<TypeVariable, Type> map) {
return ResolvableType.forType(genericType, new TypeVariableMapVariableResolver(map)).resolve(Object.class);
}
@@ -267,6 +269,7 @@ public static Class<?> resolveType(Type genericType, Map<TypeVariable, Type> map
* @deprecated as of Spring 4.0 in favor of {@link ResolvableType}
*/
@Deprecated
+ @SuppressWarnings("rawtypes")
public static Map<TypeVariable, Type> getTypeVariableMap(Class<?> clazz) {
Map<TypeVariable, Type> typeVariableMap = typeVariableCache.get(clazz);
if (typeVariableMap == null) {
@@ -277,6 +280,7 @@ public static Map<TypeVariable, Type> getTypeVariableMap(Class<?> clazz) {
return typeVariableMap;
}
+ @SuppressWarnings("rawtypes")
private static void buildTypeVariableMap(ResolvableType type, Map<TypeVariable, Type> typeVariableMap) {
if (type != ResolvableType.NONE) {
if (type.getType() instanceof ParameterizedType) {
@@ -302,7 +306,7 @@ private static void buildTypeVariableMap(ResolvableType type, Map<TypeVariable,
}
- @SuppressWarnings("serial")
+ @SuppressWarnings({"serial", "rawtypes"})
private static class TypeVariableMapVariableResolver implements ResolvableType.VariableResolver {
private final Map<TypeVariable, Type> typeVariableMap; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/MethodParameter.java | @@ -43,7 +43,7 @@ public class MethodParameter {
private final Method method;
- private final Constructor constructor;
+ private final Constructor<?> constructor;
private final int parameterIndex;
@@ -99,7 +99,7 @@ public MethodParameter(Method method, int parameterIndex, int nestingLevel) {
* @param constructor the Constructor to specify a parameter for
* @param parameterIndex the index of the parameter
*/
- public MethodParameter(Constructor constructor, int parameterIndex) {
+ public MethodParameter(Constructor<?> constructor, int parameterIndex) {
this(constructor, parameterIndex, 1);
}
@@ -111,7 +111,7 @@ public MethodParameter(Constructor constructor, int parameterIndex) {
* (typically 1; e.g. in case of a List of Lists, 1 would indicate the
* nested List, whereas 2 would indicate the element of the nested List)
*/
- public MethodParameter(Constructor constructor, int parameterIndex, int nestingLevel) {
+ public MethodParameter(Constructor<?> constructor, int parameterIndex, int nestingLevel) {
Assert.notNull(constructor, "Constructor must not be null");
this.constructor = constructor;
this.parameterIndex = parameterIndex;
@@ -155,7 +155,7 @@ public Method getMethod() {
* <p>Note: Either Method or Constructor is available.
* @return the Constructor, or {@code null} if none
*/
- public Constructor getConstructor() {
+ public Constructor<?> getConstructor() {
return this.constructor;
}
@@ -268,12 +268,12 @@ public Class<?> getNestedParameterType() {
Type[] args = ((ParameterizedType) type).getActualTypeArguments();
Type arg = args[index != null ? index : args.length - 1];
if (arg instanceof Class) {
- return (Class) arg;
+ return (Class<?>) arg;
}
else if (arg instanceof ParameterizedType) {
arg = ((ParameterizedType) arg).getRawType();
if (arg instanceof Class) {
- return (Class) arg;
+ return (Class<?>) arg;
}
}
}
@@ -489,7 +489,7 @@ public static MethodParameter forMethodOrConstructor(Object methodOrConstructor,
return new MethodParameter((Method) methodOrConstructor, parameterIndex);
}
else if (methodOrConstructor instanceof Constructor) {
- return new MethodParameter((Constructor) methodOrConstructor, parameterIndex);
+ return new MethodParameter((Constructor<?>) methodOrConstructor, parameterIndex);
}
else {
throw new IllegalArgumentException( | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/NestedCheckedException.java | @@ -109,7 +109,7 @@ public Throwable getMostSpecificCause() {
* @param exType the exception type to look for
* @return whether there is a nested exception of the specified type
*/
- public boolean contains(Class exType) {
+ public boolean contains(Class<?> exType) {
if (exType == null) {
return false;
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/NestedRuntimeException.java | @@ -110,7 +110,7 @@ public Throwable getMostSpecificCause() {
* @param exType the exception type to look for
* @return whether there is a nested exception of the specified type
*/
- public boolean contains(Class exType) {
+ public boolean contains(Class<?> exType) {
if (exType == null) {
return false;
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/OrderComparator.java | @@ -111,7 +111,7 @@ public static void sortIfNecessary(Object value) {
sort((Object[]) value);
}
else if (value instanceof List) {
- sort((List) value);
+ sort((List<?>) value);
}
}
| true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/OverridingClassLoader.java | @@ -55,8 +55,8 @@ public OverridingClassLoader(ClassLoader parent) {
@Override
- protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
- Class result = null;
+ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
+ Class<?> result = null;
if (isEligibleForOverriding(name)) {
result = loadClassForOverriding(name);
}
@@ -90,8 +90,8 @@ protected boolean isEligibleForOverriding(String className) {
* @return the Class object, or {@code null} if no class defined for that name
* @throws ClassNotFoundException if the class for the given name couldn't be loaded
*/
- protected Class loadClassForOverriding(String name) throws ClassNotFoundException {
- Class result = findLoadedClass(name);
+ protected Class<?> loadClassForOverriding(String name) throws ClassNotFoundException {
+ Class<?> result = findLoadedClass(name);
if (result == null) {
byte[] bytes = loadBytesForClass(name);
if (bytes != null) { | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java | @@ -61,7 +61,7 @@ public Type getType() {
@Override
public boolean equals(Object obj) {
return (this == obj || (obj instanceof ParameterizedTypeReference &&
- this.type.equals(((ParameterizedTypeReference) obj).type)));
+ this.type.equals(((ParameterizedTypeReference<?>) obj).type)));
}
@Override | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/PrioritizedParameterNameDiscoverer.java | @@ -60,7 +60,7 @@ public String[] getParameterNames(Method method) {
}
@Override
- public String[] getParameterNames(Constructor ctor) {
+ public String[] getParameterNames(Constructor<?> ctor) {
for (ParameterNameDiscoverer pnd : this.parameterNameDiscoverers) {
String[] result = pnd.getParameterNames(ctor);
if (result != null) { | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/ResolvableType.java | @@ -155,7 +155,7 @@ public Class<?> getRawClass() {
if (rawType instanceof ParameterizedType) {
rawType = ((ParameterizedType) rawType).getRawType();
}
- return (rawType instanceof Class ? (Class) rawType : null);
+ return (rawType instanceof Class ? (Class<?>) rawType : null);
}
/**
@@ -1060,11 +1060,11 @@ public Object getSource() {
@SuppressWarnings("serial")
private static class TypeVariablesVariableResolver implements VariableResolver {
- private final TypeVariable[] typeVariables;
+ private final TypeVariable<?>[] typeVariables;
private final ResolvableType[] generics;
- public TypeVariablesVariableResolver(TypeVariable[] typeVariables, ResolvableType[] generics) {
+ public TypeVariablesVariableResolver(TypeVariable<?>[] typeVariables, ResolvableType[] generics) {
Assert.isTrue(typeVariables.length == generics.length, "Mismatched number of generics specified");
this.typeVariables = typeVariables;
this.generics = generics; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/SmartClassLoader.java | @@ -38,6 +38,6 @@ public interface SmartClassLoader {
* @return whether the class should be expected to appear in a reloaded
* version (with a different {@code Class} object) later on
*/
- boolean isClassReloadable(Class clazz);
+ boolean isClassReloadable(Class<?> clazz);
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java | @@ -50,7 +50,7 @@ protected int getOrder(Object obj) {
return ((Ordered) obj).getOrder();
}
if (obj != null) {
- Class<?> clazz = (obj instanceof Class ? (Class) obj : obj.getClass());
+ Class<?> clazz = (obj instanceof Class ? (Class<?>) obj : obj.getClass());
Order order = AnnotationUtils.findAnnotation(clazz, Order.class);
if (order != null) {
return order.value();
@@ -99,7 +99,7 @@ public static void sortIfNecessary(Object value) {
sort((Object[]) value);
}
else if (value instanceof List) {
- sort((List) value);
+ sort((List<?>) value);
}
}
| true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java | @@ -523,7 +523,7 @@ public static Object getValue(Annotation annotation) {
*/
public static Object getValue(Annotation annotation, String attributeName) {
try {
- Method method = annotation.annotationType().getDeclaredMethod(attributeName, new Class[0]);
+ Method method = annotation.annotationType().getDeclaredMethod(attributeName, new Class<?>[0]);
ReflectionUtils.makeAccessible(method);
return method.invoke(annotation);
}
@@ -574,7 +574,7 @@ public static Object getDefaultValue(Class<? extends Annotation> annotationType)
*/
public static Object getDefaultValue(Class<? extends Annotation> annotationType, String attributeName) {
try {
- Method method = annotationType.getDeclaredMethod(attributeName, new Class[0]);
+ Method method = annotationType.getDeclaredMethod(attributeName, new Class<?>[0]);
return method.getDefaultValue();
}
catch (Exception ex) { | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java | @@ -56,7 +56,6 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
}
@Override
- @SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/convert/support/CollectionToCollectionConverter.java | @@ -56,7 +56,6 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
}
@Override
- @SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java | @@ -28,7 +28,6 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import org.springframework.core.GenericTypeResolver;
import org.springframework.core.ResolvableType;
import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.ConversionFailedException; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java | @@ -52,7 +52,6 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
}
@Override
- @SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java | @@ -56,7 +56,6 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
}
@Override
- @SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/io/ClassRelativeResourceLoader.java | @@ -30,14 +30,14 @@
*/
public class ClassRelativeResourceLoader extends DefaultResourceLoader {
- private final Class clazz;
+ private final Class<?> clazz;
/**
* Create a new ClassRelativeResourceLoader for the given class.
* @param clazz the class to load resources through
*/
- public ClassRelativeResourceLoader(Class clazz) {
+ public ClassRelativeResourceLoader(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
this.clazz = clazz;
setClassLoader(clazz.getClassLoader());
@@ -55,9 +55,9 @@ protected Resource getResourceByPath(String path) {
*/
private static class ClassRelativeContextResource extends ClassPathResource implements ContextResource {
- private final Class clazz;
+ private final Class<?> clazz;
- public ClassRelativeContextResource(String path, Class clazz) {
+ public ClassRelativeContextResource(String path, Class<?> clazz) {
super(path, clazz);
this.clazz = clazz;
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java | @@ -175,9 +175,9 @@ public static Properties loadAllProperties(String resourceName, ClassLoader clas
clToUse = ClassUtils.getDefaultClassLoader();
}
Properties props = new Properties();
- Enumeration urls = clToUse.getResources(resourceName);
+ Enumeration<URL> urls = clToUse.getResources(resourceName);
while (urls.hasMoreElements()) {
- URL url = (URL) urls.nextElement();
+ URL url = urls.nextElement();
URLConnection con = url.openConnection();
ResourceUtils.useCachesIfNecessary(con);
InputStream is = con.getInputStream(); | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/style/DefaultValueStyler.java | @@ -57,20 +57,20 @@ else if (value instanceof String) {
return "\'" + value + "\'";
}
else if (value instanceof Class) {
- return ClassUtils.getShortName((Class) value);
+ return ClassUtils.getShortName((Class<?>) value);
}
else if (value instanceof Method) {
Method method = (Method) value;
return method.getName() + "@" + ClassUtils.getShortName(method.getDeclaringClass());
}
else if (value instanceof Map) {
- return style((Map) value);
+ return style((Map<?, ?>) value);
}
else if (value instanceof Map.Entry) {
- return style((Map.Entry) value);
+ return style((Map.Entry<? ,?>) value);
}
else if (value instanceof Collection) {
- return style((Collection) value);
+ return style((Collection<?>) value);
}
else if (value.getClass().isArray()) {
return styleArray(ObjectUtils.toObjectArray(value));
@@ -80,11 +80,11 @@ else if (value.getClass().isArray()) {
}
}
- private String style(Map value) {
+ private <K, V> String style(Map<K, V> value) {
StringBuilder result = new StringBuilder(value.size() * 8 + 16);
result.append(MAP + "[");
- for (Iterator it = value.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+ for (Iterator<Map.Entry<K, V>> it = value.entrySet().iterator(); it.hasNext();) {
+ Map.Entry<K, V> entry = it.next();
result.append(style(entry));
if (it.hasNext()) {
result.append(',').append(' ');
@@ -97,14 +97,14 @@ private String style(Map value) {
return result.toString();
}
- private String style(Map.Entry value) {
+ private String style(Map.Entry<?, ?> value) {
return style(value.getKey()) + " -> " + style(value.getValue());
}
- private String style(Collection value) {
+ private String style(Collection<?> value) {
StringBuilder result = new StringBuilder(value.size() * 8 + 16);
result.append(getCollectionTypeString(value)).append('[');
- for (Iterator i = value.iterator(); i.hasNext();) {
+ for (Iterator<?> i = value.iterator(); i.hasNext();) {
result.append(style(i.next()));
if (i.hasNext()) {
result.append(',').append(' ');
@@ -117,7 +117,7 @@ private String style(Collection value) {
return result.toString();
}
- private String getCollectionTypeString(Collection value) {
+ private String getCollectionTypeString(Collection<?> value) {
if (value instanceof List) {
return LIST;
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/type/StandardClassMetadata.java | @@ -30,22 +30,22 @@
*/
public class StandardClassMetadata implements ClassMetadata {
- private final Class introspectedClass;
+ private final Class<?> introspectedClass;
/**
* Create a new StandardClassMetadata wrapper for the given Class.
* @param introspectedClass the Class to introspect
*/
- public StandardClassMetadata(Class introspectedClass) {
+ public StandardClassMetadata(Class<?> introspectedClass) {
Assert.notNull(introspectedClass, "Class must not be null");
this.introspectedClass = introspectedClass;
}
/**
* Return the underlying Class.
*/
- public final Class getIntrospectedClass() {
+ public final Class<?> getIntrospectedClass() {
return this.introspectedClass;
}
@@ -89,7 +89,7 @@ public boolean hasEnclosingClass() {
@Override
public String getEnclosingClassName() {
- Class enclosingClass = this.introspectedClass.getEnclosingClass();
+ Class<?> enclosingClass = this.introspectedClass.getEnclosingClass();
return (enclosingClass != null ? enclosingClass.getName() : null);
}
@@ -100,13 +100,13 @@ public boolean hasSuperClass() {
@Override
public String getSuperClassName() {
- Class superClass = this.introspectedClass.getSuperclass();
+ Class<?> superClass = this.introspectedClass.getSuperclass();
return (superClass != null ? superClass.getName() : null);
}
@Override
public String[] getInterfaceNames() {
- Class[] ifcs = this.introspectedClass.getInterfaces();
+ Class<?>[] ifcs = this.introspectedClass.getInterfaces();
String[] ifcNames = new String[ifcs.length];
for (int i = 0; i < ifcs.length; i++) {
ifcNames[i] = ifcs[i].getName(); | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationReadingVisitorUtils.java | @@ -60,7 +60,7 @@ else if (value instanceof Type) {
}
else if (value instanceof Type[]) {
Type[] array = (Type[]) value;
- Object[] convArray = (classValuesAsString ? new String[array.length] : new Class[array.length]);
+ Object[] convArray = (classValuesAsString ? new String[array.length] : new Class<?>[array.length]);
for (int i = 0; i < array.length; i++) {
convArray[i] = (classValuesAsString ? array[i].getClassName() :
classLoader.loadClass(array[i].getClassName())); | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/core/type/filter/AssignableTypeFilter.java | @@ -26,14 +26,14 @@
*/
public class AssignableTypeFilter extends AbstractTypeHierarchyTraversingFilter {
- private final Class targetType;
+ private final Class<?> targetType;
/**
* Create a new AssignableTypeFilter for the given type.
* @param targetType the type to match
*/
- public AssignableTypeFilter(Class targetType) {
+ public AssignableTypeFilter(Class<?> targetType) {
super(true, true);
this.targetType = targetType;
}
@@ -63,7 +63,7 @@ else if (Object.class.getName().equals(typeName)) {
}
else if (typeName.startsWith("java.")) {
try {
- Class clazz = getClass().getClassLoader().loadClass(typeName);
+ Class<?> clazz = getClass().getClassLoader().loadClass(typeName);
return Boolean.valueOf(this.targetType.isAssignableFrom(clazz));
}
catch (ClassNotFoundException ex) { | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/Assert.java | @@ -263,7 +263,7 @@ public static void noNullElements(Object[] array) {
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the collection is {@code null} or has no elements
*/
- public static void notEmpty(Collection collection, String message) {
+ public static void notEmpty(Collection<?> collection, String message) {
if (CollectionUtils.isEmpty(collection)) {
throw new IllegalArgumentException(message);
}
@@ -276,7 +276,7 @@ public static void notEmpty(Collection collection, String message) {
* @param collection the collection to check
* @throws IllegalArgumentException if the collection is {@code null} or has no elements
*/
- public static void notEmpty(Collection collection) {
+ public static void notEmpty(Collection<?> collection) {
notEmpty(collection,
"[Assertion failed] - this collection must not be empty: it must contain at least 1 element");
}
@@ -289,7 +289,7 @@ public static void notEmpty(Collection collection) {
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the map is {@code null} or has no entries
*/
- public static void notEmpty(Map map, String message) {
+ public static void notEmpty(Map<?, ?> map, String message) {
if (CollectionUtils.isEmpty(map)) {
throw new IllegalArgumentException(message);
}
@@ -302,7 +302,7 @@ public static void notEmpty(Map map, String message) {
* @param map the map to check
* @throws IllegalArgumentException if the map is {@code null} or has no entries
*/
- public static void notEmpty(Map map) {
+ public static void notEmpty(Map<?, ?> map) {
notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry");
}
| true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/AutoPopulatingList.java | @@ -123,7 +123,7 @@ public boolean contains(Object o) {
}
@Override
- public boolean containsAll(Collection c) {
+ public boolean containsAll(Collection<?> c) {
return this.backingList.containsAll(c);
}
| true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/ClassUtils.java | @@ -894,13 +894,13 @@ public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType) {
return true;
}
if (lhsType.isPrimitive()) {
- Class resolvedPrimitive = primitiveWrapperTypeMap.get(rhsType);
+ Class<?> resolvedPrimitive = primitiveWrapperTypeMap.get(rhsType);
if (resolvedPrimitive != null && lhsType.equals(resolvedPrimitive)) {
return true;
}
}
else {
- Class resolvedWrapper = primitiveTypeToWrapperMap.get(rhsType);
+ Class<?> resolvedWrapper = primitiveTypeToWrapperMap.get(rhsType);
if (resolvedWrapper != null && lhsType.isAssignableFrom(resolvedWrapper)) {
return true;
}
@@ -1002,7 +1002,7 @@ public static String classPackageAsResourcePath(Class<?> clazz) {
* @return a String of form "[com.foo.Bar, com.foo.Baz]"
* @see java.util.AbstractCollection#toString()
*/
- public static String classNamesToString(Class... classes) {
+ public static String classNamesToString(Class<?>... classes) {
return classNamesToString(Arrays.asList(classes));
}
@@ -1015,13 +1015,13 @@ public static String classNamesToString(Class... classes) {
* @return a String of form "[com.foo.Bar, com.foo.Baz]"
* @see java.util.AbstractCollection#toString()
*/
- public static String classNamesToString(Collection<Class> classes) {
+ public static String classNamesToString(Collection<Class<?>> classes) {
if (CollectionUtils.isEmpty(classes)) {
return "[]";
}
StringBuilder sb = new StringBuilder("[");
- for (Iterator<Class> it = classes.iterator(); it.hasNext(); ) {
- Class clazz = it.next();
+ for (Iterator<Class<?>> it = classes.iterator(); it.hasNext(); ) {
+ Class<?> clazz = it.next();
sb.append(clazz.getName());
if (it.hasNext()) {
sb.append(", ");
@@ -1077,8 +1077,8 @@ public static Class<?>[] getAllInterfacesForClass(Class<?> clazz) {
* @return all interfaces that the given object implements as array
*/
public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, ClassLoader classLoader) {
- Set<Class> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader);
- return ifcs.toArray(new Class[ifcs.size()]);
+ Set<Class<?>> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader);
+ return ifcs.toArray(new Class<?>[ifcs.size()]);
}
/**
@@ -1087,7 +1087,7 @@ public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, ClassLoader cl
* @param instance the instance to analyze for interfaces
* @return all interfaces that the given instance implements as Set
*/
- public static Set<Class> getAllInterfacesAsSet(Object instance) {
+ public static Set<Class<?>> getAllInterfacesAsSet(Object instance) {
Assert.notNull(instance, "Instance must not be null");
return getAllInterfacesForClassAsSet(instance.getClass());
}
@@ -1099,7 +1099,7 @@ public static Set<Class> getAllInterfacesAsSet(Object instance) {
* @param clazz the class to analyze for interfaces
* @return all interfaces that the given object implements as Set
*/
- public static Set<Class> getAllInterfacesForClassAsSet(Class clazz) {
+ public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz) {
return getAllInterfacesForClassAsSet(clazz, null);
}
@@ -1112,12 +1112,12 @@ public static Set<Class> getAllInterfacesForClassAsSet(Class clazz) {
* (may be {@code null} when accepting all declared interfaces)
* @return all interfaces that the given object implements as Set
*/
- public static Set<Class> getAllInterfacesForClassAsSet(Class clazz, ClassLoader classLoader) {
+ public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, ClassLoader classLoader) {
Assert.notNull(clazz, "Class must not be null");
if (clazz.isInterface() && isVisible(clazz, classLoader)) {
- return Collections.singleton(clazz);
+ return Collections.<Class<?>>singleton(clazz);
}
- Set<Class> interfaces = new LinkedHashSet<Class>();
+ Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>();
while (clazz != null) {
Class<?>[] ifcs = clazz.getInterfaces();
for (Class<?> ifc : ifcs) { | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/CollectionUtils.java | @@ -47,7 +47,7 @@ public abstract class CollectionUtils {
* @param collection the Collection to check
* @return whether the given Collection is empty
*/
- public static boolean isEmpty(Collection collection) {
+ public static boolean isEmpty(Collection<?> collection) {
return (collection == null || collection.isEmpty());
}
@@ -57,7 +57,7 @@ public static boolean isEmpty(Collection collection) {
* @param map the Map to check
* @return whether the given Map is empty
*/
- public static boolean isEmpty(Map map) {
+ public static boolean isEmpty(Map<?, ?> map) {
return (map == null || map.isEmpty());
}
@@ -70,8 +70,9 @@ public static boolean isEmpty(Map map) {
* @return the converted List result
* @see ObjectUtils#toObjectArray(Object)
*/
- public static List arrayToList(Object source) {
- return Arrays.asList(ObjectUtils.toObjectArray(source));
+ @SuppressWarnings("unchecked")
+ public static <E> List<E> arrayToList(Object source) {
+ return (List<E>) Arrays.asList(ObjectUtils.toObjectArray(source));
}
/**
@@ -80,13 +81,13 @@ public static List arrayToList(Object source) {
* @param collection the target Collection to merge the array into
*/
@SuppressWarnings("unchecked")
- public static void mergeArrayIntoCollection(Object array, Collection collection) {
+ public static <E> void mergeArrayIntoCollection(Object array, Collection<E> collection) {
if (collection == null) {
throw new IllegalArgumentException("Collection must not be null");
}
Object[] arr = ObjectUtils.toObjectArray(array);
for (Object elem : arr) {
- collection.add(elem);
+ collection.add((E) elem);
}
}
@@ -99,19 +100,19 @@ public static void mergeArrayIntoCollection(Object array, Collection collection)
* @param map the target Map to merge the properties into
*/
@SuppressWarnings("unchecked")
- public static void mergePropertiesIntoMap(Properties props, Map map) {
+ public static <K, V> void mergePropertiesIntoMap(Properties props, Map<K, V> map) {
if (map == null) {
throw new IllegalArgumentException("Map must not be null");
}
if (props != null) {
- for (Enumeration en = props.propertyNames(); en.hasMoreElements();) {
+ for (Enumeration<?> en = props.propertyNames(); en.hasMoreElements();) {
String key = (String) en.nextElement();
Object value = props.getProperty(key);
if (value == null) {
// Potentially a non-String value...
value = props.get(key);
}
- map.put(key, value);
+ map.put((K) key, (V) value);
}
}
}
@@ -123,7 +124,7 @@ public static void mergePropertiesIntoMap(Properties props, Map map) {
* @param element the element to look for
* @return {@code true} if found, {@code false} else
*/
- public static boolean contains(Iterator iterator, Object element) {
+ public static boolean contains(Iterator<?> iterator, Object element) {
if (iterator != null) {
while (iterator.hasNext()) {
Object candidate = iterator.next();
@@ -141,7 +142,7 @@ public static boolean contains(Iterator iterator, Object element) {
* @param element the element to look for
* @return {@code true} if found, {@code false} else
*/
- public static boolean contains(Enumeration enumeration, Object element) {
+ public static boolean contains(Enumeration<?> enumeration, Object element) {
if (enumeration != null) {
while (enumeration.hasMoreElements()) {
Object candidate = enumeration.nextElement();
@@ -161,7 +162,7 @@ public static boolean contains(Enumeration enumeration, Object element) {
* @param element the element to look for
* @return {@code true} if found, {@code false} else
*/
- public static boolean containsInstance(Collection collection, Object element) {
+ public static boolean containsInstance(Collection<?> collection, Object element) {
if (collection != null) {
for (Object candidate : collection) {
if (candidate == element) {
@@ -179,7 +180,7 @@ public static boolean containsInstance(Collection collection, Object element) {
* @param candidates the candidates to search for
* @return whether any of the candidates has been found
*/
- public static boolean containsAny(Collection source, Collection candidates) {
+ public static boolean containsAny(Collection<?> source, Collection<?> candidates) {
if (isEmpty(source) || isEmpty(candidates)) {
return false;
}
@@ -200,13 +201,14 @@ public static boolean containsAny(Collection source, Collection candidates) {
* @param candidates the candidates to search for
* @return the first present object, or {@code null} if not found
*/
- public static Object findFirstMatch(Collection source, Collection candidates) {
+ @SuppressWarnings("unchecked")
+ public static <E> E findFirstMatch(Collection<?> source, Collection<E> candidates) {
if (isEmpty(source) || isEmpty(candidates)) {
return null;
}
for (Object candidate : candidates) {
if (source.contains(candidate)) {
- return candidate;
+ return (E) candidate;
}
}
return null;
@@ -265,7 +267,7 @@ public static Object findValueOfType(Collection<?> collection, Class<?>[] types)
* @return {@code true} if the collection contains a single reference or
* multiple references to the same instance, {@code false} else
*/
- public static boolean hasUniqueObject(Collection collection) {
+ public static boolean hasUniqueObject(Collection<?> collection) {
if (isEmpty(collection)) {
return false;
}
@@ -289,7 +291,7 @@ else if (candidate != elem) {
* @return the common element type, or {@code null} if no clear
* common type has been found (or the collection was empty)
*/
- public static Class<?> findCommonElementType(Collection collection) {
+ public static Class<?> findCommonElementType(Collection<?> collection) {
if (isEmpty(collection)) {
return null;
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/MethodInvoker.java | @@ -168,7 +168,7 @@ public void prepare() throws ClassNotFoundException, NoSuchMethodException {
}
Object[] arguments = getArguments();
- Class[] argTypes = new Class[arguments.length];
+ Class<?>[] argTypes = new Class<?>[arguments.length];
for (int i = 0; i < arguments.length; ++i) {
argTypes[i] = (arguments[i] != null ? arguments[i].getClass() : Object.class);
}
@@ -216,7 +216,7 @@ protected Method findMatchingMethod() {
for (Method candidate : candidates) {
if (candidate.getName().equals(targetMethod)) {
- Class[] paramTypes = candidate.getParameterTypes();
+ Class<?>[] paramTypes = candidate.getParameterTypes();
if (paramTypes.length == argCount) {
int typeDiffWeight = getTypeDifferenceWeight(paramTypes, arguments);
if (typeDiffWeight < minTypeDiffWeight) { | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/NumberUtils.java | @@ -115,7 +115,7 @@ else if (targetClass.equals(BigDecimal.class)) {
* @param number the number we tried to convert
* @param targetClass the target class we tried to convert to
*/
- private static void raiseOverflowException(Number number, Class targetClass) {
+ private static void raiseOverflowException(Number number, Class<?> targetClass) {
throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" +
number.getClass().getName() + "] to target class [" + targetClass.getName() + "]: overflow");
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/ObjectUtils.java | @@ -69,7 +69,7 @@ public static boolean isCheckedException(Throwable ex) {
* @param declaredExceptions the exceptions declared in the throws clause
* @return whether the given exception is compatible
*/
- public static boolean isCompatibleWithThrowsClause(Throwable ex, Class[] declaredExceptions) {
+ public static boolean isCompatibleWithThrowsClause(Throwable ex, Class<?>[] declaredExceptions) {
if (!isCheckedException(ex)) {
return true;
}
@@ -218,7 +218,7 @@ public static Object[] toObjectArray(Object source) {
if (length == 0) {
return new Object[0];
}
- Class wrapperType = Array.get(source, 0).getClass();
+ Class<?> wrapperType = Array.get(source, 0).getClass();
Object[] newArray = (Object[]) Array.newInstance(wrapperType, length);
for (int i = 0; i < length; i++) {
newArray[i] = Array.get(source, i);
@@ -286,7 +286,7 @@ public static boolean nullSafeEquals(Object o1, Object o2) {
/**
* Return as hash code for the given object; typically the value of
- * {@code {@link Object#hashCode()}}. If the object is an array,
+ * {@code Object#hashCode()}}. If the object is an array,
* this method will delegate to any of the {@code nullSafeHashCode}
* methods for arrays in this class. If the object is {@code null},
* this method returns 0. | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/ReflectionUtils.java | @@ -133,7 +133,7 @@ public static Object getField(Field field, Object target) {
* @return the Method object, or {@code null} if none found
*/
public static Method findMethod(Class<?> clazz, String name) {
- return findMethod(clazz, name, new Class[0]);
+ return findMethod(clazz, name, new Class<?>[0]);
}
/** | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/WeakReferenceMonitor.java | @@ -53,7 +53,7 @@ public class WeakReferenceMonitor {
private static final ReferenceQueue<Object> handleQueue = new ReferenceQueue<Object>();
// All tracked entries (WeakReference => ReleaseListener)
- private static final Map<Reference, ReleaseListener> trackedEntries = new HashMap<Reference, ReleaseListener>();
+ private static final Map<Reference<?>, ReleaseListener> trackedEntries = new HashMap<Reference<?>, ReleaseListener>();
// Thread polling handleQueue, lazy initialized
private static Thread monitoringThread = null;
@@ -84,7 +84,7 @@ public static void monitor(Object handle, ReleaseListener listener) {
* @param ref reference to tracked handle
* @param entry the associated entry
*/
- private static void addEntry(Reference ref, ReleaseListener entry) {
+ private static void addEntry(Reference<?> ref, ReleaseListener entry) {
synchronized (WeakReferenceMonitor.class) {
// Add entry, the key is given reference.
trackedEntries.put(ref, entry);
@@ -103,7 +103,7 @@ private static void addEntry(Reference ref, ReleaseListener entry) {
* @param reference the reference that should be removed
* @return entry object associated with given reference
*/
- private static ReleaseListener removeEntry(Reference reference) {
+ private static ReleaseListener removeEntry(Reference<?> reference) {
synchronized (WeakReferenceMonitor.class) {
return trackedEntries.remove(reference);
}
@@ -138,7 +138,7 @@ public void run() {
// Check if there are any tracked entries left.
while (keepMonitoringThreadAlive()) {
try {
- Reference reference = handleQueue.remove();
+ Reference<?> reference = handleQueue.remove();
// Stop tracking this reference.
ReleaseListener entry = removeEntry(reference);
if (entry != null) { | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/comparator/CompoundComparator.java | @@ -37,10 +37,10 @@
* @author Juergen Hoeller
* @since 1.2.2
*/
-@SuppressWarnings("serial")
+@SuppressWarnings({ "serial", "rawtypes" })
public class CompoundComparator<T> implements Comparator<T>, Serializable {
- private final List<InvertibleComparator<T>> comparators;
+ private final List<InvertibleComparator> comparators;
/**
@@ -49,7 +49,7 @@
* IllegalStateException is thrown.
*/
public CompoundComparator() {
- this.comparators = new ArrayList<InvertibleComparator<T>>();
+ this.comparators = new ArrayList<InvertibleComparator>();
}
/**
@@ -62,7 +62,7 @@ public CompoundComparator() {
@SuppressWarnings({ "unchecked", "rawtypes" })
public CompoundComparator(Comparator... comparators) {
Assert.notNull(comparators, "Comparators must not be null");
- this.comparators = new ArrayList<InvertibleComparator<T>>(comparators.length);
+ this.comparators = new ArrayList<InvertibleComparator>(comparators.length);
for (Comparator comparator : comparators) {
this.addComparator(comparator);
}
@@ -76,12 +76,13 @@ public CompoundComparator(Comparator... comparators) {
* @param comparator the Comparator to add to the end of the chain
* @see InvertibleComparator
*/
- public void addComparator(Comparator<T> comparator) {
+ @SuppressWarnings("unchecked")
+ public void addComparator(Comparator<? extends T> comparator) {
if (comparator instanceof InvertibleComparator) {
- this.comparators.add((InvertibleComparator<T>) comparator);
+ this.comparators.add((InvertibleComparator) comparator);
}
else {
- this.comparators.add(new InvertibleComparator<T>(comparator));
+ this.comparators.add(new InvertibleComparator(comparator));
}
}
@@ -90,8 +91,9 @@ public void addComparator(Comparator<T> comparator) {
* @param comparator the Comparator to add to the end of the chain
* @param ascending the sort order: ascending (true) or descending (false)
*/
- public void addComparator(Comparator<T> comparator, boolean ascending) {
- this.comparators.add(new InvertibleComparator<T>(comparator, ascending));
+ @SuppressWarnings("unchecked")
+ public void addComparator(Comparator<? extends T> comparator, boolean ascending) {
+ this.comparators.add(new InvertibleComparator(comparator, ascending));
}
/**
@@ -102,12 +104,13 @@ public void addComparator(Comparator<T> comparator, boolean ascending) {
* @param comparator the Comparator to place at the given index
* @see InvertibleComparator
*/
- public void setComparator(int index, Comparator<T> comparator) {
+ @SuppressWarnings("unchecked")
+ public void setComparator(int index, Comparator<? extends T> comparator) {
if (comparator instanceof InvertibleComparator) {
- this.comparators.set(index, (InvertibleComparator<T>) comparator);
+ this.comparators.set(index, (InvertibleComparator) comparator);
}
else {
- this.comparators.set(index, new InvertibleComparator<T>(comparator));
+ this.comparators.set(index, new InvertibleComparator(comparator));
}
}
@@ -126,7 +129,7 @@ public void setComparator(int index, Comparator<T> comparator, boolean ascending
* comparator.
*/
public void invertOrder() {
- for (InvertibleComparator<T> comparator : this.comparators) {
+ for (InvertibleComparator comparator : this.comparators) {
comparator.invertOrder();
}
}
@@ -163,10 +166,11 @@ public int getComparatorCount() {
}
@Override
+ @SuppressWarnings("unchecked")
public int compare(T o1, T o2) {
Assert.state(this.comparators.size() > 0,
"No sort definitions have been added to this CompoundComparator to compare");
- for (InvertibleComparator<T> comparator : this.comparators) {
+ for (InvertibleComparator comparator : this.comparators) {
int result = comparator.compare(o1, o2);
if (result != 0) {
return result; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java | @@ -64,7 +64,7 @@
* @see #NULLS_LOW
* @see #NULLS_HIGH
*/
- @SuppressWarnings({ "unchecked"})
+ @SuppressWarnings({ "unchecked", "rawtypes"})
private NullSafeComparator(boolean nullsLow) {
this.nonNullComparator = new ComparableComparator();
this.nullsLow = nullsLow; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/xml/DomUtils.java | @@ -184,7 +184,7 @@ private static boolean nodeNameMatch(Node node, String desiredName) {
/**
* Matches the given node's name and local name against the given desired names.
*/
- private static boolean nodeNameMatch(Node node, Collection desiredNames) {
+ private static boolean nodeNameMatch(Node node, Collection<?> desiredNames) {
return (desiredNames.contains(node.getNodeName()) || desiredNames.contains(node.getLocalName()));
}
| true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/xml/SimpleNamespaceContext.java | @@ -63,12 +63,12 @@ else if (prefixToNamespaceUri.containsKey(prefix)) {
@Override
public String getPrefix(String namespaceUri) {
- List prefixes = getPrefixesInternal(namespaceUri);
+ List<?> prefixes = getPrefixesInternal(namespaceUri);
return prefixes.isEmpty() ? null : (String) prefixes.get(0);
}
@Override
- public Iterator getPrefixes(String namespaceUri) {
+ public Iterator<String> getPrefixes(String namespaceUri) {
return getPrefixesInternal(namespaceUri).iterator();
}
@@ -155,7 +155,7 @@ public void removeBinding(String prefix) {
}
else {
String namespaceUri = prefixToNamespaceUri.remove(prefix);
- List prefixes = getPrefixesInternal(namespaceUri);
+ List<String> prefixes = getPrefixesInternal(namespaceUri);
prefixes.remove(prefix);
}
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/xml/StaxEventContentHandler.java | @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
@@ -29,11 +30,10 @@
import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.util.XMLEventConsumer;
+import org.springframework.util.StringUtils;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
-import org.springframework.util.StringUtils;
-
/**
* SAX {@code ContentHandler} that transforms callback calls to {@code XMLEvent}s
* and writes them to a {@code XMLEventConsumer}.
@@ -92,15 +92,15 @@ protected void endDocumentInternal() throws XMLStreamException {
protected void startElementInternal(QName name, Attributes atts, SimpleNamespaceContext namespaceContext)
throws XMLStreamException {
- List attributes = getAttributes(atts);
- List namespaces = createNamespaces(namespaceContext);
+ List<Attribute> attributes = getAttributes(atts);
+ List<Namespace> namespaces = createNamespaces(namespaceContext);
consumeEvent(this.eventFactory.createStartElement(name, attributes.iterator(),
(namespaces != null ? namespaces.iterator() : null)));
}
@Override
protected void endElementInternal(QName name, SimpleNamespaceContext namespaceContext) throws XMLStreamException {
- List namespaces = createNamespaces(namespaceContext);
+ List<Namespace> namespaces = createNamespaces(namespaceContext);
consumeEvent(this.eventFactory.createEndElement(name, namespaces != null ? namespaces.iterator() : null));
}
@@ -136,8 +136,8 @@ private List<Namespace> createNamespaces(SimpleNamespaceContext namespaceContext
if (StringUtils.hasLength(defaultNamespaceUri)) {
namespaces.add(this.eventFactory.createNamespace(defaultNamespaceUri));
}
- for (Iterator iterator = namespaceContext.getBoundPrefixes(); iterator.hasNext();) {
- String prefix = (String) iterator.next();
+ for (Iterator<String> iterator = namespaceContext.getBoundPrefixes(); iterator.hasNext();) {
+ String prefix = iterator.next();
String namespaceUri = namespaceContext.getNamespaceURI(prefix);
namespaces.add(this.eventFactory.createNamespace(prefix, namespaceUri));
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/xml/StaxEventXMLReader.java | @@ -17,8 +17,7 @@
package org.springframework.util.xml;
import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
+
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLEventReader;
@@ -38,14 +37,13 @@
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
+import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.ext.Locator2;
import org.xml.sax.helpers.AttributesImpl;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
-
/**
* SAX {@code XMLReader} that reads from a StAX {@code XMLEventReader}. Consumes {@code XMLEvents} from
* an {@code XMLEventReader}, and calls the corresponding methods on the SAX callback interfaces.
@@ -58,14 +56,13 @@
* @see #setEntityResolver(org.xml.sax.EntityResolver)
* @see #setErrorHandler(org.xml.sax.ErrorHandler)
*/
+@SuppressWarnings("rawtypes")
class StaxEventXMLReader extends AbstractStaxXMLReader {
private static final String DEFAULT_XML_VERSION = "1.0";
private final XMLEventReader reader;
- private final Map<String, String> namespaces = new LinkedHashMap<String, String>();
-
private String xmlVersion = DEFAULT_XML_VERSION;
private String encoding; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/xml/XMLEventStreamReader.java | @@ -17,6 +17,7 @@
package org.springframework.util.xml;
import java.util.Iterator;
+
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
@@ -38,6 +39,7 @@
* @since 3.0
* @see StaxUtils#createEventStreamReader(javax.xml.stream.XMLEventReader)
*/
+@SuppressWarnings("rawtypes")
class XMLEventStreamReader extends AbstractXMLStreamReader {
private XMLEvent event; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/main/java/org/springframework/util/xml/XMLEventStreamWriter.java | @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventFactory;
@@ -38,6 +39,7 @@
* @since 3.0.5
* @see StaxUtils#createEventStreamWriter(javax.xml.stream.XMLEventWriter, javax.xml.stream.XMLEventFactory)
*/
+@SuppressWarnings("rawtypes")
class XMLEventStreamWriter implements XMLStreamWriter {
private static final String DEFAULT_ENCODING = "UTF-8"; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java | @@ -75,6 +75,7 @@ public void methodReturnTypes() {
}
@Test
+ @Deprecated
public void testResolveType() {
Method intMessageMethod = findMethod(MyTypeWithMethods.class, "readIntegerInputMessage", MyInterfaceType.class);
MethodParameter intMessageMethodParam = new MethodParameter(intMessageMethod, 0);
@@ -100,6 +101,7 @@ public void testBoundParameterizedType() {
}
@Test
+ @Deprecated
public void testGetTypeVariableMap() throws Exception {
Map<TypeVariable, Type> map;
| true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java | @@ -1230,11 +1230,13 @@ private static interface AssertAssignbleMatcher {
}
+ @SuppressWarnings("serial")
static class ExtendsList extends ArrayList<CharSequence> {
}
+ @SuppressWarnings("serial")
static class ExtendsMap extends HashMap<String, Integer> {
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java | @@ -840,6 +840,7 @@ public void passDownGeneric() throws Exception {
public PassDownGeneric<Integer> passDownGeneric = new PassDownGeneric<Integer>();
+ @SuppressWarnings("serial")
public static class PassDownGeneric<T> extends ArrayList<List<Set<T>>> {
}
| true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-expression/src/main/java/org/springframework/expression/Expression.java | @@ -112,7 +112,7 @@ public interface Expression {
* @return the most general type of value that can be set on this context
* @throws EvaluationException if there is a problem determining the type
*/
- Class getValueType() throws EvaluationException;
+ Class<?> getValueType() throws EvaluationException;
/**
* Returns the most general type that can be passed to the {@link #setValue(EvaluationContext, Object)}
@@ -121,7 +121,7 @@ public interface Expression {
* @return the most general type of value that can be set on this context
* @throws EvaluationException if there is a problem determining the type
*/
- Class getValueType(Object rootObject) throws EvaluationException;
+ Class<?> getValueType(Object rootObject) throws EvaluationException;
/**
* Returns the most general type that can be passed to the {@link #setValue(EvaluationContext, Object)}
@@ -130,7 +130,7 @@ public interface Expression {
* @return the most general type of value that can be set on this context
* @throws EvaluationException if there is a problem determining the type
*/
- Class getValueType(EvaluationContext context) throws EvaluationException;
+ Class<?> getValueType(EvaluationContext context) throws EvaluationException;
/**
* Returns the most general type that can be passed to the {@link #setValue(EvaluationContext, Object)}
@@ -140,7 +140,7 @@ public interface Expression {
* @return the most general type of value that can be set on this context
* @throws EvaluationException if there is a problem determining the type
*/
- Class getValueType(EvaluationContext context, Object rootObject) throws EvaluationException;
+ Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException;
/**
* Returns the most general type that can be passed to the {@link #setValue(EvaluationContext, Object)} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-expression/src/main/java/org/springframework/expression/PropertyAccessor.java | @@ -40,7 +40,7 @@ public interface PropertyAccessor {
* @return an array of classes that this resolver is suitable for (or null if a
* general resolver)
*/
- Class[] getSpecificTargetClasses();
+ Class<?>[] getSpecificTargetClasses();
/**
* Called to determine if a resolver instance is able to access a specified property | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-expression/src/main/java/org/springframework/expression/common/CompositeStringExpression.java | @@ -26,15 +26,15 @@
* Represents a template expression broken into pieces. Each piece will be an Expression
* but pure text parts to the template will be represented as LiteralExpression objects.
* An example of a template expression might be:
- *
+ *
* <pre class="code">
* "Hello ${getName()}"
* </pre>
- *
+ *
* which will be represented as a CompositeStringExpression of two parts. The first part
* being a LiteralExpression representing 'Hello ' and the second part being a real
* expression that will call {@code getName()} when invoked.
- *
+ *
* @author Andy Clement
* @author Juergen Hoeller
* @since 3.0
@@ -107,12 +107,12 @@ public String getValue(EvaluationContext context, Object rootObject) throws Eval
}
@Override
- public Class getValueType(EvaluationContext context) {
+ public Class<?> getValueType(EvaluationContext context) {
return String.class;
}
@Override
- public Class getValueType() {
+ public Class<?> getValueType() {
return String.class;
}
@@ -167,12 +167,12 @@ public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> des
}
@Override
- public Class getValueType(Object rootObject) throws EvaluationException {
+ public Class<?> getValueType(Object rootObject) throws EvaluationException {
return String.class;
}
@Override
- public Class getValueType(EvaluationContext context, Object rootObject) throws EvaluationException {
+ public Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException {
return String.class;
}
| true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-expression/src/main/java/org/springframework/expression/common/LiteralExpression.java | @@ -63,7 +63,7 @@ public String getValue(Object rootObject) {
}
@Override
- public Class getValueType(EvaluationContext context) {
+ public Class<?> getValueType(EvaluationContext context) {
return String.class;
}
@@ -100,7 +100,7 @@ public boolean isWritable(EvaluationContext context) {
}
@Override
- public Class getValueType() {
+ public Class<?> getValueType() {
return String.class;
}
@@ -122,12 +122,12 @@ public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> des
}
@Override
- public Class getValueType(Object rootObject) throws EvaluationException {
+ public Class<?> getValueType(Object rootObject) throws EvaluationException {
return String.class;
}
@Override
- public Class getValueType(EvaluationContext context, Object rootObject) throws EvaluationException {
+ public Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException {
return String.class;
}
| true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-expression/src/main/java/org/springframework/expression/spel/ast/FormatHelper.java | @@ -66,7 +66,7 @@ public static String formatClassNameForMessage(Class<?> clazz) {
StringBuilder fmtd = new StringBuilder();
if (clazz.isArray()) {
int dims = 1;
- Class baseClass = clazz.getComponentType();
+ Class<?> baseClass = clazz.getComponentType();
while (baseClass.isArray()) {
baseClass = baseClass.getComponentType();
dims++; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-expression/src/main/java/org/springframework/expression/spel/ast/SpelNodeImpl.java | @@ -73,7 +73,7 @@ protected SpelNodeImpl getPreviousChild() {
/**
* @return true if the next child is one of the specified classes
*/
- protected boolean nextChildIs(Class... clazzes) {
+ protected boolean nextChildIs(Class<?>... clazzes) {
if (this.parent != null) {
SpelNodeImpl[] peers = this.parent.children;
for (int i = 0, max = peers.length; i < max; i++) {
@@ -82,8 +82,8 @@ protected boolean nextChildIs(Class... clazzes) {
return false;
}
- Class clazz = peers[i + 1].getClass();
- for (Class desiredClazz : clazzes) {
+ Class<?> clazz = peers[i + 1].getClass();
+ for (Class<?> desiredClazz : clazzes) {
if (clazz.equals(desiredClazz)) {
return true;
} | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java | @@ -60,7 +60,7 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
return new TypedValue(clazz);
}
- private Class makeArrayIfNecessary(Class clazz) {
+ private Class<?> makeArrayIfNecessary(Class<?> clazz) {
if (this.dimensions!=0) {
for (int i=0;i<this.dimensions;i++) {
Object o = Array.newInstance(clazz, 0); | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java | @@ -123,11 +123,11 @@ public static int getTypeDifferenceWeight(List<TypeDescriptor> paramTypes, List<
return Integer.MAX_VALUE;
}
if (argType != null) {
- Class paramTypeClazz = paramType.getType();
+ Class<?> paramTypeClazz = paramType.getType();
if (paramTypeClazz.isPrimitive()) {
paramTypeClazz = Object.class;
}
- Class superClass = argType.getClass().getSuperclass();
+ Class<?> superClass = argType.getClass().getSuperclass();
while (superClass != null) {
if (paramType.equals(superClass)) {
result = result + 2;
@@ -216,7 +216,7 @@ else if (typeConverter.canConvert(suppliedArg, expectedArg)) {
else {
// Now... we have the final argument in the method we are checking as a match and we have 0 or more other
// arguments left to pass to it.
- Class varargsParameterType = expectedArgTypes.get(expectedArgTypes.size() - 1).getElementTypeDescriptor().getType();
+ Class<?> varargsParameterType = expectedArgTypes.get(expectedArgTypes.size() - 1).getElementTypeDescriptor().getType();
// All remaining parameters must be of this type or convertable to this type
for (int i = expectedArgTypes.size() - 1; i < suppliedArgTypes.size(); i++) {
@@ -319,7 +319,7 @@ static void convertArguments(TypeConverter converter, Object[] arguments, Object
public static void convertAllArguments(TypeConverter converter, Object[] arguments, Method method) throws SpelEvaluationException {
Integer varargsPosition = null;
if (method.isVarArgs()) {
- Class[] paramTypes = method.getParameterTypes();
+ Class<?>[] paramTypes = method.getParameterTypes();
varargsPosition = paramTypes.length - 1;
}
for (int argPosition = 0; argPosition < arguments.length; argPosition++) {
@@ -361,7 +361,7 @@ public static void convertAllArguments(TypeConverter converter, Object[] argumen
* @param args the arguments to be setup ready for the invocation
* @return a repackaged array of arguments where any varargs setup has been done
*/
- public static Object[] setupArgumentsForVarargsInvocation(Class[] requiredParameterTypes, Object... args) {
+ public static Object[] setupArgumentsForVarargsInvocation(Class<?>[] requiredParameterTypes, Object... args) {
// Check if array already built for final argument
int parameterCount = requiredParameterTypes.length;
int argumentCount = args.length; | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorExecutor.java | @@ -46,7 +46,7 @@ class ReflectiveConstructorExecutor implements ConstructorExecutor {
public ReflectiveConstructorExecutor(Constructor<?> ctor, int[] argsRequiringConversion) {
this.ctor = ctor;
if (ctor.isVarArgs()) {
- Class[] paramTypes = ctor.getParameterTypes();
+ Class<?>[] paramTypes = ctor.getParameterTypes();
this.varargsPosition = paramTypes.length - 1;
}
else { | true |
Other | spring-projects | spring-framework | 59002f245623d758765b72d598cd78c326c6f5fa.json | 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 | spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorResolver.java | @@ -59,23 +59,23 @@ public ConstructorExecutor resolve(EvaluationContext context, String typename, L
try {
TypeConverter typeConverter = context.getTypeConverter();
Class<?> type = context.getTypeLocator().findType(typename);
- Constructor[] ctors = type.getConstructors();
+ Constructor<?>[] ctors = type.getConstructors();
- Arrays.sort(ctors, new Comparator<Constructor>() {
+ Arrays.sort(ctors, new Comparator<Constructor<?>>() {
@Override
- public int compare(Constructor c1, Constructor c2) {
+ public int compare(Constructor<?> c1, Constructor<?> c2) {
int c1pl = c1.getParameterTypes().length;
int c2pl = c2.getParameterTypes().length;
return (new Integer(c1pl)).compareTo(c2pl);
}
});
- Constructor closeMatch = null;
+ Constructor<?> closeMatch = null;
int[] argsToConvert = null;
- Constructor matchRequiringConversion = null;
+ Constructor<?> matchRequiringConversion = null;
- for (Constructor ctor : ctors) {
- Class[] paramTypes = ctor.getParameterTypes();
+ for (Constructor<?> ctor : ctors) {
+ Class<?>[] paramTypes = ctor.getParameterTypes();
List<TypeDescriptor> paramDescriptors = new ArrayList<TypeDescriptor>(paramTypes.length);
for (int i = 0; i < paramTypes.length; i++) {
paramDescriptors.add(new TypeDescriptor(new MethodParameter(ctor, i))); | true |
Other | spring-projects | spring-framework | 44c5eaeaa3f3bc2c45f4592a4551ec054bf4697b.json | Fix typo in Javadoc | spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java | @@ -54,7 +54,7 @@ public StandardAnnotationMetadata(Class<?> introspectedClass) {
* providing the option to return any nested annotations or annotation arrays in the
* form of {@link org.springframework.core.annotation.AnnotationAttributes} instead
* of actual {@link Annotation} instances.
- * @param introspectedClass the Class to instrospect
+ * @param introspectedClass the Class to introspect
* @param nestedAnnotationsAsMap return nested annotations and annotation arrays as
* {@link org.springframework.core.annotation.AnnotationAttributes} for compatibility
* with ASM-based {@link AnnotationMetadata} implementations | false |
Other | spring-projects | spring-framework | 127bc07cdaa2434b6fa4c8227faaa5fdcb9a9647.json | Delete unused package import | spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java | @@ -22,7 +22,6 @@
import org.hibernate.SessionFactory;
import org.hibernate.exception.ConstraintViolationException;
-import org.hibernate.exception.GenericJDBCException;
import org.junit.Before;
import org.junit.Test; | false |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpDec.java | @@ -16,6 +16,8 @@
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Operation;
import org.springframework.expression.TypedValue;
@@ -29,6 +31,7 @@
* appropriate exceptions if the operand in question does not support decrement.
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
* @since 3.2
*/
public class OpDec extends Operator {
@@ -58,7 +61,11 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
if (operandValue instanceof Number) {
Number op1 = (Number) operandValue;
- if (op1 instanceof Double) {
+ if (op1 instanceof BigDecimal) {
+ newValue = new TypedValue(((BigDecimal) op1).subtract(BigDecimal.ONE),
+ operandTypedValue.getTypeDescriptor());
+ }
+ else if (op1 instanceof Double) {
newValue = new TypedValue(op1.doubleValue() - 1.0d,
operandTypedValue.getTypeDescriptor());
}
@@ -79,7 +86,7 @@ else if (op1 instanceof Short) {
operandTypedValue.getTypeDescriptor());
}
}
- if (newValue==null) {
+ if (newValue == null) {
try {
newValue = state.operate(Operation.SUBTRACT, returnValue.getValue(), 1);
} | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpDivide.java | @@ -16,47 +16,62 @@
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Operation;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ExpressionState;
+import org.springframework.util.NumberUtils;
/**
* Implements division operator.
*
* @author Andy Clement
* @author Juergen Hoeller
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public class OpDivide extends Operator {
+
public OpDivide(int pos, SpelNodeImpl... operands) {
super("/", pos, operands);
}
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
- Object operandOne = getLeftOperand().getValueInternal(state).getValue();
- Object operandTwo = getRightOperand().getValueInternal(state).getValue();
- if (operandOne instanceof Number && operandTwo instanceof Number) {
- Number op1 = (Number) operandOne;
- Number op2 = (Number) operandTwo;
- if (op1 instanceof Double || op2 instanceof Double) {
- return new TypedValue(op1.doubleValue() / op2.doubleValue());
+ Object leftOperand = getLeftOperand().getValueInternal(state).getValue();
+ Object rightOperand = getRightOperand().getValueInternal(state).getValue();
+
+ if (leftOperand instanceof Number && rightOperand instanceof Number) {
+ Number leftNumber = (Number) leftOperand;
+ Number rightNumber = (Number) rightOperand;
+
+ if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) {
+ BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
+ BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
+ int scale = Math.max(leftBigDecimal.scale(), rightBigDecimal.scale());
+ return new TypedValue(leftBigDecimal.divide(rightBigDecimal, scale, RoundingMode.HALF_EVEN));
}
- else if (op1 instanceof Float || op2 instanceof Float) {
- return new TypedValue(op1.floatValue() / op2.floatValue());
+
+ if (leftNumber instanceof Double || rightNumber instanceof Double) {
+ return new TypedValue(leftNumber.doubleValue() / rightNumber.doubleValue());
}
- else if (op1 instanceof Long || op2 instanceof Long) {
- return new TypedValue(op1.longValue() / op2.longValue());
+ if (leftNumber instanceof Float || rightNumber instanceof Float) {
+ return new TypedValue(leftNumber.floatValue() / rightNumber.floatValue());
}
- else {
- // TODO what about non-int result of the division?
- return new TypedValue(op1.intValue() / op2.intValue());
+ if (leftNumber instanceof Long || rightNumber instanceof Long) {
+ return new TypedValue(leftNumber.longValue() / rightNumber.longValue());
}
+
+ // TODO what about non-int result of the division?
+ return new TypedValue(leftNumber.intValue() / rightNumber.intValue());
}
- return state.operate(Operation.DIVIDE, operandOne, operandTwo);
+
+ return state.operate(Operation.DIVIDE, leftOperand, rightOperand);
}
} | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpGE.java | @@ -15,18 +15,23 @@
*/
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+
import org.springframework.expression.EvaluationException;
import org.springframework.expression.spel.ExpressionState;
import org.springframework.expression.spel.support.BooleanTypedValue;
+import org.springframework.util.NumberUtils;
/**
* Implements greater-than-or-equal operator.
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public class OpGE extends Operator {
+
public OpGE(int pos, SpelNodeImpl... operands) {
super(">=", pos, operands);
}
@@ -39,18 +44,25 @@ public BooleanTypedValue getValueInternal(ExpressionState state) throws Evaluati
if (left instanceof Number && right instanceof Number) {
Number leftNumber = (Number) left;
Number rightNumber = (Number) right;
+
+ if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) {
+ BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
+ BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
+ return BooleanTypedValue.forValue(leftBigDecimal.compareTo(rightBigDecimal) >= 0);
+ }
+
if (leftNumber instanceof Double || rightNumber instanceof Double) {
return BooleanTypedValue.forValue(leftNumber.doubleValue() >= rightNumber.doubleValue());
}
- else if (leftNumber instanceof Float || rightNumber instanceof Float) {
+
+ if (leftNumber instanceof Float || rightNumber instanceof Float) {
return BooleanTypedValue.forValue(leftNumber.floatValue() >= rightNumber.floatValue());
}
- else if (leftNumber instanceof Long || rightNumber instanceof Long) {
+
+ if (leftNumber instanceof Long || rightNumber instanceof Long) {
return BooleanTypedValue.forValue(leftNumber.longValue() >= rightNumber.longValue());
}
- else {
- return BooleanTypedValue.forValue(leftNumber.intValue() >= rightNumber.intValue());
- }
+ return BooleanTypedValue.forValue(leftNumber.intValue() >= rightNumber.intValue());
}
return BooleanTypedValue.forValue(state.getTypeComparator().compare(left, right) >= 0);
} | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpGT.java | @@ -16,14 +16,18 @@
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+
import org.springframework.expression.EvaluationException;
import org.springframework.expression.spel.ExpressionState;
import org.springframework.expression.spel.support.BooleanTypedValue;
+import org.springframework.util.NumberUtils;
/**
* Implements greater-than operator.
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public class OpGT extends Operator {
@@ -38,21 +42,30 @@ public OpGT(int pos, SpelNodeImpl... operands) {
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
Object left = getLeftOperand().getValueInternal(state).getValue();
Object right = getRightOperand().getValueInternal(state).getValue();
+
if (left instanceof Number && right instanceof Number) {
Number leftNumber = (Number) left;
Number rightNumber = (Number) right;
+
+ if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) {
+ BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
+ BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
+ return BooleanTypedValue.forValue(leftBigDecimal.compareTo(rightBigDecimal) > 0);
+ }
+
if (leftNumber instanceof Double || rightNumber instanceof Double) {
return BooleanTypedValue.forValue(leftNumber.doubleValue() > rightNumber.doubleValue());
}
- else if (leftNumber instanceof Float || rightNumber instanceof Float) {
+
+ if (leftNumber instanceof Float || rightNumber instanceof Float) {
return BooleanTypedValue.forValue(leftNumber.floatValue() > rightNumber.floatValue());
}
- else if (leftNumber instanceof Long || rightNumber instanceof Long) {
+
+ if (leftNumber instanceof Long || rightNumber instanceof Long) {
return BooleanTypedValue.forValue(leftNumber.longValue() > rightNumber.longValue());
}
- else {
- return BooleanTypedValue.forValue(leftNumber.intValue() > rightNumber.intValue());
- }
+
+ return BooleanTypedValue.forValue(leftNumber.intValue() > rightNumber.intValue());
}
return BooleanTypedValue.forValue(state.getTypeComparator().compare(left, right) > 0);
} | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpInc.java | @@ -16,6 +16,8 @@
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Operation;
import org.springframework.expression.TypedValue;
@@ -29,6 +31,7 @@
* appropriate exceptions if the operand in question does not support increment.
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
* @since 3.2
*/
public class OpInc extends Operator {
@@ -47,34 +50,38 @@ public OpInc(int pos, boolean postfix, SpelNodeImpl... operands) {
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
SpelNodeImpl operand = getLeftOperand();
- ValueRef lvalue = operand.getValueRef(state);
+ ValueRef valueRef = operand.getValueRef(state);
- final TypedValue operandTypedValue = lvalue.getValue();
- final Object operandValue = operandTypedValue.getValue();
- TypedValue returnValue = operandTypedValue;
+ final TypedValue typedValue = valueRef.getValue();
+ final Object value = typedValue.getValue();
+ TypedValue returnValue = typedValue;
TypedValue newValue = null;
- if (operandValue instanceof Number) {
- Number op1 = (Number) operandValue;
- if (op1 instanceof Double) {
+ if (value instanceof Number) {
+ Number op1 = (Number) value;
+ if (op1 instanceof BigDecimal) {
+ newValue = new TypedValue(((BigDecimal) op1).add(BigDecimal.ONE),
+ typedValue.getTypeDescriptor());
+ }
+ else if (op1 instanceof Double) {
newValue = new TypedValue(op1.doubleValue() + 1.0d,
- operandTypedValue.getTypeDescriptor());
+ typedValue.getTypeDescriptor());
}
else if (op1 instanceof Float) {
newValue = new TypedValue(op1.floatValue() + 1.0f,
- operandTypedValue.getTypeDescriptor());
+ typedValue.getTypeDescriptor());
}
else if (op1 instanceof Long) {
newValue = new TypedValue(op1.longValue() + 1L,
- operandTypedValue.getTypeDescriptor());
+ typedValue.getTypeDescriptor());
}
else if (op1 instanceof Short) {
newValue = new TypedValue(op1.shortValue() + (short) 1,
- operandTypedValue.getTypeDescriptor());
+ typedValue.getTypeDescriptor());
}
else {
newValue = new TypedValue(op1.intValue() + 1,
- operandTypedValue.getTypeDescriptor());
+ typedValue.getTypeDescriptor());
}
}
if (newValue == null) {
@@ -93,7 +100,7 @@ else if (op1 instanceof Short) {
// set the name value
try {
- lvalue.setValue(newValue.getValue());
+ valueRef.setValue(newValue.getValue());
}
catch (SpelEvaluationException see) {
// if unable to set the value the operand is not writable (e.g. 1++ ) | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpLE.java | @@ -16,18 +16,23 @@
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+
import org.springframework.expression.EvaluationException;
import org.springframework.expression.spel.ExpressionState;
import org.springframework.expression.spel.support.BooleanTypedValue;
+import org.springframework.util.NumberUtils;
/**
* Implements the less-than-or-equal operator.
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public class OpLE extends Operator {
+
public OpLE(int pos, SpelNodeImpl... operands) {
super("<=", pos, operands);
}
@@ -41,19 +46,28 @@ public BooleanTypedValue getValueInternal(ExpressionState state)
if (left instanceof Number && right instanceof Number) {
Number leftNumber = (Number) left;
Number rightNumber = (Number) right;
+
+ if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) {
+ BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
+ BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
+ return BooleanTypedValue.forValue(leftBigDecimal.compareTo(rightBigDecimal) <= 0);
+ }
+
if (leftNumber instanceof Double || rightNumber instanceof Double) {
return BooleanTypedValue.forValue(leftNumber.doubleValue() <= rightNumber.doubleValue());
}
- else if (leftNumber instanceof Float || rightNumber instanceof Float) {
+
+ if (leftNumber instanceof Float || rightNumber instanceof Float) {
return BooleanTypedValue.forValue(leftNumber.floatValue() <= rightNumber.floatValue());
}
- else if (leftNumber instanceof Long || rightNumber instanceof Long) {
+
+ if (leftNumber instanceof Long || rightNumber instanceof Long) {
return BooleanTypedValue.forValue(leftNumber.longValue() <= rightNumber.longValue());
}
- else {
- return BooleanTypedValue.forValue(leftNumber.intValue() <= rightNumber.intValue());
- }
+
+ return BooleanTypedValue.forValue(leftNumber.intValue() <= rightNumber.intValue());
}
+
return BooleanTypedValue.forValue(state.getTypeComparator().compare(left, right) <= 0);
}
| true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpLT.java | @@ -16,14 +16,18 @@
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+
import org.springframework.expression.EvaluationException;
import org.springframework.expression.spel.ExpressionState;
import org.springframework.expression.spel.support.BooleanTypedValue;
+import org.springframework.util.NumberUtils;
/**
* Implements the less-than operator.
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public class OpLT extends Operator {
@@ -43,18 +47,26 @@ public BooleanTypedValue getValueInternal(ExpressionState state)
if (left instanceof Number && right instanceof Number) {
Number leftNumber = (Number) left;
Number rightNumber = (Number) right;
+
+ if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) {
+ BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
+ BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
+ return BooleanTypedValue.forValue(leftBigDecimal.compareTo(rightBigDecimal) < 0);
+ }
+
if (leftNumber instanceof Double || rightNumber instanceof Double) {
return BooleanTypedValue.forValue(leftNumber.doubleValue() < rightNumber.doubleValue());
}
- else if (leftNumber instanceof Float || rightNumber instanceof Float) {
+
+ if (leftNumber instanceof Float || rightNumber instanceof Float) {
return BooleanTypedValue.forValue(leftNumber.floatValue() < rightNumber.floatValue());
}
- else if (leftNumber instanceof Long || rightNumber instanceof Long) {
+
+ if (leftNumber instanceof Long || rightNumber instanceof Long) {
return BooleanTypedValue.forValue(leftNumber.longValue() < rightNumber.longValue());
}
- else {
- return BooleanTypedValue.forValue(leftNumber.intValue() < rightNumber.intValue());
- }
+
+ return BooleanTypedValue.forValue(leftNumber.intValue() < rightNumber.intValue());
}
return BooleanTypedValue.forValue(state.getTypeComparator().compare(left, right) < 0);
} | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpMinus.java | @@ -16,33 +16,40 @@
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Operation;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ExpressionState;
+import org.springframework.util.NumberUtils;
/**
* The minus operator supports:
* <ul>
+ * <li>subtraction of {@code BigDecimal}
* <li>subtraction of doubles (floats are represented as doubles)
* <li>subtraction of longs
* <li>subtraction of integers
* <li>subtraction of an int from a string of one character (effectively decreasing that
* character), so 'd'-3='a'
* </ul>
- * It can be used as a unary operator for numbers (double/long/int). The standard
- * promotions are performed when the operand types vary (double-int=double). For other
- * options it defers to the registered overloader.
+ * It can be used as a unary operator for numbers ({@code BigDecimal}/double/long/int).
+ * The standard promotions are performed when the operand types vary (double-int=double).
+ * For other options it defers to the registered overloader.
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public class OpMinus extends Operator {
+
public OpMinus(int pos, SpelNodeImpl... operands) {
super("-", pos, operands);
}
+
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
@@ -53,6 +60,12 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
Object operand = leftOp.getValueInternal(state).getValue();
if (operand instanceof Number) {
Number n = (Number) operand;
+
+ if (operand instanceof BigDecimal) {
+ BigDecimal bdn = (BigDecimal) n;
+ return new TypedValue(bdn.negate());
+ }
+
if (operand instanceof Double) {
return new TypedValue(0 - n.doubleValue());
}
@@ -64,6 +77,7 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
if (operand instanceof Long) {
return new TypedValue(0 - n.longValue());
}
+
return new TypedValue(0 - n.intValue());
}
@@ -74,21 +88,28 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
Object right = rightOp.getValueInternal(state).getValue();
if (left instanceof Number && right instanceof Number) {
- Number op1 = (Number) left;
- Number op2 = (Number) right;
- if (op1 instanceof Double || op2 instanceof Double) {
- return new TypedValue(op1.doubleValue() - op2.doubleValue());
+ Number leftNumber = (Number) left;
+ Number rightNumber = (Number) right;
+
+ if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) {
+ BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
+ BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
+ return new TypedValue(leftBigDecimal.subtract(rightBigDecimal));
+ }
+
+ if (leftNumber instanceof Double || rightNumber instanceof Double) {
+ return new TypedValue(leftNumber.doubleValue() - rightNumber.doubleValue());
}
- if (op1 instanceof Float || op2 instanceof Float) {
- return new TypedValue(op1.floatValue() - op2.floatValue());
+ if (leftNumber instanceof Float || rightNumber instanceof Float) {
+ return new TypedValue(leftNumber.floatValue() - rightNumber.floatValue());
}
- if (op1 instanceof Long || op2 instanceof Long) {
- return new TypedValue(op1.longValue() - op2.longValue());
+ if (leftNumber instanceof Long || rightNumber instanceof Long) {
+ return new TypedValue(leftNumber.longValue() - rightNumber.longValue());
}
- return new TypedValue(op1.intValue() - op2.intValue());
+ return new TypedValue(leftNumber.intValue() - rightNumber.intValue());
}
else if (left instanceof String && right instanceof Integer
&& ((String) left).length() == 1) { | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpModulus.java | @@ -16,45 +16,59 @@
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Operation;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ExpressionState;
+import org.springframework.util.NumberUtils;
/**
* Implements the modulus operator.
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public class OpModulus extends Operator {
+
public OpModulus(int pos, SpelNodeImpl... operands) {
super("%", pos, operands);
}
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
- Object operandOne = getLeftOperand().getValueInternal(state).getValue();
- Object operandTwo = getRightOperand().getValueInternal(state).getValue();
- if (operandOne instanceof Number && operandTwo instanceof Number) {
- Number op1 = (Number) operandOne;
- Number op2 = (Number) operandTwo;
- if (op1 instanceof Double || op2 instanceof Double) {
- return new TypedValue(op1.doubleValue() % op2.doubleValue());
+ Object leftOperand = getLeftOperand().getValueInternal(state).getValue();
+ Object rightOperand = getRightOperand().getValueInternal(state).getValue();
+ if (leftOperand instanceof Number && rightOperand instanceof Number) {
+ Number leftNumber = (Number) leftOperand;
+ Number rightNumber = (Number) rightOperand;
+
+ if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) {
+ BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
+ BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
+ return new TypedValue(leftBigDecimal.remainder(rightBigDecimal));
}
- else if (op1 instanceof Float || op2 instanceof Float) {
- return new TypedValue(op1.floatValue() % op2.floatValue());
+
+ if (leftNumber instanceof Double || rightNumber instanceof Double) {
+ return new TypedValue(leftNumber.doubleValue() % rightNumber.doubleValue());
}
- else if (op1 instanceof Long || op2 instanceof Long) {
- return new TypedValue(op1.longValue() % op2.longValue());
+
+ if (leftNumber instanceof Float || rightNumber instanceof Float) {
+ return new TypedValue(leftNumber.floatValue() % rightNumber.floatValue());
}
- else {
- return new TypedValue(op1.intValue() % op2.intValue());
+
+ if (leftNumber instanceof Long || rightNumber instanceof Long) {
+ return new TypedValue(leftNumber.longValue() % rightNumber.longValue());
}
+
+ return new TypedValue(leftNumber.intValue() % rightNumber.intValue());
}
- return state.operate(Operation.MODULUS, operandOne, operandTwo);
+
+ return state.operate(Operation.MODULUS, leftOperand, rightOperand);
}
} | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpMultiply.java | @@ -16,31 +16,37 @@
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Operation;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ExpressionState;
+import org.springframework.util.NumberUtils;
/**
* Implements the {@code multiply} operator.
*
* <p>Conversions and promotions are handled as defined in
* <a href="http://java.sun.com/docs/books/jls/third_edition/html/conversions.html">Section
- * 5.6.2 of the Java Language Specification</a>:
+ * 5.6.2 of the Java Language Specification</a>, with the addiction of {@code BigDecimal} management:
*
* <p>If any of the operands is of a reference type, unboxing conversion (Section 5.1.8)
* is performed. Then:<br>
+ * If either operand is of type {@code BigDecimal}, the other is converted to {@code BigDecimal}.<br>
* If either operand is of type double, the other is converted to double.<br>
* Otherwise, if either operand is of type float, the other is converted to float.<br>
* Otherwise, if either operand is of type long, the other is converted to long.<br>
* Otherwise, both operands are converted to type int.
*
* @author Andy Clement
* @author Sam Brannen
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public class OpMultiply extends Operator {
+
public OpMultiply(int pos, SpelNodeImpl... operands) {
super("*", pos, operands);
}
@@ -52,6 +58,7 @@ public OpMultiply(int pos, SpelNodeImpl... operands) {
* for types not supported here.
* <p>Supported operand types:
* <ul>
+ * <li>{@code BigDecimal}
* <li>doubles
* <li>longs
* <li>integers
@@ -61,15 +68,20 @@ public OpMultiply(int pos, SpelNodeImpl... operands) {
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
- Object operandOne = getLeftOperand().getValueInternal(state).getValue();
- Object operandTwo = getRightOperand().getValueInternal(state).getValue();
+ Object leftOperand = getLeftOperand().getValueInternal(state).getValue();
+ Object rightOperand = getRightOperand().getValueInternal(state).getValue();
+
+ if (leftOperand instanceof Number && rightOperand instanceof Number) {
+ Number leftNumber = (Number) leftOperand;
+ Number rightNumber = (Number) rightOperand;
+ if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) {
+ BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
+ BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
+ return new TypedValue(leftBigDecimal.multiply(rightBigDecimal));
+ }
- if (operandOne instanceof Number && operandTwo instanceof Number) {
- Number leftNumber = (Number) operandOne;
- Number rightNumber = (Number) operandTwo;
if (leftNumber instanceof Double || rightNumber instanceof Double) {
- return new TypedValue(leftNumber.doubleValue()
- * rightNumber.doubleValue());
+ return new TypedValue(leftNumber.doubleValue() * rightNumber.doubleValue());
}
if (leftNumber instanceof Float || rightNumber instanceof Float) {
@@ -82,16 +94,16 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
return new TypedValue(leftNumber.intValue() * rightNumber.intValue());
}
- else if (operandOne instanceof String && operandTwo instanceof Integer) {
- int repeats = (Integer) operandTwo;
+ else if (leftOperand instanceof String && rightOperand instanceof Integer) {
+ int repeats = (Integer) rightOperand;
StringBuilder result = new StringBuilder();
for (int i = 0; i < repeats; i++) {
- result.append(operandOne);
+ result.append(leftOperand);
}
return new TypedValue(result.toString());
}
- return state.operate(Operation.MULTIPLY, operandOne, operandTwo);
+ return state.operate(Operation.MULTIPLY, leftOperand, rightOperand);
}
} | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpPlus.java | @@ -16,32 +16,38 @@
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Operation;
import org.springframework.expression.TypeConverter;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ExpressionState;
import org.springframework.util.Assert;
+import org.springframework.util.NumberUtils;
/**
* The plus operator will:
* <ul>
+ * <li>add {@code BigDecimal}
* <li>add doubles (floats are represented as doubles)
* <li>add longs
* <li>add integers
* <li>concatenate strings
* </ul>
- * It can be used as a unary operator for numbers (double/long/int). The standard
- * promotions are performed when the operand types vary (double+int=double). For other
- * options it defers to the registered overloader.
+ * It can be used as a unary operator for numbers ({@code BigDecimal}/double/long/int).
+ * The standard promotions are performed when the operand types vary (double+int=double).
+ * For other options it defers to the registered overloader.
*
* @author Andy Clement
* @author Ivo Smid
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public class OpPlus extends Operator {
+
public OpPlus(int pos, SpelNodeImpl... operands) {
super("+", pos, operands);
Assert.notEmpty(operands);
@@ -56,7 +62,7 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
if (rightOp == null) { // If only one operand, then this is unary plus
Object operandOne = leftOp.getValueInternal(state).getValue();
if (operandOne instanceof Number) {
- if (operandOne instanceof Double || operandOne instanceof Long) {
+ if (operandOne instanceof Double || operandOne instanceof Long || operandOne instanceof BigDecimal) {
return new TypedValue(operandOne);
}
if (operandOne instanceof Float) {
@@ -68,55 +74,64 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
}
final TypedValue operandOneValue = leftOp.getValueInternal(state);
- final Object operandOne = operandOneValue.getValue();
+ final Object leftOperand = operandOneValue.getValue();
final TypedValue operandTwoValue = rightOp.getValueInternal(state);
- final Object operandTwo = operandTwoValue.getValue();
+ final Object rightOperand = operandTwoValue.getValue();
+
+ if (leftOperand instanceof Number && rightOperand instanceof Number) {
+ Number leftNumber = (Number) leftOperand;
+ Number rightNumber = (Number) rightOperand;
+
+ if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) {
+ BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
+ BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
+ return new TypedValue(leftBigDecimal.add(rightBigDecimal));
+ }
- if (operandOne instanceof Number && operandTwo instanceof Number) {
- Number op1 = (Number) operandOne;
- Number op2 = (Number) operandTwo;
- if (op1 instanceof Double || op2 instanceof Double) {
- return new TypedValue(op1.doubleValue() + op2.doubleValue());
+ if (leftNumber instanceof Double || rightNumber instanceof Double) {
+ return new TypedValue(leftNumber.doubleValue() + rightNumber.doubleValue());
}
- if (op1 instanceof Float || op2 instanceof Float) {
- return new TypedValue(op1.floatValue() + op2.floatValue());
+
+ if (leftNumber instanceof Float || rightNumber instanceof Float) {
+ return new TypedValue(leftNumber.floatValue() + rightNumber.floatValue());
}
- if (op1 instanceof Long || op2 instanceof Long) {
- return new TypedValue(op1.longValue() + op2.longValue());
+
+ if (leftNumber instanceof Long || rightNumber instanceof Long) {
+ return new TypedValue(leftNumber.longValue() + rightNumber.longValue());
}
+
// TODO what about overflow?
- return new TypedValue(op1.intValue() + op2.intValue());
+ return new TypedValue(leftNumber.intValue() + rightNumber.intValue());
}
- if (operandOne instanceof String && operandTwo instanceof String) {
- return new TypedValue(new StringBuilder((String) operandOne).append(
- (String) operandTwo).toString());
+ if (leftOperand instanceof String && rightOperand instanceof String) {
+ return new TypedValue(new StringBuilder((String) leftOperand).append(
+ (String) rightOperand).toString());
}
- if (operandOne instanceof String) {
- StringBuilder result = new StringBuilder((String) operandOne);
- result.append((operandTwo == null ? "null" : convertTypedValueToString(
+ if (leftOperand instanceof String) {
+ StringBuilder result = new StringBuilder((String) leftOperand);
+ result.append((rightOperand == null ? "null" : convertTypedValueToString(
operandTwoValue, state)));
return new TypedValue(result.toString());
}
- if (operandTwo instanceof String) {
- StringBuilder result = new StringBuilder((operandOne == null ? "null"
+ if (rightOperand instanceof String) {
+ StringBuilder result = new StringBuilder((leftOperand == null ? "null"
: convertTypedValueToString(operandOneValue, state)));
- result.append((String) operandTwo);
+ result.append((String) rightOperand);
return new TypedValue(result.toString());
}
- return state.operate(Operation.ADD, operandOne, operandTwo);
+ return state.operate(Operation.ADD, leftOperand, rightOperand);
}
@Override
public String toStringAST() {
if (this.children.length<2) { // unary plus
return new StringBuilder().append("+").append(getLeftOperand().toStringAST()).toString();
}
-
return super.toStringAST();
}
@@ -125,7 +140,6 @@ public SpelNodeImpl getRightOperand() {
if (this.children.length < 2) {
return null;
}
-
return this.children[1];
}
| true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java | @@ -16,14 +16,19 @@
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+
import org.springframework.expression.spel.ExpressionState;
+import org.springframework.util.NumberUtils;
+import org.springframework.util.ObjectUtils;
/**
* Common supertype for operators that operate on either one or two operands. In the case
* of multiply or divide there would be two operands, but for unary plus or minus, there
* is only one.
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public abstract class Operator extends SpelNodeImpl {
@@ -67,29 +72,35 @@ public String toStringAST() {
protected boolean equalityCheck(ExpressionState state, Object left, Object right) {
if (left instanceof Number && right instanceof Number) {
- Number op1 = (Number) left;
- Number op2 = (Number) right;
+ Number leftNumber = (Number) left;
+ Number rightNumber = (Number) right;
+
+ if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) {
+ BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
+ BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
+ return (leftBigDecimal == null ? rightBigDecimal == null : leftBigDecimal.compareTo(rightBigDecimal) == 0);
+ }
- if (op1 instanceof Double || op2 instanceof Double) {
- return (op1.doubleValue() == op2.doubleValue());
+ if (leftNumber instanceof Double || rightNumber instanceof Double) {
+ return (leftNumber.doubleValue() == rightNumber.doubleValue());
}
- if (op1 instanceof Float || op2 instanceof Float) {
- return (op1.floatValue() == op2.floatValue());
+ if (leftNumber instanceof Float || rightNumber instanceof Float) {
+ return (leftNumber.floatValue() == rightNumber.floatValue());
}
- if (op1 instanceof Long || op2 instanceof Long) {
- return (op1.longValue() == op2.longValue());
+ if (leftNumber instanceof Long || rightNumber instanceof Long) {
+ return (leftNumber.longValue() == rightNumber.longValue());
}
- return (op1.intValue() == op2.intValue());
+ return (leftNumber.intValue() == rightNumber.intValue());
}
if (left != null && (left instanceof Comparable)) {
return (state.getTypeComparator().compare(left, right) == 0);
}
- return (left == null ? right == null : left.equals(right));
+ return ObjectUtils.nullSafeEquals(left, right);
}
} | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorPower.java | @@ -16,15 +16,19 @@
package org.springframework.expression.spel.ast;
+import java.math.BigDecimal;
+
import org.springframework.expression.EvaluationException;
import org.springframework.expression.Operation;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ExpressionState;
+import org.springframework.util.NumberUtils;
/**
* The power operator.
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public class OperatorPower extends Operator {
@@ -39,32 +43,41 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
SpelNodeImpl leftOp = getLeftOperand();
SpelNodeImpl rightOp = getRightOperand();
- Object operandOne = leftOp.getValueInternal(state).getValue();
- Object operandTwo = rightOp.getValueInternal(state).getValue();
- if (operandOne instanceof Number && operandTwo instanceof Number) {
- Number op1 = (Number) operandOne;
- Number op2 = (Number) operandTwo;
- if (op1 instanceof Double || op2 instanceof Double) {
- return new TypedValue(Math.pow(op1.doubleValue(), op2.doubleValue()));
+ Object leftOperand = leftOp.getValueInternal(state).getValue();
+ Object rightOperand = rightOp.getValueInternal(state).getValue();
+
+ if (leftOperand instanceof Number && rightOperand instanceof Number) {
+ Number leftNumber = (Number) leftOperand;
+ Number rightNumber = (Number) rightOperand;
+
+ if (leftNumber instanceof BigDecimal) {
+ BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
+ return new TypedValue(leftBigDecimal.pow(rightNumber.intValue()));
}
- else if (op1 instanceof Float || op2 instanceof Float) {
- return new TypedValue(Math.pow(op1.floatValue(), op2.floatValue()));
+
+ if (leftNumber instanceof Double || rightNumber instanceof Double) {
+ return new TypedValue(Math.pow(leftNumber.doubleValue(), rightNumber.doubleValue()));
+ }
+
+ if (leftNumber instanceof Float || rightNumber instanceof Float) {
+ return new TypedValue(Math.pow(leftNumber.floatValue(), rightNumber.floatValue()));
}
- else if (op1 instanceof Long || op2 instanceof Long) {
- double d = Math.pow(op1.longValue(), op2.longValue());
+
+ if (leftNumber instanceof Long || rightNumber instanceof Long) {
+ double d = Math.pow(leftNumber.longValue(), rightNumber.longValue());
+ return new TypedValue((long) d);
+ }
+
+ double d = Math.pow(leftNumber.longValue(), rightNumber.longValue());
+ if (d > Integer.MAX_VALUE) {
return new TypedValue((long) d);
}
else {
- double d = Math.pow(op1.longValue(), op2.longValue());
- if (d > Integer.MAX_VALUE) {
- return new TypedValue((long) d);
- }
- else {
- return new TypedValue((int) d);
- }
+ return new TypedValue((int) d);
}
}
- return state.operate(Operation.POWER, operandOne, operandTwo);
+
+ return state.operate(Operation.POWER, leftOperand, rightOperand);
}
} | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java | @@ -16,16 +16,20 @@
package org.springframework.expression.spel.support;
+import java.math.BigDecimal;
+
import org.springframework.expression.TypeComparator;
import org.springframework.expression.spel.SpelEvaluationException;
import org.springframework.expression.spel.SpelMessage;
+import org.springframework.util.NumberUtils;
/**
* A simple basic TypeComparator implementation. It supports comparison of numbers and
* types implementing Comparable.
*
* @author Andy Clement
* @author Juergen Hoeller
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public class StandardTypeComparator implements TypeComparator {
@@ -45,27 +49,26 @@ else if (right == null) {
if (left instanceof Number && right instanceof Number) {
Number leftNumber = (Number) left;
Number rightNumber = (Number) right;
+
+ if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) {
+ BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class);
+ BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class);
+ return leftBigDecimal.compareTo(rightBigDecimal);
+ }
+
if (leftNumber instanceof Double || rightNumber instanceof Double) {
- double d1 = leftNumber.doubleValue();
- double d2 = rightNumber.doubleValue();
- return Double.compare(d1, d2);
+ return Double.compare(leftNumber.doubleValue(), rightNumber.doubleValue());
}
if (leftNumber instanceof Float || rightNumber instanceof Float) {
- float f1 = leftNumber.floatValue();
- float f2 = rightNumber.floatValue();
- return Float.compare(f1, f2);
+ return Float.compare(leftNumber.floatValue(), rightNumber.floatValue());
}
if (leftNumber instanceof Long || rightNumber instanceof Long) {
- Long l1 = leftNumber.longValue();
- Long l2 = rightNumber.longValue();
- return l1.compareTo(l2);
+ return Long.compare(leftNumber.longValue(), rightNumber.longValue());
}
- Integer i1 = leftNumber.intValue();
- Integer i2 = rightNumber.intValue();
- return i1.compareTo(i2);
+ return Integer.compare(leftNumber.intValue(), rightNumber.intValue());
}
try { | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/test/java/org/springframework/expression/spel/DefaultComparatorUnitTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.math.BigDecimal;
+
import org.junit.Test;
import org.springframework.expression.EvaluationException;
import org.springframework.expression.TypeComparator;
@@ -27,6 +29,7 @@
* Unit tests for type comparison
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
*/
public class DefaultComparatorUnitTests {
@@ -59,6 +62,35 @@ public void testPrimitives() throws EvaluationException {
assertTrue(comparator.compare(2L, 1L) > 0);
}
+ @Test
+ public void testNonPrimitiveNumbers() throws EvaluationException {
+ TypeComparator comparator = new StandardTypeComparator();
+
+ BigDecimal bdOne = new BigDecimal("1");
+ BigDecimal bdTwo = new BigDecimal("2");
+
+ assertTrue(comparator.compare(bdOne, bdTwo) < 0);
+ assertTrue(comparator.compare(bdOne, new BigDecimal("1")) == 0);
+ assertTrue(comparator.compare(bdTwo, bdOne) > 0);
+
+ assertTrue(comparator.compare(1, bdTwo) < 0);
+ assertTrue(comparator.compare(1, bdOne) == 0);
+ assertTrue(comparator.compare(2, bdOne) > 0);
+
+ assertTrue(comparator.compare(1.0d, bdTwo) < 0);
+ assertTrue(comparator.compare(1.0d, bdOne) == 0);
+ assertTrue(comparator.compare(2.0d, bdOne) > 0);
+
+ assertTrue(comparator.compare(1.0f, bdTwo) < 0);
+ assertTrue(comparator.compare(1.0f, bdOne) == 0);
+ assertTrue(comparator.compare(2.0f, bdOne) > 0);
+
+ assertTrue(comparator.compare(1L, bdTwo) < 0);
+ assertTrue(comparator.compare(1L, bdOne) == 0);
+ assertTrue(comparator.compare(2L, bdOne) > 0);
+
+ }
+
@Test
public void testNulls() throws EvaluationException {
TypeComparator comparator = new StandardTypeComparator(); | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java | @@ -26,6 +26,7 @@
import static org.junit.Assert.fail;
import java.lang.reflect.Method;
+import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -55,6 +56,7 @@
* @author Mark Fisher
* @author Sam Brannen
* @author Phillip Webb
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0
*/
public class EvaluationTests extends ExpressionTestCase {
@@ -636,6 +638,7 @@ public List<Method> filter(List<Method> methods) {
static class Spr9751 {
public String type = "hello";
+ public BigDecimal bd = new BigDecimal("2");
public double ddd = 2.0d;
public float fff = 3.0f;
public long lll = 66666L;
@@ -755,6 +758,13 @@ public void increment02postfix() {
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
Expression e = null;
+ // BigDecimal
+ e = parser.parseExpression("bd++");
+ assertTrue(new BigDecimal("2").equals(helper.bd));
+ BigDecimal return_bd = e.getValue(ctx,BigDecimal.class);
+ assertTrue(new BigDecimal("2").equals(return_bd));
+ assertTrue(new BigDecimal("3").equals(helper.bd));
+
// double
e = parser.parseExpression("ddd++");
assertEquals(2.0d,helper.ddd,0d);
@@ -801,6 +811,14 @@ public void increment02prefix() {
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
Expression e = null;
+
+ // BigDecimal
+ e = parser.parseExpression("++bd");
+ assertTrue(new BigDecimal("2").equals(helper.bd));
+ BigDecimal return_bd = e.getValue(ctx,BigDecimal.class);
+ assertTrue(new BigDecimal("3").equals(return_bd));
+ assertTrue(new BigDecimal("3").equals(helper.bd));
+
// double
e = parser.parseExpression("++ddd");
assertEquals(2.0d,helper.ddd,0d);
@@ -907,6 +925,13 @@ public void decrement02postfix() {
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
Expression e = null;
+ // BigDecimal
+ e = parser.parseExpression("bd--");
+ assertTrue(new BigDecimal("2").equals(helper.bd));
+ BigDecimal return_bd = e.getValue(ctx,BigDecimal.class);
+ assertTrue(new BigDecimal("2").equals(return_bd));
+ assertTrue(new BigDecimal("1").equals(helper.bd));
+
// double
e = parser.parseExpression("ddd--");
assertEquals(2.0d,helper.ddd,0d);
@@ -953,6 +978,13 @@ public void decrement02prefix() {
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
Expression e = null;
+ // BigDecimal
+ e = parser.parseExpression("--bd");
+ assertTrue(new BigDecimal("2").equals(helper.bd));
+ BigDecimal return_bd = e.getValue(ctx,BigDecimal.class);
+ assertTrue(new BigDecimal("1").equals(return_bd));
+ assertTrue(new BigDecimal("1").equals(helper.bd));
+
// double
e = parser.parseExpression("--ddd");
assertEquals(2.0d,helper.ddd,0d); | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/test/java/org/springframework/expression/spel/ListTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
* Test usage of inline lists.
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
* @since 3.0.4
*/
public class ListTests extends ExpressionTestCase {
@@ -108,6 +109,14 @@ public void testRelOperatorsBetween03() {
evaluate("42 between {32, 42}", "true", Boolean.class);
}
+ @Test
+ public void testRelOperatorsBetween04() {
+ evaluate("new java.math.BigDecimal('1') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}", "true", Boolean.class);
+ evaluate("new java.math.BigDecimal('3') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}", "true", Boolean.class);
+ evaluate("new java.math.BigDecimal('5') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}", "true", Boolean.class);
+ evaluate("new java.math.BigDecimal('8') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}", "false", Boolean.class);
+ }
+
@Test
public void testRelOperatorsBetweenErrors02() {
evaluateAndCheckError("'abc' between {5,7}", SpelMessage.NOT_COMPARABLE, 6); | true |
Other | spring-projects | spring-framework | d0ab131a57b2dc0cec6b379d439ceff912d5c3d1.json | Add BigDecimal support for SpEl numeric operations
Prior to this change, SpEL supported numeric operations for int, float,
ect. `new java.math.BigDecimal('0.1') > 0` evaluated to false
(BigDecimal is truncated to int)
This commit introduces support for BigDecimal operations for all
mathematical operators. `new java.math.BigDecimal('0.1') > 0` now
evaluates to true (the comparison is made with BigDecimals)
Issue: SPR-9164 | spring-expression/src/test/java/org/springframework/expression/spel/OperatorTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.springframework.expression.spel;
import static org.junit.Assert.assertEquals;
+import java.math.BigDecimal;
import org.junit.Test;
import org.springframework.expression.spel.ast.Operator;
@@ -26,6 +27,7 @@
* Tests the evaluation of expressions using relational operators.
*
* @author Andy Clement
+ * @author Giovanni Dall'Oglio Risso
*/
public class OperatorTests extends ExpressionTestCase {
@@ -41,6 +43,8 @@ public void testRealLiteral() {
@Test
public void testLessThan() {
+
+ evaluate("5 < 5", false, Boolean.class);
evaluate("3 < 5", true, Boolean.class);
evaluate("5 < 3", false, Boolean.class);
evaluate("3L < 5L", true, Boolean.class);
@@ -49,6 +53,15 @@ public void testLessThan() {
evaluate("5.0d < 3.0d", false, Boolean.class);
evaluate("'abc' < 'def'",true,Boolean.class);
evaluate("'def' < 'abc'",false,Boolean.class);
+ evaluate("new java.math.BigDecimal('3') < new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') < new java.math.BigDecimal('3')", false, Boolean.class);
+ evaluate("3 < new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') < 5", true, Boolean.class);
+ evaluate("3L < new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("3.0d < new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("3L < new java.math.BigDecimal('3.1')", true, Boolean.class);
+ evaluate("3.0d < new java.math.BigDecimal('3.1')", true, Boolean.class);
+ evaluate("3.0d < new java.math.BigDecimal('3.0')", false, Boolean.class);
evaluate("3 lt 5", true, Boolean.class);
evaluate("5 lt 3", false, Boolean.class);
@@ -58,6 +71,15 @@ public void testLessThan() {
evaluate("5.0d Lt 3.0d", false, Boolean.class);
evaluate("'abc' LT 'def'",true,Boolean.class);
evaluate("'def' lt 'abc'",false,Boolean.class);
+ evaluate("new java.math.BigDecimal('3') lt new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') lt new java.math.BigDecimal('3')", false, Boolean.class);
+ evaluate("3 lt new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') lt 5", true, Boolean.class);
+ evaluate("3L lt new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("3.0d lt new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("3L lt new java.math.BigDecimal('3.1')", true, Boolean.class);
+ evaluate("3.0d lt new java.math.BigDecimal('3.1')", true, Boolean.class);
+ evaluate("3.0d lt new java.math.BigDecimal('3.0')", false, Boolean.class);
}
@Test
@@ -74,6 +96,16 @@ public void testLessThanOrEqual() {
evaluate("'abc' <= 'def'",true,Boolean.class);
evaluate("'def' <= 'abc'",false,Boolean.class);
evaluate("'abc' <= 'abc'",true,Boolean.class);
+ evaluate("new java.math.BigDecimal('5') <= new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') <= new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') <= new java.math.BigDecimal('3')", false, Boolean.class);
+ evaluate("3 <= new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') <= 5", true, Boolean.class);
+ evaluate("3L <= new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("3.0d <= new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("3L <= new java.math.BigDecimal('3.1')", true, Boolean.class);
+ evaluate("3.0d <= new java.math.BigDecimal('3.1')", true, Boolean.class);
+ evaluate("3.0d <= new java.math.BigDecimal('3.0')", true, Boolean.class);
evaluate("3 le 5", true, Boolean.class);
evaluate("5 le 3", false, Boolean.class);
@@ -87,6 +119,16 @@ public void testLessThanOrEqual() {
evaluate("'abc' Le 'def'",true,Boolean.class);
evaluate("'def' LE 'abc'",false,Boolean.class);
evaluate("'abc' le 'abc'",true,Boolean.class);
+ evaluate("new java.math.BigDecimal('5') le new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') le new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') le new java.math.BigDecimal('3')", false, Boolean.class);
+ evaluate("3 le new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') le 5", true, Boolean.class);
+ evaluate("3L le new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("3.0d le new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("3L le new java.math.BigDecimal('3.1')", true, Boolean.class);
+ evaluate("3.0d le new java.math.BigDecimal('3.1')", true, Boolean.class);
+ evaluate("3.0d le new java.math.BigDecimal('3.0')", true, Boolean.class);
}
@Test
@@ -97,13 +139,33 @@ public void testEqual() {
evaluate("3.0f == 5.0f", false, Boolean.class);
evaluate("3.0f == 3.0f", true, Boolean.class);
evaluate("'abc' == null", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') == new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') == new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') == new java.math.BigDecimal('3')", false, Boolean.class);
+ evaluate("3 == new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') == 5", false, Boolean.class);
+ evaluate("3L == new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("3.0d == new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("3L == new java.math.BigDecimal('3.1')", false, Boolean.class);
+ evaluate("3.0d == new java.math.BigDecimal('3.1')", false, Boolean.class);
+ evaluate("3.0d == new java.math.BigDecimal('3.0')", true, Boolean.class);
evaluate("3 eq 5", false, Boolean.class);
evaluate("5 eQ 3", false, Boolean.class);
evaluate("6 Eq 6", true, Boolean.class);
evaluate("3.0f eq 5.0f", false, Boolean.class);
evaluate("3.0f EQ 3.0f", true, Boolean.class);
evaluate("'abc' EQ null", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') eq new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') eq new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') eq new java.math.BigDecimal('3')", false, Boolean.class);
+ evaluate("3 eq new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') eq 5", false, Boolean.class);
+ evaluate("3L eq new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("3.0d eq new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("3L eq new java.math.BigDecimal('3.1')", false, Boolean.class);
+ evaluate("3.0d eq new java.math.BigDecimal('3.1')", false, Boolean.class);
+ evaluate("3.0d eq new java.math.BigDecimal('3.0')", true, Boolean.class);
}
@Test
@@ -113,12 +175,32 @@ public void testNotEqual() {
evaluate("6 != 6", false, Boolean.class);
evaluate("3.0f != 5.0f", true, Boolean.class);
evaluate("3.0f != 3.0f", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') != new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') != new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') != new java.math.BigDecimal('3')", true, Boolean.class);
+ evaluate("3 != new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') != 5", true, Boolean.class);
+ evaluate("3L != new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("3.0d != new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("3L != new java.math.BigDecimal('3.1')", true, Boolean.class);
+ evaluate("3.0d != new java.math.BigDecimal('3.1')", true, Boolean.class);
+ evaluate("3.0d != new java.math.BigDecimal('3.0')", false, Boolean.class);
evaluate("3 ne 5", true, Boolean.class);
evaluate("5 nE 3", true, Boolean.class);
evaluate("6 Ne 6", false, Boolean.class);
evaluate("3.0f NE 5.0f", true, Boolean.class);
evaluate("3.0f ne 3.0f", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') ne new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') ne new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') ne new java.math.BigDecimal('3')", true, Boolean.class);
+ evaluate("3 ne new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') ne 5", true, Boolean.class);
+ evaluate("3L ne new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("3.0d ne new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("3L ne new java.math.BigDecimal('3.1')", true, Boolean.class);
+ evaluate("3.0d ne new java.math.BigDecimal('3.1')", true, Boolean.class);
+ evaluate("3.0d ne new java.math.BigDecimal('3.0')", false, Boolean.class);
}
@Test
@@ -135,11 +217,31 @@ public void testGreaterThanOrEqual() {
evaluate("'abc' >= 'def'",false,Boolean.class);
evaluate("'def' >= 'abc'",true,Boolean.class);
evaluate("'abc' >= 'abc'",true,Boolean.class);
+ evaluate("new java.math.BigDecimal('5') >= new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') >= new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') >= new java.math.BigDecimal('3')", true, Boolean.class);
+ evaluate("3 >= new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') >= 5", false, Boolean.class);
+ evaluate("3L >= new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("3.0d >= new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("3L >= new java.math.BigDecimal('3.1')", false, Boolean.class);
+ evaluate("3.0d >= new java.math.BigDecimal('3.1')", false, Boolean.class);
+ evaluate("3.0d >= new java.math.BigDecimal('3.0')", true, Boolean.class);
evaluate("3 GE 5", false, Boolean.class);
evaluate("5 gE 3", true, Boolean.class);
evaluate("6 Ge 6", true, Boolean.class);
evaluate("3L ge 5L", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') ge new java.math.BigDecimal('5')", true, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') ge new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') ge new java.math.BigDecimal('3')", true, Boolean.class);
+ evaluate("3 ge new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') ge 5", false, Boolean.class);
+ evaluate("3L ge new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("3.0d ge new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("3L ge new java.math.BigDecimal('3.1')", false, Boolean.class);
+ evaluate("3.0d ge new java.math.BigDecimal('3.1')", false, Boolean.class);
+ evaluate("3.0d ge new java.math.BigDecimal('3.0')", true, Boolean.class);
}
@Test
@@ -152,11 +254,29 @@ public void testGreaterThan() {
evaluate("5.0d > 3.0d", true, Boolean.class);
evaluate("'abc' > 'def'",false,Boolean.class);
evaluate("'def' > 'abc'",true,Boolean.class);
+ evaluate("new java.math.BigDecimal('3') > new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') > new java.math.BigDecimal('3')", true, Boolean.class);
+ evaluate("3 > new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') > 5", false, Boolean.class);
+ evaluate("3L > new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("3.0d > new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("3L > new java.math.BigDecimal('3.1')", false, Boolean.class);
+ evaluate("3.0d > new java.math.BigDecimal('3.1')", false, Boolean.class);
+ evaluate("3.0d > new java.math.BigDecimal('3.0')", false, Boolean.class);
evaluate("3.0d gt 5.0d", false, Boolean.class);
evaluate("5.0d gT 3.0d", true, Boolean.class);
evaluate("'abc' Gt 'def'",false,Boolean.class);
evaluate("'def' GT 'abc'",true,Boolean.class);
+ evaluate("new java.math.BigDecimal('3') gt new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('5') gt new java.math.BigDecimal('3')", true, Boolean.class);
+ evaluate("3 gt new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("new java.math.BigDecimal('3') gt 5", false, Boolean.class);
+ evaluate("3L gt new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("3.0d gt new java.math.BigDecimal('5')", false, Boolean.class);
+ evaluate("3L gt new java.math.BigDecimal('3.1')", false, Boolean.class);
+ evaluate("3.0d gt new java.math.BigDecimal('3.1')", false, Boolean.class);
+ evaluate("3.0d gt new java.math.BigDecimal('3.0')", false, Boolean.class);
}
@Test
@@ -169,6 +289,32 @@ public void testMultiplyDoubleDoubleGivesDouble() {
evaluate("3.0d * 5.0d", 15.0d, Double.class);
}
+ @Test
+ public void testMixedOperandsBigDecimal() {
+ evaluate("3 * new java.math.BigDecimal('5')", new BigDecimal("15"), BigDecimal.class);
+ evaluate("3L * new java.math.BigDecimal('5')", new BigDecimal("15"), BigDecimal.class);
+ evaluate("3.0d * new java.math.BigDecimal('5')", new BigDecimal("15.0"), BigDecimal.class);
+
+ evaluate("3 + new java.math.BigDecimal('5')", new BigDecimal("8"), BigDecimal.class);
+ evaluate("3L + new java.math.BigDecimal('5')", new BigDecimal("8"), BigDecimal.class);
+ evaluate("3.0d + new java.math.BigDecimal('5')", new BigDecimal("8.0"), BigDecimal.class);
+
+ evaluate("3 - new java.math.BigDecimal('5')", new BigDecimal("-2"), BigDecimal.class);
+ evaluate("3L - new java.math.BigDecimal('5')", new BigDecimal("-2"), BigDecimal.class);
+ evaluate("3.0d - new java.math.BigDecimal('5')", new BigDecimal("-2.0"), BigDecimal.class);
+
+ evaluate("3 / new java.math.BigDecimal('5')", new BigDecimal("1"), BigDecimal.class);
+ evaluate("3 / new java.math.BigDecimal('5.0')", new BigDecimal("0.6"), BigDecimal.class);
+ evaluate("3 / new java.math.BigDecimal('5.00')", new BigDecimal("0.60"), BigDecimal.class);
+ evaluate("3L / new java.math.BigDecimal('5.0')", new BigDecimal("0.6"), BigDecimal.class);
+ evaluate("3.0d / new java.math.BigDecimal('5.0')", new BigDecimal("0.6"), BigDecimal.class);
+
+ evaluate("5 % new java.math.BigDecimal('3')", new BigDecimal("2"), BigDecimal.class);
+ evaluate("3 % new java.math.BigDecimal('5')", new BigDecimal("3"), BigDecimal.class);
+ evaluate("3L % new java.math.BigDecimal('5')", new BigDecimal("3"), BigDecimal.class);
+ evaluate("3.0d % new java.math.BigDecimal('5')", new BigDecimal("3.0"), BigDecimal.class);
+ }
+
@Test
public void testMathOperatorAdd02() {
evaluate("'hello' + ' ' + 'world'", "hello world", String.class);
@@ -201,6 +347,7 @@ public void testPlus() throws Exception {
evaluate("7 + 2", "9", Integer.class);
evaluate("3.0f + 5.0f", 8.0f, Float.class);
evaluate("3.0d + 5.0d", 8.0d, Double.class);
+ evaluate("3 + new java.math.BigDecimal('5')", new BigDecimal("8"), BigDecimal.class);
evaluate("'ab' + 2", "ab2", String.class);
evaluate("2 + 'a'", "2a", String.class);
@@ -217,6 +364,7 @@ public void testPlus() throws Exception {
evaluate("+5d",5d,Double.class);
evaluate("+5L",5L,Long.class);
evaluate("+5",5,Integer.class);
+ evaluate("+new java.math.BigDecimal('5')", new BigDecimal("5"),BigDecimal.class);
evaluateAndCheckError("+'abc'",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
// string concatenation
@@ -240,6 +388,7 @@ public void testMinus() throws Exception {
evaluate("-5d",-5d,Double.class);
evaluate("-5L",-5L,Long.class);
evaluate("-5",-5,Integer.class);
+ evaluate("-new java.math.BigDecimal('5')", new BigDecimal("-5"),BigDecimal.class);
evaluateAndCheckError("-'abc'",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
}
@@ -249,6 +398,8 @@ public void testModulus() {
evaluate("3L%2L",1L,Long.class);
evaluate("3.0f%2.0f",1f,Float.class);
evaluate("5.0d % 3.1d", 1.9d, Double.class);
+ evaluate("new java.math.BigDecimal('5') % new java.math.BigDecimal('3')", new BigDecimal("2"), BigDecimal.class);
+ evaluate("new java.math.BigDecimal('5') % 3", new BigDecimal("2"), BigDecimal.class);
evaluateAndCheckError("'abc'%'def'",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
}
@@ -258,6 +409,10 @@ public void testDivide() {
evaluate("4L/2L",2L,Long.class);
evaluate("3.0f div 5.0f", 0.6f, Float.class);
evaluate("4L DIV 2L",2L,Long.class);
+ evaluate("new java.math.BigDecimal('3') / 5", new BigDecimal("1"), BigDecimal.class);
+ evaluate("new java.math.BigDecimal('3.0') / 5", new BigDecimal("0.6"), BigDecimal.class);
+ evaluate("new java.math.BigDecimal('3.00') / 5", new BigDecimal("0.60"), BigDecimal.class);
+ evaluate("new java.math.BigDecimal('3.00') / new java.math.BigDecimal('5.0000')", new BigDecimal("0.6000"), BigDecimal.class);
evaluateAndCheckError("'abc'/'def'",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
}
@@ -284,6 +439,18 @@ public void testDoubles() {
evaluate("6.0d % 3.5d", 2.5d, Double.class);
}
+
+ @Test
+ public void testBigDecimals() {
+ evaluate("3 + new java.math.BigDecimal('5')", new BigDecimal("8"), BigDecimal.class);
+ evaluate("3 - new java.math.BigDecimal('5')", new BigDecimal("-2"), BigDecimal.class);
+ evaluate("3 * new java.math.BigDecimal('5')", new BigDecimal("15"), BigDecimal.class);
+ evaluate("3 / new java.math.BigDecimal('5')", new BigDecimal("1"), BigDecimal.class);
+ evaluate("5 % new java.math.BigDecimal('3')", new BigDecimal("2"), BigDecimal.class);
+ evaluate("new java.math.BigDecimal('5') % 3", new BigDecimal("2"), BigDecimal.class);
+ evaluate("new java.math.BigDecimal('5') ^ 3", new BigDecimal("125"), BigDecimal.class);
+ }
+
@Test
public void testOperatorNames() throws Exception {
Operator node = getOperatorNode((SpelExpression)parser.parseExpression("1==3"));
@@ -335,6 +502,7 @@ public void testPower() {
evaluate("3.0d^2.0d",9.0d,Double.class);
evaluate("3L^2L",9L,Long.class);
evaluate("(2^32)^2",9223372036854775807L,Long.class);
+ evaluate("new java.math.BigDecimal('5') ^ 3", new BigDecimal("125"), BigDecimal.class);
}
@Test | true |
Other | spring-projects | spring-framework | 2a05e6afa116ab56378521b5e8c834ba92c25b85.json | Change SpEL equality operators to use .equals
Prior to this commit the SpEL operators `==` and `!=` were using the
Java `==` comparison operator as part of their equality checking. It is
more flexible to use the equals() method on Object.
Under this commit the change to .equals() has been made and the equality
checking code has been pushed into a common method in the Operator
superclass. This commit also makes some tweaks to the other operator
classes - the Float case was missing from OpGT.
Issue: SPR-9194 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpEQ.java | @@ -28,6 +28,7 @@
*/
public class OpEQ extends Operator {
+
public OpEQ(int pos, SpelNodeImpl... operands) {
super("==", pos, operands);
}
@@ -38,29 +39,7 @@ public BooleanTypedValue getValueInternal(ExpressionState state)
throws EvaluationException {
Object left = getLeftOperand().getValueInternal(state).getValue();
Object right = getRightOperand().getValueInternal(state).getValue();
- if (left instanceof Number && right instanceof Number) {
- Number op1 = (Number) left;
- Number op2 = (Number) right;
- if (op1 instanceof Double || op2 instanceof Double) {
- return BooleanTypedValue.forValue(op1.doubleValue() == op2.doubleValue());
- }
- else if (op1 instanceof Float || op2 instanceof Float) {
- return BooleanTypedValue.forValue(op1.floatValue() == op2.floatValue());
- }
- else if (op1 instanceof Long || op2 instanceof Long) {
- return BooleanTypedValue.forValue(op1.longValue() == op2.longValue());
- }
- else {
- return BooleanTypedValue.forValue(op1.intValue() == op2.intValue());
- }
- }
- if (left != null && (left instanceof Comparable)) {
- return BooleanTypedValue.forValue(state.getTypeComparator().compare(left,
- right) == 0);
- }
- else {
- return BooleanTypedValue.forValue(left == right);
- }
+ return BooleanTypedValue.forValue(equalityCheck(state, left, right));
}
} | true |
Other | spring-projects | spring-framework | 2a05e6afa116ab56378521b5e8c834ba92c25b85.json | Change SpEL equality operators to use .equals
Prior to this commit the SpEL operators `==` and `!=` were using the
Java `==` comparison operator as part of their equality checking. It is
more flexible to use the equals() method on Object.
Under this commit the change to .equals() has been made and the equality
checking code has been pushed into a common method in the Operator
superclass. This commit also makes some tweaks to the other operator
classes - the Float case was missing from OpGT.
Issue: SPR-9194 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpGT.java | @@ -28,6 +28,7 @@
*/
public class OpGT extends Operator {
+
public OpGT(int pos, SpelNodeImpl... operands) {
super(">", pos, operands);
}
@@ -43,6 +44,9 @@ public BooleanTypedValue getValueInternal(ExpressionState state) throws Evaluati
if (leftNumber instanceof Double || rightNumber instanceof Double) {
return BooleanTypedValue.forValue(leftNumber.doubleValue() > rightNumber.doubleValue());
}
+ else if (leftNumber instanceof Float || rightNumber instanceof Float) {
+ return BooleanTypedValue.forValue(leftNumber.floatValue() > rightNumber.floatValue());
+ }
else if (leftNumber instanceof Long || rightNumber instanceof Long) {
return BooleanTypedValue.forValue(leftNumber.longValue() > rightNumber.longValue());
} | true |
Other | spring-projects | spring-framework | 2a05e6afa116ab56378521b5e8c834ba92c25b85.json | Change SpEL equality operators to use .equals
Prior to this commit the SpEL operators `==` and `!=` were using the
Java `==` comparison operator as part of their equality checking. It is
more flexible to use the equals() method on Object.
Under this commit the change to .equals() has been made and the equality
checking code has been pushed into a common method in the Operator
superclass. This commit also makes some tweaks to the other operator
classes - the Float case was missing from OpGT.
Issue: SPR-9194 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpLT.java | @@ -28,6 +28,7 @@
*/
public class OpLT extends Operator {
+
public OpLT(int pos, SpelNodeImpl... operands) {
super("<", pos, operands);
}
@@ -38,7 +39,7 @@ public BooleanTypedValue getValueInternal(ExpressionState state)
throws EvaluationException {
Object left = getLeftOperand().getValueInternal(state).getValue();
Object right = getRightOperand().getValueInternal(state).getValue();
- // TODO could leave all of these to the comparator - just seems quicker to do some here
+
if (left instanceof Number && right instanceof Number) {
Number leftNumber = (Number) left;
Number rightNumber = (Number) right; | true |
Other | spring-projects | spring-framework | 2a05e6afa116ab56378521b5e8c834ba92c25b85.json | Change SpEL equality operators to use .equals
Prior to this commit the SpEL operators `==` and `!=` were using the
Java `==` comparison operator as part of their equality checking. It is
more flexible to use the equals() method on Object.
Under this commit the change to .equals() has been made and the equality
checking code has been pushed into a common method in the Operator
superclass. This commit also makes some tweaks to the other operator
classes - the Float case was missing from OpGT.
Issue: SPR-9194 | spring-expression/src/main/java/org/springframework/expression/spel/ast/OpNE.java | @@ -28,42 +28,17 @@
*/
public class OpNE extends Operator {
+
public OpNE(int pos, SpelNodeImpl... operands) {
super("!=", pos, operands);
}
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
-
Object left = getLeftOperand().getValueInternal(state).getValue();
Object right = getRightOperand().getValueInternal(state).getValue();
-
- if (left instanceof Number && right instanceof Number) {
- Number op1 = (Number) left;
- Number op2 = (Number) right;
-
- if (op1 instanceof Double || op2 instanceof Double) {
- return BooleanTypedValue.forValue(op1.doubleValue() != op2.doubleValue());
- }
-
- if (op1 instanceof Float || op2 instanceof Float) {
- return BooleanTypedValue.forValue(op1.floatValue() != op2.floatValue());
- }
-
- if (op1 instanceof Long || op2 instanceof Long) {
- return BooleanTypedValue.forValue(op1.longValue() != op2.longValue());
- }
-
- return BooleanTypedValue.forValue(op1.intValue() != op2.intValue());
- }
-
- if (left != null && (left instanceof Comparable)) {
- return BooleanTypedValue.forValue(state.getTypeComparator().compare(left,
- right) != 0);
- }
-
- return BooleanTypedValue.forValue(left != right);
+ return BooleanTypedValue.forValue(!equalityCheck(state, left, right));
}
} | true |
Other | spring-projects | spring-framework | 2a05e6afa116ab56378521b5e8c834ba92c25b85.json | Change SpEL equality operators to use .equals
Prior to this commit the SpEL operators `==` and `!=` were using the
Java `==` comparison operator as part of their equality checking. It is
more flexible to use the equals() method on Object.
Under this commit the change to .equals() has been made and the equality
checking code has been pushed into a common method in the Operator
superclass. This commit also makes some tweaks to the other operator
classes - the Float case was missing from OpGT.
Issue: SPR-9194 | spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java | @@ -16,6 +16,8 @@
package org.springframework.expression.spel.ast;
+import org.springframework.expression.spel.ExpressionState;
+
/**
* Common supertype for operators that operate on either one or two operands. In the case
* of multiply or divide there would be two operands, but for unary plus or minus, there
@@ -26,7 +28,7 @@
*/
public abstract class Operator extends SpelNodeImpl {
- String operatorName;
+ private final String operatorName;
public Operator(String payload,int pos,SpelNodeImpl... operands) {
@@ -63,4 +65,31 @@ public String toStringAST() {
return sb.toString();
}
+ protected boolean equalityCheck(ExpressionState state, Object left, Object right) {
+ if (left instanceof Number && right instanceof Number) {
+ Number op1 = (Number) left;
+ Number op2 = (Number) right;
+
+ if (op1 instanceof Double || op2 instanceof Double) {
+ return (op1.doubleValue() == op2.doubleValue());
+ }
+
+ if (op1 instanceof Float || op2 instanceof Float) {
+ return (op1.floatValue() == op2.floatValue());
+ }
+
+ if (op1 instanceof Long || op2 instanceof Long) {
+ return (op1.longValue() == op2.longValue());
+ }
+
+ return (op1.intValue() == op2.intValue());
+ }
+
+ if (left != null && (left instanceof Comparable)) {
+ return (state.getTypeComparator().compare(left, right) == 0);
+ }
+
+ return (left == null ? right == null : left.equals(right));
+ }
+
} | true |
Other | spring-projects | spring-framework | 2a05e6afa116ab56378521b5e8c834ba92c25b85.json | Change SpEL equality operators to use .equals
Prior to this commit the SpEL operators `==` and `!=` were using the
Java `==` comparison operator as part of their equality checking. It is
more flexible to use the equals() method on Object.
Under this commit the change to .equals() has been made and the equality
checking code has been pushed into a common method in the Operator
superclass. This commit also makes some tweaks to the other operator
classes - the Float case was missing from OpGT.
Issue: SPR-9194 | spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java | @@ -1839,6 +1839,19 @@ public void SPR_10486() throws Exception {
equalTo((Object) "name"));
}
+ @Test
+ public void testOperatorEq_SPR9194() {
+ TestClass2 one = new TestClass2("abc");
+ TestClass2 two = new TestClass2("abc");
+ Map<String,TestClass2> map = new HashMap<String,TestClass2>();
+ map.put("one",one);
+ map.put("two",two);
+
+ SpelExpressionParser parser = new SpelExpressionParser();
+ Expression classNameExpression = parser.parseExpression("['one'] == ['two']");
+ assertTrue(classNameExpression.getValue(map,Boolean.class));
+ }
+
private static enum ABC {A, B, C}
@@ -1922,4 +1935,20 @@ public void setName(String name) {
}
}
+
+ static class TestClass2 { // SPR-9194
+ String string;
+
+ public TestClass2(String string) {
+ this.string = string;
+ }
+
+ public boolean equals(Object o) {
+ if (o instanceof TestClass2) {
+ return string.equals(((TestClass2)o).string);
+ }
+ return false;
+ }
+
+ }
} | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.