You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "kexianjun (GitHub)" <gi...@apache.org> on 2018/11/12 11:50:19 UTC

[GitHub] [incubator-dubbo] kexianjun commented on issue #2766: [Dubbo - telnet] Unrecognized overload method

`private static boolean isMatch(Class<?>[] types, List<Object> args) {
        if (types.length != args.size()) {
            return false;
        }
        for (int i = 0; i < types.length; i++) {
            Class<?> type = types[i];
            Object arg = args.get(i);

            if (arg == null) {
                // if the type is primitive, the method to invoke will cause NullPointerException definitely
                // so we can offer a specified error message to the invoker in advance and avoid unnecessary invoking
                if (type.isPrimitive()) {
                    throw new NullPointerException(String.format(
                            "The type of No.%d parameter is primitive(%s), but the value passed is null.", i + 1, type.getName()));
                }

                // if the type is not primitive, we choose to believe what the invoker want is a null value
                continue;
            }

            if (ReflectUtils.isPrimitive(arg.getClass())) {
                if (!ReflectUtils.isPrimitive(type)) {
                    return false;
                }
            } else if (arg instanceof Map) {
                String name = (String) ((Map<?, ?>) arg).get("class");
                Class<?> cls = arg.getClass();
                if (name != null && name.length() > 0) {
                    cls = ReflectUtils.forName(name);
                }
                if (!type.isAssignableFrom(cls)) {
                    return false;
                }
            } else if (arg instanceof Collection) {
                if (!type.isArray() && !type.isAssignableFrom(arg.getClass())) {
                    return false;
                }
            } else {
                if (!type.isAssignableFrom(arg.getClass())) {
                    return false;
                }
            }
        }
        return true;
    }` 
这个方法判断有问题吧
'if (ReflectUtils.isPrimitive(arg.getClass())) {
                if (!ReflectUtils.isPrimitive(type)) {
                    return false;
                }' 
这里只判断了是不是同为基本类型,如果同为基本类型没有继续判断类型是否兼容了,导致不管示例中第一个参数传什么,都是匹配到第一个方法了

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2766 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org