plutext / docx4j

JAXB-based Java library for Word docx, Powerpoint pptx, and Excel xlsx files

Home Page:https://www.docx4java.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RelationshipsPart.removeParts can't remove hyperlinks (IllegalArgumentException)

h-huss opened this issue · comments

RelationshipsPart.removeParts throws an exception when removing a hyperlink.

Steps to reproduce:
Docx4j 8.3.8

 public static void main(String[] args) throws Exception {
        RelationshipsPart rels = WordprocessingMLPackage.createPackage().getMainDocumentPart().getRelationshipsPart();
        // Created by Word when inserting a hyperlink
        Relationship r = new Relationship();
        r.setId("rel1");
        r.setTarget("https://example.com");
        r.setType(Namespaces.HYPERLINK);
        r.setTargetMode("External");
        rels.addRelationship(r);
        rels.removeParts();
}

Expected: Relationship is removed

Actual:

ERROR org.docx4j.openpackaging.URIHelper - targetUri https://example.com is absolute!
Exception in thread "main" java.lang.IllegalArgumentException: targetUri
	at org.docx4j.openpackaging.URIHelper.resolvePartUri(URIHelper.java:399)
	at org.docx4j.openpackaging.parts.relationships.RelationshipsPart.removeParts(RelationshipsPart.java:731)