diff --git a/CHANGELOG.md b/CHANGELOG.md index 5da0dce764..5bbf754fb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,11 +10,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com) ## Unreleased ([details][unreleased changes details]) - ### Fixed - #3380 - Remove forced red theme from system notification text body - #3398 - CreateRedirectConfigurationServlet throws PersistenceException when ancestor node types are different than expected +- #3402 - EnsureOakIndexManagerImpl does not pick up changes in EnsureOakIndex configurations. +- #3357 - Added debugging and null checking to ReferencesModel to prevent NPE +- #3398 - CreateRedirectConfigurationServlet throws PersistenceException when ancestor node types are different than expected - #3275 - CCVAR: Fixed Same Attribute not updating correctly. ### Changed @@ -24,12 +26,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com) - #3401 - Move SyslogAppender into separate bundle for onprem only. SyslogAppender does not work in Cloud Service. - #3390 - Remove usage of commons collections 3 - -### Fixed - -- #3402 - EnsureOakIndexManagerImpl does not pick up changes in EnsureOakIndex configurations. - - ## 6.6.2 - 2024-06-25 ### Fixed diff --git a/bundle/src/main/java/com/adobe/acs/commons/reports/models/ReferencesModel.java b/bundle/src/main/java/com/adobe/acs/commons/reports/models/ReferencesModel.java index 47c064940a..a514e8edcd 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/reports/models/ReferencesModel.java +++ b/bundle/src/main/java/com/adobe/acs/commons/reports/models/ReferencesModel.java @@ -18,6 +18,7 @@ package com.adobe.acs.commons.reports.models; import com.adobe.acs.commons.reports.internal.DelimiterConfiguration; + import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -36,59 +37,87 @@ import com.adobe.granite.references.ReferenceAggregator; import com.adobe.granite.references.ReferenceList; import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Model(adaptables = Resource.class) public class ReferencesModel implements ReportCellCSVExporter { + private static final Logger log = LoggerFactory.getLogger(ReferencesModel.class); + + @ValueMapValue + @OSGiService + private ReferenceAggregator aggregator; + + @OSGiService + private DelimiterConfiguration delimiterConfiguration; + + private ReferenceList referenceList; + + private Resource resource; + + public ReferencesModel(Resource resource) { + this.resource = resource; + } + + /** + * Used only for testing. + * + * @param delimiterConfiguration the delimiter configuration to use for this exporter + */ + ReferencesModel(Resource resource, DelimiterConfiguration delimiterConfiguration) { + this.resource = resource; + this.delimiterConfiguration = delimiterConfiguration; + } - @ValueMapValue - @OSGiService - private ReferenceAggregator aggregator; - - @OSGiService - private DelimiterConfiguration delimiterConfiguration; - - private ReferenceList referenceList; - - private Resource resource; - - public ReferencesModel(Resource resource) { - this.resource = resource; - } - - /** - * Used only for testing. - * @param delimiterConfiguration the delimiter configuration to use for this exporter - */ - ReferencesModel(Resource resource, DelimiterConfiguration delimiterConfiguration) { - this.resource = resource; - this.delimiterConfiguration = delimiterConfiguration; - } - - public List getReferences() { - return Optional.ofNullable(referenceList) - .map(Collections::unmodifiableList) - .orElse(Collections.emptyList()); - } - - @Override - public String getValue(Object result) { - resource = (Resource) result; - init(); - List refStrings = new ArrayList<>(); - for (Reference reference : referenceList) { - refStrings.add(reference.getType() + " - " + reference.getTarget().getPath()); + public List getReferences() { + return Optional.ofNullable(referenceList) + .map(Collections::unmodifiableList) + .orElse(Collections.emptyList()); } - return StringUtils.join(refStrings, delimiterConfiguration.getMultiValueDelimiter()); - } - - @PostConstruct - public void init() { - referenceList = aggregator.createReferenceList(resource); - Iterator references = referenceList.iterator(); - while (references.hasNext()) { - if (references.next().getTarget().getPath().equals(resource.getPath())) { - references.remove(); - } + + @Override + public String getValue(Object result) { + resource = (Resource) result; + init(); + List refStrings = new ArrayList<>(); + for (Reference reference : referenceList) { + refStrings.add(reference.getType() + " - " + reference.getTarget().getPath()); + } + return StringUtils.join(refStrings, delimiterConfiguration.getMultiValueDelimiter()); + } + + @PostConstruct + public void init() { + if (resource == null) { + throw new IllegalStateException("Resource is null, and must must be set before calling init()"); + } + + referenceList = aggregator.createReferenceList(resource); + Iterator references = referenceList.iterator(); + + while (references.hasNext()) { + Reference reference = references.next(); + + if (reference == null) { + log.warn("Reference is null for resource: {}", resource.getPath()); + continue; + } + + Resource target = reference.getTarget(); + if (target == null) { + log.warn("Reference target is null for resource: {}", resource.getPath()); + continue; + } + + String targetPath = target.getPath(); + if (StringUtils.isBlank(targetPath)) { + log.warn("Reference target path is blank for resource: {}", resource.getPath()); + continue; + } + + if (StringUtils.equals(targetPath, resource.getPath())) { + references.remove(); + } + } } - } }