Bug 60512 - Missing XSSFRelation.CUSTOM_PROPERTY generates POIXMLException on cloneSheet() method
Summary: Missing XSSFRelation.CUSTOM_PROPERTY generates POIXMLException on cloneSheet(...
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.15-FINAL
Hardware: PC All
: P2 regression (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Blocks: 60742
  Show dependency tree
Reported: 2016-12-22 14:55 UTC by samson
Modified: 2017-02-17 16:58 UTC (History)
2 users (show)

TestCloneSheetWithCustomProperty (64.60 KB, application/octet-stream)
2016-12-30 14:11 UTC, samson

Note You need to log in before you can comment on or make changes to this bug.
Description samson 2016-12-22 14:55:14 UTC
The XSSFRelation doesn't have a relation of type Custom property. Hence while cloning a sheet (XSSFSheet) containing a custom property relation type, it generates an exception 

POIXMLException: Can't clone sheet - unknown relation type found: http://schemas.openxmlformats.org/officeDocument/2006/relationships/customProperty


 private static void addRelation(RelationPart rp, POIXMLDocumentPart target) {
        PackageRelationship rel = rp.getRelationship();
        if (rel.getTargetMode() == TargetMode.EXTERNAL) {
                rel.getTargetURI(), rel.getTargetMode(), rel.getRelationshipType(), rel.getId());
        } else {        
            XSSFRelation xssfRel = XSSFRelation.getInstance(rel.getRelationshipType());
            if (xssfRel == null) {
                // Don't copy all relations blindly, but only the ones we know about
                throw new POIXMLException("Can't clone sheet - unknown relation type found: "+rel.getRelationshipType());
            target.addRelation(rel.getId(), xssfRel, rp.getDocumentPart());

You can find more infos here: http://people.apache.org/~centic/poi_regression/reportsAll/
Comment 1 samson 2016-12-22 15:19:11 UTC
A possible fix: add a new XSSFRelation (XSSFRelation.java)

    public static final XSSFRelation CUSTOM_PROPERTIES = new XSSFRelation(
Comment 2 Javen O'Neal 2016-12-27 18:25:20 UTC
Can you attch a sample workbook with a custom relation so that we can write a unit test for this?
Code that adds a custom relation to a blank workbook works too.
Comment 3 samson 2016-12-30 14:11:35 UTC
Created attachment 34570 [details]

Here I have attached a sample excel file which contains a custom property (i.e. raises an exception when the contained sheet is to be cloned).
Comment 4 Dominik Stadler 2016-12-30 16:55:50 UTC
Applied via r1776606, thanks for the suggested patch.