Skip to content

Commit

Permalink
Prevent potential NullPointerExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Feb 4, 2025
1 parent 9353d55 commit f85cec4
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private DataRecord performQueryToRecord(DataImport dataImport, String queryURL,
}
try (InputStream inputStream = httpEntity.getContent()) {
String content = IOUtils.toString(inputStream, Charset.defaultCharset());
if (Objects.nonNull(interfaceType.getNumberOfRecordsString())
if (Objects.nonNull(interfaceType) && Objects.nonNull(interfaceType.getNumberOfRecordsString())
&& XmlResponseHandler.extractNumberOfRecords(content, interfaceType) < 1) {
throw new NoRecordFoundException("No record with ID \"" + identifier + "\" found!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ public void prepareProcess(int templateId, int projectId, String referringView,
processDataTab.setAllDocTypes(docTypes);
titleRecordLinkTab.setChosenParentProcess(String.valueOf(parentId));
titleRecordLinkTab.chooseParentProcess();
if (Objects.nonNull(project.getDefaultChildProcessImportConfiguration())) {
if (Objects.nonNull(project) && Objects.nonNull(project
.getDefaultChildProcessImportConfiguration())) {
setCurrentImportConfiguration(project.getDefaultChildProcessImportConfiguration());
}
if (setChildCount(titleRecordLinkTab.getTitleRecordProcess(), rulesetManagement, workpiece)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ private void createMetadataTable() {
}
}
List<MetadataViewWithValuesInterface> tableData = metadataView.getSortedVisibleMetadata(entered, additionallySelectedFields);
treeNode.getChildren().clear();
if (Objects.nonNull(treeNode) && Objects.nonNull(treeNode.getChildren())) {
treeNode.getChildren().clear();
}
hiddenMetadata = Collections.emptyList();
for (MetadataViewWithValuesInterface rowData : tableData) {
Optional<MetadataViewInterface> optionalMetadataView = rowData.getMetadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,14 @@ public void show() {

private void restoreSelection(String rowKey, TreeNode parentNode) {
for (TreeNode childNode : parentNode.getChildren()) {
if (Objects.nonNull(childNode) && rowKey.equals(childNode.getRowKey())) {
childNode.setSelected(true);
break;
} else {
childNode.setSelected(false);
restoreSelection(rowKey, childNode);
if (Objects.nonNull(childNode)) {
if (rowKey.equals(childNode.getRowKey())) {
childNode.setSelected(true);
break;
} else {
childNode.setSelected(false);
restoreSelection(rowKey, childNode);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ private void markErrorCommentAsCorrected(Task currentTask, Integer correctionTas
}

private static boolean isEqualCorrectionTask(Integer correctionTaskId, Task correctionTask) {
return (Objects.isNull(correctionTaskId) && Objects.isNull(correctionTask)) || (Objects.nonNull(
correctionTaskId) && correctionTaskId.equals(correctionTask.getId()));
return (Objects.isNull(correctionTaskId)
&& Objects.isNull(correctionTask))
|| (Objects.nonNull(correctionTaskId)
&& Objects.nonNull(correctionTask)
&& correctionTaskId.equals(correctionTask.getId()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,10 @@ private void processRecoveredMetadata(List<RecoveredMetadata> recoveredMetadata)
metadata.setMetadataType(metaDatum.getMetadataType());
metadata.setStartValue(metaDatum.getValue());
metadata.setStepSize(metaDatum.getStepSize());
foundBlock.addMetadata(metadata);
last.put(Pair.of(foundBlock, metaDatum.getMetadataType()), metadata);
if (Objects.nonNull(foundBlock)) {
foundBlock.addMetadata(metadata);
last.put(Pair.of(foundBlock, metaDatum.getMetadataType()), metadata);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ && new IssueComparator(block).compare(Pair.of(this.create.getLeft(), this.create
&& (Objects.isNull(delete) || new IssueComparator(block).compare(issue, delete) < 0)
|| Boolean.TRUE.equals(create) && Pair.of(this.create.getLeft(), this.create.getMiddle()).equals(issue)
|| Boolean.FALSE.equals(create)
&& (Objects.isNull(issue) && Objects.isNull(this.delete) || issue.equals(this.delete)));
&& (Objects.isNull(issue) && Objects.isNull(this.delete)
|| (Objects.nonNull(issue) && issue.equals(this.delete))));
}
}
return false;
Expand Down Expand Up @@ -342,7 +343,7 @@ public List<ProcessDetail> getAllMetadataTypes(Integer processId) {
Helper.setErrorMessage("Unable to load metadata types: " + e.getMessage());
}
}
if (Objects.nonNull(metadataDetail)) {
if (Objects.nonNull(metadataDetail) && Objects.nonNull(allMetadataTypes)) {
for (int i = 0; i < allMetadataTypes.size(); i++) {
if (allMetadataTypes.get(i).getMetadataID().equals(metadataDetail.getMetadataID())) {
allMetadataTypes.set(i, metadataDetail);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ protected Long countDocuments(QueryBuilder query) throws DataException {
* @return query
*/
protected QueryBuilder createSetQuery(String key, Set<?> values, boolean contains) {
if (contains && !values.isEmpty()) {
if (contains && Objects.nonNull(values) && !values.isEmpty()) {
return termsQuery(key, values);
} else if (!contains && Objects.nonNull(values)) {
BoolQueryBuilder boolQuery = new BoolQueryBuilder();
Expand Down

0 comments on commit f85cec4

Please sign in to comment.