RED-1428: fixed nullpointer if file does not contain file attribute

This commit is contained in:
aoezyetimoglu 2021-05-20 11:49:10 +02:00
parent 96d86b0603
commit 02ccdcd867

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");
}