[MAGNOLIA-6055] NullPointerException thrown to PageEditor when class configured for contextAttribute is not available Created: 29/Jan/15  Updated: 13/Feb/15  Resolved: 04/Feb/15

Status: Closed
Project: Magnolia
Component/s: rendering
Affects Version/s: 5.4
Fix Version/s: 5.4

Type: Bug Priority: Neutral
Reporter: Christopher Zimmermann Assignee: Philip Mundt
Resolution: Fixed Votes: 0
Labels: quickwin
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   

This could happen to a user if for example they install a module which installs a contextAttribute in the configuration @ /modules/rendering/renderers/freemarker/contextAttributes
(Such as damfn).

And then the user removes the module from the project.
They only get a totally cryptic NullPointerException on every page render.

Expected Fix:
Page should render as normal (as long as they dont try to use the contextAttribute of course) and useful error written to log.

Please see branch on MAIN: 'MAGNOLIA-6055-clz'.



 Comments   
Comment by Christopher Zimmermann [ 29/Jan/15 ]

If "entry.getValue().getComponentClass()" is null, log error and do not try to add it as a context attribute.

Comment by Magnolia International [ 03/Feb/15 ]

While I agree to not try and add the component into the context if null, the rest of this patch should IMO be reverted:

  • it's not the business of the renderer to know how/where it's configured
  • you already an ERROR in your log like the below, which happens whenever the configuration is loaded (in your case, likely at startup, but you'll see the same if you try and modify the config at runtime)
  • this goes against what we do for config where a) stuff might be configured in other location than nodes (which makes your log message more confusing than helping), b) stuff gets validated (so one could have a rule for ContextAttributeConfiguration that mandates a non-null componentClass), and c) stuff that's invalid will likely (although that's still up for decision) not be usable (e.g in a case like this, the whole renderer would be invalid, and consequently the page won't be rendered at all)
ERROR  info.magnolia.jcr.node2bean.impl.Node2BeanTransformerImpl 03.02.2015 15:09:40 -- Can't set property [componentClass] to value [foo.info.magnolia.templating.functions.TemplatingFunctions] in bean [info.magnolia.rendering.renderer.ContextAttributeConfiguration] for node /modules/rendering/renderers/freemarker/contextAttributes/cmsfn due to org.apache.commons.beanutils.ConversionException: Default conversion to Class failed.
Generated at Mon Feb 12 04:10:53 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.