[MAGNOLIA-4673] MgnlMailFactory fails with NPE when failing to initialise renderer. Created: 19/Nov/12  Updated: 27/Nov/12  Resolved: 26/Nov/12

Status: Closed
Project: Magnolia
Component/s: mail
Affects Version/s: 4.5.4
Fix Version/s: 4.5.7

Type: Bug Priority: Neutral
Reporter: Jan Haderka Assignee: Roman Kovařík
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Cloners
is cloned by MGNLMAIL-3 MgnlMailFactory fails with NPE when f... Closed
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

 Description   
        if(renderers.containsKey(template.getType().toLowerCase())){
            String rendererClass = renderers.get(template.getType().toLowerCase());
            mail = Classes.quietNewInstance(rendererClass, template);
        }
        else {
            mail = new SimpleEmail(template);
        }

quietNewInstance() will return null in case of failure to instantiate renderer. This leads to NPE later down in the code when attempting to set properties on mail.

I believe that failure to create renderer should not be swallowed but propagated up to calling code.
Also code above should be able to handle situation when template type is not specified at all (And choose SimpleMail like in case of unrecognized renderer.



 Comments   
Comment by Jan Haderka [ 26/Nov/12 ]

This issue needs to be cloned to MGNLMAIL and fix on master of mail module as well.
Further more rather then using quietNewInstance() and then checking the null and throwing exception:

             mail = Classes.quietNewInstance(rendererClass, template);
+                throw new Exception("Failure to instantiate rendererclass: " + rendererClass + ".");

you should use just Classes.newInstance() and let the exception that is thrown from this method go through instead.

Generated at Mon Feb 12 03:57:56 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.