com中可能的空指针解除引用。 <package>。 NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

时间:2018-01-09 18:01:33

标签: java maven

我有以下代码库。

 private void buildHiveConfAndVars(final StringBuilder hiveConfbuilder, final StringBuilder hiveVarBuilder)
        throws FileNotFoundException, IOException, SQLException {
    if (StringUtils.isEmpty(variableDirectories)) {
        return;
    }
    String[] hiveVariableDirectoryPaths = variableDirectories.split(",");
    for (int i = 0; i < hiveVariableDirectoryPaths.length; i++) {
        File hiveVariableDirectory = new File(hiveVariableDirectoryPaths[i]);
        File[] hiveVariableFiles = hiveVariableDirectory.listFiles(new FileFilter() {

            @Override
            public boolean accept(final File file) {
                return file.getName().endsWith(variableFileExtension);
            }
        });
        for (int j = 0; j < hiveVariableFiles.length; j++) {
            buildVariableMapFromFile(hiveVarBuilder, hiveVariableFiles[j].getAbsolutePath());
        }
    }
    if (StringUtils.isEmpty(variableFiles)) {
        return;
    }
    String[] hiveVariableFilePaths = variableFiles.split(",");
    buildVariableMap(hiveVarBuilder, hiveVariableFilePaths);
}

我正在运行findbugs-maven-plugin。所以低于警告。

[INFO] Possible null pointer dereference in com.<package-name>.PigUnitMojo.buildHiveConfAndVars(StringBuilder, StringBuilder) due to return value of called method [com.<package-name>.PigUnitMojo, com.<package-name>.PigUnitMojo] Dereferenced at PigUnitMojo.java:[line 441]Known null at PigUnitMojo.java:[line 433] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

[INFO] com..PigUnitMojo.buildHiveConfAndVars(StringBuilder,StringBuilder)中可能的空指针取消引用由于被调用方法的返回值[com..PigUnitMojo,com..PigUnitMojo]在PigUnitMojo.java上取消引用:[line 441] PigUnitMojo.java中的已知null:[line 433] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

1 个答案:

答案 0 :(得分:0)

你的问题出在以下几个方面:

File[] hiveVariableFiles = hiveVariableDirectory.listFiles(...)
for (int j = 0; j < hiveVariableFiles.length; j++) {

...因为如果找不到文件,listFiles将返回null。因此,请记住检查File.listFiles返回的每个值的空值。