【发布时间】:2020-11-08 04:24:09
【问题描述】:
SonarQube for Java 在以下代码中抱怨:“确保在此处安全使用命令行参数”:
public class Test {
public static void main(String[] args) {
try {
System.out.print(returnSum(args));
} catch (NumberFormatException nfe) {
System.out.println("main: Input argument should be a number");
}
}
public static int returnSum(String[] args) {
int sum = 0;
if (args.length > 0) {
try {
for (String arg : args)
sum += Integer.parseInt(arg);
} catch (NumberFormatException nfe) {
System.out.println("returnSum: Input argument should be a number");
throw nfe;
}
}
return sum;
}
}
为了满足 SonarQube 的要求,我还缺少什么?
【问题讨论】: