Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent potential NullPointerExceptions #6369

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -219,7 +219,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()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can parentNode have children which are Null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially, yes, because children is just a list of DefaultTreeNode, itself an implementation of the interface TreeNode, and instances of every non-primitive type in Java can be null. Whether this can actually be the case in the Kitodo context is a different story, but shouldn't be the deciding factor for adding null checks, IMHO.

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 @@ -632,7 +632,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
Loading