[hyddd的FindBugs分析记录][H C FS] Format string references missing argument
2009-02-16 21:00 hyddd 阅读(976) 评论(0) 编辑 收藏 举报[H C FS] Format string references missing argument [VA_FORMAT_STRING_MISSING_ARGUMENT]
Not enough arguments are passed to satisfy a placeholder in the format string. A runtime exception will occur when this statement is executed.
看实例代码:
public static void main(String args[]) throws Exception{
String sqlrightDate = "select state from right where user_id = '%s' and soft_code ='%s' and right_name = '%s' ";
String str = String.format(sqlrightDate,"1" ,"2");
System.out.println(str);
}
对,你没有眼花,format里面只传了两个参数,但sqlrightData需要的是三个参数!这可能值是你的一个笔误,相信没人会故意写这样的代码,但编译器检查不出这种问题,这导致运行时这里会抛异常,所以用FindBugs扫扫代码还是有点用处的~!
String sqlrightDate = "select state from right where user_id = '%s' and soft_code ='%s' and right_name = '%s' ";
String str = String.format(sqlrightDate,"1" ,"2");
System.out.println(str);
}
作者:hyddd
出处:http://www.cnblogs.com/hyddd/
本文版权归作者所有,欢迎转载,演绎或用于商业目的,但是必须说明本文出处(包含链接)。