Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SubErrors#getSubErrorCode类型转换bug #4

Open
xiegengcai opened this issue Nov 7, 2012 · 1 comment
Open

SubErrors#getSubErrorCode类型转换bug #4

xiegengcai opened this issue Nov 7, 2012 · 1 comment

Comments

@xiegengcai
Copy link

如果参数是Number类型就没法强制转换为String,那么错误信息就没法准确定位了

public static String getSubErrorCode(SubErrorType subErrorType, Object... params) {
String subErrorCode = subErrorType.value();
if (params.length > 0) {
if (params.length == 1) {
subErrorCode = subErrorCode.replace(PARAM_1, (String) params[0]);
} else {
subErrorCode = subErrorCode.replace(PARAM_1, (String) params[0]);
if (params[1] != null) {
subErrorCode = subErrorCode.replace(PARAM_2, (String) params[1]);
}
}
}
return subErrorCode;
}


目前是修改为

public static String getSubErrorCode(SubErrorType subErrorType, Object... params) {
String subErrorCode = subErrorType.value();
if (params.length > 0) {
String replaceStr=params[0] instanceof Number?String.valueOf(params[0]):(String) params[0];
if (params.length == 1) {
subErrorCode = subErrorCode.replace(PARAM_1, replaceStr);
} else {
subErrorCode = subErrorCode.replace(PARAM_1, replaceStr);
if (params[1] != null) {
subErrorCode = subErrorCode.replace(PARAM_2, params[0] instanceof Number?String.valueOf(params[1]):(String) params[1]);
}
}
}
return subErrorCode;
}

@itstamen
Copy link
Owner

这样不好吧,如果是多少参数呢?在传入参数时自己转一下不是更好吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants