INT-3182 Fix JMX Operation Invoking With Primitive
Previously, methods with primitive parameters were not matched with primitive wrapper objects. Check, if the argument is a primitive wrapper, that the paramer type can be the equivalent primitive. Add test case. INT-3182 Polishing - PR Comments Extract PrimitiveWrapper->Primitive map to ClassUtils. JIRA: https://jira.springsource.org/browse/INT-3182
This commit is contained in:
committed by
Artem Bilan
parent
eaa28a9dbf
commit
435064453f
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.integration.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -24,6 +26,24 @@ import java.util.Set;
|
||||
*/
|
||||
public abstract class ClassUtils {
|
||||
|
||||
/**
|
||||
* Map with primitive wrapper type as key and corresponding primitive
|
||||
* type as value, for example: Integer.class -> int.class.
|
||||
*/
|
||||
private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new HashMap<Class<?>, Class<?>>(8);
|
||||
|
||||
|
||||
static {
|
||||
primitiveWrapperTypeMap.put(Boolean.class, boolean.class);
|
||||
primitiveWrapperTypeMap.put(Byte.class, byte.class);
|
||||
primitiveWrapperTypeMap.put(Character.class, char.class);
|
||||
primitiveWrapperTypeMap.put(Double.class, double.class);
|
||||
primitiveWrapperTypeMap.put(Float.class, float.class);
|
||||
primitiveWrapperTypeMap.put(Integer.class, int.class);
|
||||
primitiveWrapperTypeMap.put(Long.class, long.class);
|
||||
primitiveWrapperTypeMap.put(Short.class, short.class);
|
||||
}
|
||||
|
||||
public static Class<?> findClosestMatch(Class<?> type, Set<Class<?>> candidates, boolean failOnTie) {
|
||||
int minTypeDiffWeight = Integer.MAX_VALUE;
|
||||
Class<?> closestMatch = null;
|
||||
@@ -35,7 +55,7 @@ public abstract class ClassUtils {
|
||||
}
|
||||
else if (failOnTie && typeDiffWeight < Integer.MAX_VALUE && (typeDiffWeight == minTypeDiffWeight)) {
|
||||
throw new IllegalStateException("Unresolvable ambiguity while attempting to find closest match for [" +
|
||||
type.getName() + "]. Candidate types [" + closestMatch.getName() + "] and [" + candidate.getName() +
|
||||
type.getName() + "]. Candidate types [" + closestMatch.getName() + "] and [" + candidate.getName() +
|
||||
"] have equal weight.");
|
||||
}
|
||||
}
|
||||
@@ -67,4 +87,14 @@ public abstract class ClassUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the given class if it is a primitive wrapper class,
|
||||
* returning the corresponding primitive type instead.
|
||||
* @param clazz the wrapper class to check
|
||||
* @return the corresponding primitive if the clazz is a wrapper, otherwise null
|
||||
*/
|
||||
public static Class<?> resolvePrimitiveType(Class<?> clazz) {
|
||||
return primitiveWrapperTypeMap.get(clazz);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user