diff --git a/common/src/main/java/com/highgo/cloud/util/CommonUtil.java b/common/src/main/java/com/highgo/cloud/util/CommonUtil.java index 237f091..b668c0d 100644 --- a/common/src/main/java/com/highgo/cloud/util/CommonUtil.java +++ b/common/src/main/java/com/highgo/cloud/util/CommonUtil.java @@ -95,7 +95,7 @@ public static boolean isWrapClass(Class clz) { @SuppressWarnings("rawtypes") public static boolean isNumber(Class cls) { - return cls.getSuperclass().equals(Number.class) || CommonUtil.isWrapClass(cls) || cls.isPrimitive(); + return Number.class.equals(cls.getSuperclass()) || CommonUtil.isWrapClass(cls) || cls.isPrimitive(); } /** diff --git a/tests/regression/CommonUtilClassPredicateRegression.java b/tests/regression/CommonUtilClassPredicateRegression.java new file mode 100644 index 0000000..75dc59c --- /dev/null +++ b/tests/regression/CommonUtilClassPredicateRegression.java @@ -0,0 +1,39 @@ +import com.highgo.cloud.util.CommonUtil; + +/** Complete real class, genuine JDK Class values, no copied classifier or framework doubles. */ +public final class CommonUtilClassPredicateRegression { + private static int failures; + private static int cases; + + private static void expect(Class type, boolean expected) { + cases++; + try { + boolean actual = CommonUtil.isNumber(type); + if (actual != expected) { + throw new AssertionError(type + ": expected " + expected + ", got " + actual); + } + System.out.println("PASS " + type.getTypeName()); + } catch (Throwable error) { + failures++; + System.err.println("FAIL " + type.getTypeName() + ": " + error); + error.printStackTrace(System.err); + } + } + + public static void main(String[] args) { + expect(byte.class, true); + expect(short.class, true); + expect(int.class, true); + expect(long.class, true); + expect(float.class, true); + expect(double.class, true); + expect(Object.class, false); + expect(CharSequence.class, false); + expect(Integer.class, true); + expect(String.class, false); + if (failures != 0) { + throw new AssertionError(failures + " of " + cases + " cases failed"); + } + System.out.println(cases + " cases passed"); + } +}