From aeb554ee62b1c7208fea4e5cd1a75a0ea90f60c6 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Tue, 23 Jan 2018 11:46:02 +1100 Subject: [PATCH] Issue 872 fix This commit attempts a fix to issue 872. The inputFileName ('master' file) parameter may be null, in which case the function returns just the file name if short name is required. --- .../pmd/util/datasource/FileDataSource.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/datasource/FileDataSource.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/datasource/FileDataSource.java index a3691033fc..142a10d6e6 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/datasource/FileDataSource.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/datasource/FileDataSource.java @@ -37,14 +37,19 @@ public class FileDataSource implements DataSource { } private String glomName(boolean shortNames, String inputFileName, File file) { - if (shortNames && inputFileName.indexOf(',') == -1) { - if (new File(inputFileName).isDirectory()) { - return trimAnyPathSep(file.getPath().substring(inputFileName.length())); - } else { - if (inputFileName.indexOf(FILE_SEPARATOR.charAt(0)) == -1) { - return inputFileName; + if (shortNames) { + if (inputFileName != null && inputFileName.indexOf(',') == -1) { + if (new File(inputFileName).isDirectory()) { + return trimAnyPathSep(file.getPath().substring(inputFileName.length())); + } else { + if (inputFileName.indexOf(FILE_SEPARATOR.charAt(0)) == -1) { + return inputFileName; + } + return trimAnyPathSep(inputFileName.substring(inputFileName.lastIndexOf(FILE_SEPARATOR))); } - return trimAnyPathSep(inputFileName.substring(inputFileName.lastIndexOf(FILE_SEPARATOR))); + } else { + // if the 'master' file is not specified, just use the file name + return file.getName(); } }