我的Java有点生疏......特别是在垃圾收集方面,所以我可以帮助找到一个解决方案来解决这个问题是如何不正确地结束于" null"在这结束:
public void copyFileBuffered(String inPUT, String outPUT) throws
FileNotFoundException, IOException {
InputStream is = null;
OutputStream os = null;
try{
if(inPUT != null)
is = new FileInputStream(inPUT);
if(outPUT != null)
os = new FileOutputStream(outPUT);
int count = 0;
byte b[] = new byte[BLKSIZ];
while ((count = is.read(b)) != -1) { /** FORTIFY ERROR LINE */
os.write(b, 0, count);
}
}
catch(Exception e){}
finally{
if(is != null)
is.close();
if(os != null)
os.close();
}
}
从我所看到的" os = new FileOutputStream(outPUT);" FORTIFY:copyFileBuffered()方法取消引用空指针。
答案 0 :(得分:1)
您的if语句在说明以下内容时是逐字明确的:
inPUT
为null
,则is
为null
。 outPUT
为null
,则os
为null
。静态分析会告诉您的代码可能解除引用null
,这将是一个重大错误。
您没有告诉我们这些来自哪里,所以如果您遇到了NullPointerException
,请确保inPUT
和outPUT
实际上都没有通过null
这段代码。