[MAGNOLIA-2768] NPE on link replacement for invalid links in fckedit Created: 08/Jun/09  Updated: 23/Jan/13  Resolved: 22/Sep/09

Status: Closed
Project: Magnolia
Component/s: fckeditor
Affects Version/s: None
Fix Version/s: 4.1.1

Type: Bug Priority: Minor
Reporter: Fabrizio Giustina Assignee: Magnolia International
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
relation
is related to MAGNOLIA-2865 Internal Page link in fckEdit: When t... Closed
supersession
is superseded by MAGNOLIA-2862 if some paragraph contains a link /us... Closed
is superseded by MAGNOLIA-2872 Further improve/consolidate Link api 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
Date of First Response:

 Description   

This happened with a link to a resource not existing anymore in the dms repository, although it can't be reproduced easily:

java.lang.NullPointerException
	at java.util.regex.Matcher.getTextLength(Unknown Source)
	at java.util.regex.Matcher.reset(Unknown Source)
	at java.util.regex.Matcher.<init>(Unknown Source)
	at java.util.regex.Pattern.matcher(Unknown Source)
	at info.magnolia.module.fckeditor.dialogs.FckEditorDialog.convertToView(FckEditorDialog.java:407)
	at info.magnolia.module.fckeditor.dialogs.FckEditorDialog.drawHtml(FckEditorDialog.java:281)
	at info.magnolia.cms.gui.dialog.DialogControlImpl.drawSubs(DialogControlImpl.java:322)
	at info.magnolia.cms.gui.dialog.DialogControlImpl.drawHtml(DialogControlImpl.java:166)

fckedit crashes during link resolving and the dialog can't be open anymore. Looking at the code it seems LinkUtil.convertUUIDsToEditorLinks(value) returns a null value and the following regexp fails:

    public String convertToView(String value) {

        if (value != null) {
            // we have to add the context path for images and files but not for pages!
            value = LinkUtil.convertUUIDsToEditorLinks(value);

            // this section is for backward compatibility - see MAGNOLIA-2088
            final Matcher matcher = LinkHelper.LINK_OR_IMAGE_PATTERN.matcher(value);

it may worth to add a simple null check before the additional replacement...



 Comments   
Comment by Fabrizio Giustina [ 12/Aug/09 ]

A simple null check added

Comment by Jan Haderka [ 16/Sep/09 ]

The committed fix causes disappearance of the linked text as well as removal of the link. It should remove only the hyperlink, but not the text that was used as an anchor for the link.

Comment by Jan Haderka [ 25/Sep/09 ]

With the current fix the broken link remains in the page, which is all right, but would not it be better to make this configurable in the LinkFactory whether in such case the broken link should be rendered or removed (just from the rendered content, not from the original) as a means to control broken links on the site?

Comment by Magnolia International [ 25/Sep/09 ]

This could be another feature if we wanted, but the context here is when rendering text in fckeditor; we can't "hide" the links here - it's actually rendering the broken link "on purpose", so that the editor can fix the link.

When rendering links "on pages", yes, we could do something like what you propose. See linked issue for further improvements to the links api.

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