Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-3687

RenderingEngine does not restore aggregation state when throwing RenderException

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Major
    • None
    • 4.4.3
    • rendering, templating
    • None

    Description

      In DefaultRenderingEngine.java there's a number of situations that can cause a RenderException to be thrown. At the start of the method the AggregationState is updated to reflect the renderable that is to be rendered. This is not reset when an exception is thrown.

      Proposed solution:

      protected void render(Content content, String definitionName, RenderingHelper helper, Writer out) throws RenderException {
          Content orgMainContent = null;
          Content orgCurrentContent = null;
      
          AggregationState state = getAggregationStateSafely();
          if (state != null) {
              orgMainContent = state.getMainContent();
              orgCurrentContent = state.getCurrentContent();
      
              state.setCurrentContent(content);
              // if not yet set the passed content is the entry point of the rendering
              if (orgMainContent == null) {
                  state.setMainContent(content);
              }
          }
      
          try {
      
              RenderableDefinition definition = helper.getDefinition(definitionName);
              if (definition == null) {
                  throw new RenderException("Can't find renderable definition " + definitionName + " for content: " + content.getHandle());
              }
      
              Object renderer = helper.getRenderer(definition);
              if (renderer == null) {
                  throw new RenderException("Can't find renderer for type " + definition.getType() + " of content: " + content.getHandle());
              }
      
              helper.render(content, definition, renderer, out);
          }
          catch (IOException e) {
              throw new RenderException("Can't render " + content.getHandle(), e);
          } finally {
              if (state != null) {
                  state.setMainContent(orgMainContent);
                  state.setCurrentContent(orgCurrentContent);
              }
          }
      }
      

      Checklists

        Acceptance criteria

        Attachments

          Issue Links

            Activity

              People

                Unassigned Unassigned
                tmattsson Tobias Mattsson
                Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:

                  Checklists

                    Bug DoR
                    Task DoD