Uploaded image for project: 'Hippo CMS'
  1. Hippo CMS
  2. CMS-13610

Content rewriter for PageModelApi can result in NPE in case of broken links

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • None
    • 14.2.3, 14.3.0
    • None
    • None
    • Quasar
    • Puma Sprint 239

    Description

      Do we still need to fix things in 14.2.2?

      The classes

      org.hippoecm.hst.pagemodelapi.v09.content.rewriter.HtmlContentRewriter
      org.hippoecm.hst.pagemodelapi.v10.content.rewriter.HtmlContentRewriter

      have a clear NPE in

      final HstLink hstLink = getDocumentLink(documentPath, node, requestContext, targetMount);
                          if (hstLink == null || hstLink.isNotFound() || hstLink.getPath() == null) {
                              if (removeAnchorTagOfBrokenLink) {
                                  log.info("Could not create a link for '{}'. Removing the anchor now maintaining the text.",
                                          documentPath);
      
                                  final ContentNode textContent = new ContentNode(anchorTag.getText().toString());
                                  anchorTag.getParent().insertChildAfter(anchorTag, textContent);
                                  anchorTag.getParent().removeChild(anchorTag);
                                  continue;
                              } else {
                                  log.info("Could not create a link for '{}'.", documentPath);
                              }
                          }
      
                          // use link model because the hst link we want is from the 'site mount' and not from the
                          // 'page model api mount'
                          final LinkModel linkModel = LinkModel.convert(hstLink, requestContext);
      
      

      it should of course be

      final HstLink hstLink = getDocumentLink(documentPath, node, requestContext, targetMount);
                          if (hstLink == null || hstLink.isNotFound() || hstLink.getPath() == null) {
                              if (removeAnchorTagOfBrokenLink) {
                                  log.info("Could not create a link for '{}'. Removing the anchor now maintaining the text.",
                                          documentPath);
      
                                  final ContentNode textContent = new ContentNode(anchorTag.getText().toString());
                                  anchorTag.getParent().insertChildAfter(anchorTag, textContent);
                                  anchorTag.getParent().removeChild(anchorTag);
                              } else {
                                  log.info("Could not create a link for '{}'.", documentPath);
                              }
                                  continue;
                          }
      
                          // use link model because the hst link we want is from the 'site mount' and not from the
                          // 'page model api mount'
                          final LinkModel linkModel = LinkModel.convert(hstLink, requestContext);
      
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            aschrijvers Ard Schrijvers
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: