]> source.dussan.org Git - poi.git/commitdiff
Fix bug #50119 - avoid NPE when XSSFReader comes across chart sheets
authorNick Burch <nick@apache.org>
Wed, 20 Oct 2010 16:25:24 +0000 (16:25 +0000)
committerNick Burch <nick@apache.org>
Wed, 20 Oct 2010 16:25:24 +0000 (16:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1025630 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java
test-data/spreadsheet/WithChartSheet.xlsx [new file with mode: 0644]

index 979e81ce545bc47a1e91679cbd18a972240d9e00..c27545d3cfea6a8b5af5783c7f0c2d7035eb7cc0 100644 (file)
@@ -34,7 +34,7 @@
 
     <changes>
         <release version="3.8-beta1" date="2010-??-??">
-          
+           <action dev="poi-developers" type="fix">50119 - avoid NPE when XSSFReader comes across chart sheets</action>
         </release>
         <release version="3.7" date="2010-10-25">
            <action dev="poi-developers" type="fix">50075 - avoid NPE in ListLevel.getNumberText() when numberText is null </action>
index 991d6661d3c31928db0cb5cda7d00ae25363c27d..0994ad8500c2e82636a36b63727c25cfa51c231a 100644 (file)
@@ -177,7 +177,8 @@ public class XSSFReader {
                 //step 1. Map sheet's relationship Id and the corresponding PackagePart
                 sheetMap = new HashMap<String, PackagePart>();
                 for(PackageRelationship rel : wb.getRelationships()){
-                    if(rel.getRelationshipType().equals(XSSFRelation.WORKSHEET.getRelation())){
+                    if(rel.getRelationshipType().equals(XSSFRelation.WORKSHEET.getRelation()) ||
+                       rel.getRelationshipType().equals(XSSFRelation.CHARTSHEET.getRelation())){
                         PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
                         sheetMap.put(rel.getId(), wb.getPackage().getPart(relName));
                     }
index 0592fbcc76aa78fd1e240338b49724f29c1b1644..11f03dd62d8b6aa5c92f851802f82109a78de966 100644 (file)
@@ -116,4 +116,22 @@ public final class TestXSSFReader extends TestCase {
                }
                assertEquals(4, count);
        }
+       
+   
+   /**
+    * Iterating over a workbook with chart sheets in it, using the
+    *  XSSFReader method
+    * @throws Exception
+    */
+   public void test50119() throws Exception {
+      OPCPackage pkg =  XSSFTestDataSamples.openSamplePackage("WithChartSheet.xlsx");
+      XSSFReader r = new XSSFReader(pkg);
+      XSSFReader.SheetIterator it = (XSSFReader.SheetIterator)r.getSheetsData();
+      
+      while(it.hasNext())
+      {
+          InputStream stream = it.next();
+          stream.close();
+      }
+   }
 }
diff --git a/test-data/spreadsheet/WithChartSheet.xlsx b/test-data/spreadsheet/WithChartSheet.xlsx
new file mode 100644 (file)
index 0000000..8defbd6
Binary files /dev/null and b/test-data/spreadsheet/WithChartSheet.xlsx differ