Bug 60512

Summary: Missing XSSFRelation.CUSTOM_PROPERTY generates POIXMLException on cloneSheet() method
Product: POI Reporter: samson <samsontesfay>
Component: XSSFAssignee: POI Developers List <dev>
Severity: regression CC: lapocioni, lucamartini
Priority: P2    
Version: 3.15-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Bug Depends on:    
Bug Blocks: 60742    
Attachments: TestCloneSheetWithCustomProperty

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.