gpt4 book ai didi

java - 在以下方法中,我遇到了 findbug 违规 RV_RETURN_VALUE_IGNORED_BAD_PRACTICE

转载 作者:行者123 更新时间:2023-11-30 04:06:11 25 4
gpt4 key购买 nike

public File moveFileToUploadLoc(final File dir) throws Exception {
File fileToMove = null;
if (dir != null) {
final File[] files = dir.listFiles();
for (int i = 0; files != null && i < files.length; i++) {
if (files[i].getName().endsWith("abcd")) {
fileToMove = files[i];

File destnFile = this.getFilePathFrmConfigRepo(this
.getFilePathKey());
fileToMove.renameTo(destinationFile);

break;
}
}
}

return fileToMove;
}

这表明RV_RETURN_VALUE_IGNORED_BAD_PRACTICE

This method returns a value that is not checked. The return value should be checked since it can indicate an unusual or unexpected function execution. For example, the File.delete() method returns false if the file could not be successfully deleted (rather than throwing an Exception). If you don't check the result, you won't notice if the method invocation signals unexpected behavior by returning an atypical return value.

最佳答案

阅读(现在正确)引用的文本,您会发现解释很清楚。对于每个返回值的函数,您应该以某种方式使用该函数。

他们的示例甚至专门引用了 File 方法,delete()。在这种情况下,findbugs 最有可能是指您对 File.renameTo() 的调用.

您应该检查此函数的返回值并相应地处理错误 (false)。

关于java - 在以下方法中,我遇到了 findbug 违规 RV_RETURN_VALUE_IGNORED_BAD_PRACTICE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20675328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com