https://bz.apache.org/bugzilla/show_bug.cgi?id=65530

            Bug ID: 65530
           Summary: Adding an opaque URI hyperlink (e.g., 'mailto', 'tel')
                    to an image triggers a NullPointerException.
           Product: POI
           Version: unspecified
          Hardware: Macintosh
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSLF
          Assignee: dev@poi.apache.org
          Reporter: he...@canva.com
  Target Milestone: ---

Adding an opaque URI hyperlink (e.g., 'mailto', 'tel') to an image triggers a
NullPointerException.

var uri = toUri("mailto:foo@bar";);
System.out.println("Is URI opaque? " + uri.isOpaque());
var nvPicPr = ((CTPicture) picture.getXmlObject()).getNvPicPr();
var cNvPr = nvPicPr.getCNvPr() != null ? nvPicPr.getCNvPr() :
nvPicPr.addNewCNvPr();
var hyperlink = cNvPr.addNewHlinkClick();
//
// Here is where the NullPointerException is thrown
// 
var rel = slide.getPackagePart()
    .addRelationship(uri, TargetMode.EXTERNAL,
XSLFRelation.HYPERLINK.getRelation());
hyperlink.setId(rel.getId())

We tracked it down to file PackagingURIHelper.java, method
`isRelationshipPartURI`:

public static boolean isRelationshipPartURI(URI partUri) {
    if (partUri == null)
        throw new IllegalArgumentException("partUri");

// 
// !! Here, calling partUri.getPath() when the URI is opaque returns null !!
//
    return partUri.getPath().matches(
            ".*" + RELATIONSHIP_PART_SEGMENT_NAME + ".*"
                    + RELATIONSHIP_PART_EXTENSION_NAME + "$");
}  

Part of the stack trace:

java.lang.NullPointerException
        at
org.apache.poi.openxml4j.opc.PackagingURIHelper.isRelationshipPartURI(PackagingURIHelper.java:169)
        at
org.apache.poi.openxml4j.opc.PackagePart.addRelationship(PackagePart.java:337)
        at
org.apache.poi.openxml4j.opc.PackagePart.addRelationship(PackagePart.java:293)

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to