Skip to content

Commit

Permalink
[Fix] NullPointerException when input CSV file is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
blcham committed Jul 15, 2022
1 parent f8b407a commit f9c4017
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,15 @@ ExecutionContext executeSelf() {
delimiter,
"\\n").build();

ICsvListReader listReader = null;
try {
listReader = new CsvListReader(getReader(), csvPreference);

try (
ICsvListReader listReader = new CsvListReader(getReader(), csvPreference);
) {
String[] header = listReader.getHeader(true); // skip the header (can't be used with CsvListReader)

if (header == null) {
LOG.warn("Input stream resource {} to provide tabular data is empty.", this.sourceResource.getUri());
return getExecutionContext(inputModel, outputModel);
}
Set<String> columnNames = new HashSet<>();
List<RDFNode> columns = new LinkedList<>();

Expand Down Expand Up @@ -394,16 +397,12 @@ ExecutionContext executeSelf() {

} catch (IOException e) {
LOG.error("Error while reading file from resource uri {}", sourceResource, e);
} finally {
if( listReader != null ) {
try {
listReader.close();
} catch (IOException e) {
LOG.error("Error while closing file from resource uri {}", sourceResource, e);
}
}
}

return getExecutionContext(inputModel, outputModel);
}

private ExecutionContext getExecutionContext(Model inputModel, Model outputModel) {
if (isReplace) {
return ExecutionContextFactory.createContext(outputModel);
} else {
Expand Down

0 comments on commit f9c4017

Please sign in to comment.