[MGNLDAM-509] DamTemplatingFunctions: getRendition(String, String) must do a null check on the inner asset Created: 03/Sep/14  Updated: 08/Sep/14  Resolved: 08/Sep/14

Status: Closed
Project: Magnolia DAM Module
Component/s: None
Affects Version/s: 2.0.2
Fix Version/s: 2.0.3

Type: Bug Priority: Neutral
Reporter: Christian Ringele Assignee: Federico Grilli
Resolution: Fixed Votes: 0
Labels: support
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File DamTemplatingFunctions-2.0.2.patch    
Issue Links:
causality
Template:
Patch included:
Yes
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   

In:

    public AssetRendition getRendition(String itemKey, String renditionName) {
        Asset asset = getAsset(itemKey);
        return getRendition(asset, MediaType.parse(asset.getMimeType()), renditionName);
    }

the asset mus be null checked, as later is called "MediaType.parse(asset.getMimeType())" on it. Like this a un-handled exception is thrown which is not really catch-able in the freemarker script (null pointer check doesn't work).

Change to:

    public AssetRendition getRendition(String itemKey, String renditionName) {
        Asset asset = getAsset(itemKey);
        if (asset == null) {
            return null;
        }
        return getRendition(asset, MediaType.parse(asset.getMimeType()), renditionName);
    }

Possible workaround:

  • Use the info.magnolia.dam.templating.functions.DamTemplatingFunctions.getAsset(String)
  • do a null check on the returned asset
  • if not null use the info.magnolia.dam.templating.functions.DamTemplatingFunctions.getRendition(Asset, String)

Generated at Mon Feb 12 05:00:33 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.