[MAGNOLIA-7613] TemplatingFunctions#handleRepositoryException suppresses possible NPE Created: 30/Aug/19  Updated: 11/Mar/21  Resolved: 11/Mar/21

Status: Closed
Project: Magnolia
Component/s: templating
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Low
Reporter: Richard Gange Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

In the class info.magnolia.templating.functions.TemplatingFunctions if line 873 encounters a NullPointerException during `handleRepositoryException` then a side-effect is that the parameter `e` is ignored, loosing exception context to the other.

We should consider refactoring the logic or adding a second catch to handle the null pointer gracefully.

    private void handleRepositoryException(RepositoryException e, String workspace) {
        final AggregationState aggregationState = webContextProvider.get().getAggregationState();
        String template;
        if (aggregationState != null) try {
            template = NodeTypes.Renderable.getTemplate(aggregationState.getCurrentContentNode());
        } catch (RepositoryException re) {
            log.error("Repository Exception: {}", re);
        }
        log.debug("Exception in '{}' workspace when rendering template '{}' for URI '{}': {}", workspace, template, aggregationState.getOriginalBrowserURI(), e);

    }


 Comments   
Comment by Jose Maria Ruiz [ 02/Sep/19 ]

Would deleting the word "Repository" from the catch clause be an acceptable fix?

Generated at Mon Feb 12 04:25:18 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.