Skip to content

Commit

Permalink
Refactor addStandardAccessRules method for null safety
Browse files Browse the repository at this point in the history
A null-check has been added before using the standardAccessRules variable to safeguard against potential NullPointerException. The logic has also been reconsidered, and now it only attempts to populate the standardAccessRules set from the database if it is found to be empty or null. This should enhance efficiency by avoiding unnecessary database calls.
  • Loading branch information
Gcolon021 committed May 27, 2024
1 parent f8884d2 commit 2f52314
Showing 1 changed file with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -870,21 +870,24 @@ private void populateHarmonizedAccessRule(AccessRule rule, String parentConceptP
// to cache the standard access rules
private Set<AccessRule> standardAccessRules;


private void addStandardAccessRules(Set<AccessRule> accessRules) {
if (!standardAccessRules.isEmpty()) {
if (standardAccessRules != null && !standardAccessRules.isEmpty()) {
accessRules.addAll(standardAccessRules);
}
for (String arName : fence_standard_access_rules.split(",")) {
if (arName.startsWith("AR_")) {
logger.info("Adding AccessRule {} to privilege", arName);
AccessRule ar = accessruleRepo.getUniqueResultByColumn("name", arName);
if (ar != null) {
accessRules.add(ar);
} else {
logger.warn("Unable to find an access rule with name {}", arName);
} else {
standardAccessRules = new HashSet<>();
for (String arName : fence_standard_access_rules.split(",")) {
if (arName.startsWith("AR_")) {
logger.info("Adding AccessRule {} to privilege", arName);
AccessRule ar = accessruleRepo.getUniqueResultByColumn("name", arName);
if (ar != null) {
standardAccessRules.add(ar);
} else {
logger.warn("Unable to find an access rule with name {}", arName);
}
}
}

accessRules.addAll(standardAccessRules);
}
}

Expand Down

0 comments on commit 2f52314

Please sign in to comment.