如何在Java中替换“null”
对于HP Fortify null遵从性修复程序,是否有其他方法替换“null”。null正在传递给我的一个HQL查询,因此我不能使用“StringUtil.EMPTY”替换null如何在Java中替换“null”,java,fortify,Java,Fortify,对于HP Fortify null遵从性修复程序,是否有其他方法替换“null”。null正在传递给我的一个HQL查询,因此我不能使用“StringUtil.EMPTY”替换null setAdminCurriculums(getAgencyBA().getCurriculumListByCompany(**null**, false)); * * * * 空值正在传递给下面的代码 public String getCurriculumListByCompany(String company
setAdminCurriculums(getAgencyBA().getCurriculumListByCompany(**null**, false));
*
*
*
*
空值正在传递给下面的代码
public String getCurriculumListByCompany(String company, String isCorrect){
*
*
*
String hql = "select id from UserData where userId = " + company;
*
*
}
这取决于传递值“null”时希望发生什么。 如果您不能保证“null”永远不会被传递,那么您将需要在它可能出现的方法中处理它 例如,如果希望它是空字符串,则可以在方法中检查:
company = company != null ? company : "";
由于您正在进一步处理一个查询,我想这实际上不是您想要的行为。但是你想做什么呢?如果没有公司通过,您希望它是任何公司吗
String hql = "Select id from UserData";
if(company != null) {
String hql += " where userId = " + company;
}
传递空值本身不一定是问题。您应该让代码以适当的方式处理此问题-但是从您的描述中,我无法推断正确的解决方案是什么。如果希望不允许使用null值,可以给它一个@NotNull注释,这样如果出现这种情况,它将抛出一个错误
public String getCurriculumListByCompany(@NotNull String company, String isCorrect){
或者,也可以将错误作为保护语句抛出到方法中:
public String getCurriculumListByCompany(String company, String isCorrect){
if(company == null){
throw new RuntimeException("Company should not be null!");
}
..
}
你想成为什么样的人?您正在使用其值从数据库中选择第一行应该做什么?当以null作为第一个参数调用GetCourtulumListByCompany方法时,该方法是否返回任何内容?为什么用户ID是公司?