mirror of https://github.com/apache/poi.git
BUG-60285 avoid NPE if missing relationship id
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765861 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e816f0f79f
commit
489bebba0e
|
@ -47,6 +47,7 @@ import org.apache.poi.xssf.usermodel.XSSFShape;
|
|||
import org.apache.xmlbeans.XmlException;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STSheetState;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument;
|
||||
|
||||
/**
|
||||
|
@ -226,7 +227,16 @@ public class XSSFReader {
|
|||
//step 2. Read array of CTSheet elements, wrap it in a ArayList and construct an iterator
|
||||
//Note, using XMLBeans might be expensive, consider refactoring to use SAX or a plain regexp search
|
||||
CTWorkbook wbBean = WorkbookDocument.Factory.parse(wb.getInputStream(), DEFAULT_XML_OPTIONS).getWorkbook();
|
||||
sheetIterator = wbBean.getSheets().getSheetList().iterator();
|
||||
List<CTSheet> validSheets = new ArrayList<CTSheet>();
|
||||
for (CTSheet ctSheet : wbBean.getSheets().getSheetList()) {
|
||||
//if there's no relationship id, silently skip the sheet
|
||||
if ("".equals(ctSheet.getId())) {
|
||||
//skip it
|
||||
} else {
|
||||
validSheets.add(ctSheet);
|
||||
}
|
||||
}
|
||||
sheetIterator = validSheets.iterator();
|
||||
} catch (InvalidFormatException e){
|
||||
throw new POIXMLException(e);
|
||||
} catch (XmlException e){
|
||||
|
|
|
@ -246,4 +246,23 @@ public final class TestXSSFReader extends TestCase {
|
|||
|
||||
pkg.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* NPE when sheet has no relationship id in the workbook
|
||||
* 60825
|
||||
*/
|
||||
public void testSheetWithNoRelationshipId() throws Exception {
|
||||
OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("60825.xlsx");
|
||||
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(pkg);
|
||||
assertNotNull(strings);
|
||||
XSSFReader reader = new XSSFReader(pkg);
|
||||
StylesTable styles = reader.getStylesTable();
|
||||
assertNotNull(styles);
|
||||
|
||||
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) reader.getSheetsData();
|
||||
assertNotNull(iter.next());
|
||||
assertFalse(iter.hasNext());
|
||||
|
||||
pkg.close();
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue