Pull request #29: RED-1428: fixed nullpointer if file does not contain file attribute

Merge in RED/redaction-report-service from RED-1428-5 to master

* commit '02ccdcd867ecbac56747f60fc0a9ea0e264e3fa4':
  RED-1428: fixed nullpointer if file does not contain file attribute
This commit is contained in:
Ali Oezyetimoglu 2021-05-20 11:51:38 +02:00
commit 209b7c00db

View File

@ -80,7 +80,10 @@ public class WordReportGenerationService {
XWPFDocument doc = new XWPFDocument(is);
addTableRows(doc, reportEntries, fileStatus.getFilename());
for (String placeholder : placeholders) {
replaceTextPlaceholders(doc, placeholder, getPlaceholderValue(placeholder, project, fileStatus, fileAttributePlaceholders));
String placeholderValue = getPlaceholderValue(placeholder, project, fileStatus, fileAttributePlaceholders);
if(placeholderValue != null) {
replaceTextPlaceholders(doc, placeholder, placeholderValue);
}
}
return toByteArray(doc);
} catch (IOException e) {
@ -127,7 +130,11 @@ public class WordReportGenerationService {
}
if (fileAttributePlaceholders.containsKey(placeholder)) {
String id = fileAttributePlaceholders.get(placeholder);
return fileStatus.getFileAttributes().getAttributeIdToValue().get(id);
if(fileStatus.getFileAttributes() != null && fileStatus.getFileAttributes().getAttributeIdToValue() != null && fileStatus.getFileAttributes().getAttributeIdToValue().containsKey(id)) {
return fileStatus.getFileAttributes().getAttributeIdToValue().get(id);
} else {
return null;
}
}
throw new RuntimeException("unknown placeholder");
}