Skip to content

Commit

Permalink
Fixed access to nullable ContentReader
Browse files Browse the repository at this point in the history
  • Loading branch information
mirjan-hoffmann committed Oct 12, 2020
1 parent 1101adf commit 452e209
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,7 @@ public void scanFile(NodeRef nodeRef) throws InvalidNodeRefException {
if (nodeService.exists(nodeRef)) {
contentReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);

if ((contentReader != null)
&& (fileExceptions.indexOf(contentReader.getMimetype()) == -1
&& (fileOnlyOrExceptions.toLowerCase()).equals(FILE_EXCEPTIONS))
|| (fileOnly.indexOf(contentReader.getMimetype()) != -1
&& (fileOnlyOrExceptions.toLowerCase()).equals(FILE_ONLY))) {
if (shouldScan(contentReader)) {
String contentUrl = contentReader.getContentUrl();
String contentPath = contentUrl.replaceFirst("store:/", this.store);

Expand Down Expand Up @@ -249,13 +245,24 @@ else if (mode.toUpperCase().equals(VirusScanMode.ScanModeICap)) {
logger.debug("[File: " + contentReader.getContentUrl() + " is clean");
}
}
}
}

else if ((!(fileOnlyOrExceptions.toLowerCase()).equals(FILE_ONLY))
|| (!(fileOnlyOrExceptions.toLowerCase()).equals(FILE_EXCEPTIONS))) {
logger.error("Property alfviral.file.only_or_exceptions not is '" + FILE_ONLY + "' or '"
+ FILE_EXCEPTIONS + "'");
}
private boolean shouldScan(final ContentReader contentReader) {
if ((!(fileOnlyOrExceptions.toLowerCase()).equals(FILE_ONLY))
&& (!(fileOnlyOrExceptions.toLowerCase()).equals(FILE_EXCEPTIONS))) {
logger.error("Property alfviral.file.only_or_exceptions not is '" + FILE_ONLY + "' or '" + FILE_EXCEPTIONS
+ "'");
return false;
}
if (contentReader != null) {
final boolean fileExceptionsMatches = fileExceptions.indexOf(contentReader.getMimetype()) == -1
&& (fileOnlyOrExceptions.toLowerCase()).equals(FILE_EXCEPTIONS);
final boolean fileOnlyMatches = fileOnly.indexOf(contentReader.getMimetype()) != -1
&& (fileOnlyOrExceptions.toLowerCase()).equals(FILE_ONLY);
return fileExceptionsMatches || fileOnlyMatches;
}
return false;
}

/**
Expand Down

0 comments on commit 452e209

Please sign in to comment.