ASF Bugzilla – Attachment 31367 Details for
Bug 56218
[PATCH] NPE when reading XLSX file with drawing shapes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Patch check NPE with test case
npe_when_reading_xlsx_with_shapes.patch (text/plain), 30.95 KB, created by
thaichat04
on 2014-03-05 10:47:10 UTC
(
hide
)
Description:
Patch check NPE with test case
Filename:
MIME Type:
Creator:
thaichat04
Created:
2014-03-05 10:47:10 UTC
Size:
30.95 KB
patch
obsolete
>Index: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java >=================================================================== >diff --git a/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java b/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java >--- a/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java (revision 1572083) >+++ b/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java (working copy) >@@ -75,14 +75,16 @@ > protected XSSFSimpleShape(XSSFDrawing drawing, CTShape ctShape) { > this.drawing = drawing; > this.ctShape = ctShape; >- >+ > _paragraphs = new ArrayList<XSSFTextParagraph>(); >- >- // initialize any existing paragraphs - this will be the default body paragraph in a new shape, >+ >+ // initialize any existing paragraphs - this will be the default body paragraph in a new shape, > // or existing paragraphs that have been loaded from the file > CTTextBody body = ctShape.getTxBody(); >- for(int i = 0; i < body.sizeOfPArray(); i++) { >- _paragraphs.add(new XSSFTextParagraph(body.getPArray(i), ctShape)); >+ if (body != null) { >+ for(int i = 0; i < body.sizeOfPArray(); i++) { >+ _paragraphs.add(new XSSFTextParagraph(body.getPArray(i), ctShape)); >+ } > } > } > >@@ -120,10 +122,10 @@ > p.addNewPPr().setAlgn(STTextAlignType.L); > CTTextCharacterProperties endPr = p.addNewEndParaRPr(); > endPr.setLang("en-US"); >- endPr.setSz(1100); >+ endPr.setSz(1100); > CTSolidColorFillProperties scfpr = endPr.addNewSolidFill(); > scfpr.addNewSrgbClr().setVal(new byte[] { 0, 0, 0 }); >- >+ > body.addNewLstStyle(); > > prototype = shape; >@@ -143,7 +145,7 @@ > > /** > * Returns the text from all paragraphs in the shape. Paragraphs are separated by new lines. >- * >+ * > * @return text contained within this shape or empty string > */ > public String getText() { >@@ -151,7 +153,7 @@ > StringBuilder out = new StringBuilder(); > List<Integer> levelCount = new ArrayList<Integer>(MAX_LEVELS); // maximum 9 levels > XSSFTextParagraph p = null; >- >+ > // initialise the levelCount array - this maintains a record of the numbering to be used at each level > for (int k = 0; k < MAX_LEVELS; k++){ > levelCount.add(0); >@@ -162,9 +164,9 @@ > p = _paragraphs.get(i); > > if(p.isBullet() && p.getText().length() > 0){ >- >+ > int level = Math.min(p.getLevel(), MAX_LEVELS - 1); >- >+ > if(p.isBulletAutoNumber()){ > i = processAutoNumGroup(i, level, levelCount, out); > } else { >@@ -171,19 +173,19 @@ > // indent appropriately for the level > for(int j = 0; j < level; j++){ > out.append('\t'); >- } >+ } > String character = p.getBulletCharacter(); > out.append(character.length() > 0 ? character + " " : "- "); > out.append(p.getText()); >- } >+ } > } else { > out.append(p.getText()); >- >+ > // this paragraph is not a bullet, so reset the count array > for (int k = 0; k < MAX_LEVELS; k++){ > levelCount.set(k, 0); > } >- } >+ } > } > > return out.toString(); >@@ -190,7 +192,7 @@ > } > > /** >- * >+ * > */ > private int processAutoNumGroup(int index, int level, List<Integer> levelCount, StringBuilder out){ > XSSFTextParagraph p = null; >@@ -197,15 +199,15 @@ > XSSFTextParagraph nextp = null; > ListAutoNumber scheme, nextScheme; > int startAt, nextStartAt; >- >+ > p = _paragraphs.get(index); >- >+ > // The rules for generating the auto numbers are as follows. If the following paragraph is also > // an auto-number, has the same type/scheme (and startAt if defined on this paragraph) then they are > // considered part of the same group. An empty bullet paragraph is counted as part of the same > // group but does not increment the count for the group. A change of type, startAt or the paragraph > // not being a bullet resets the count for that level to 1. >- >+ > // first auto-number paragraph so initialise to 1 or the bullets startAt if present > startAt = p.getBulletAutoNumberStart(); > scheme = p.getBulletAutoNumberScheme(); >@@ -220,23 +222,23 @@ > out.append(getBulletPrefix(scheme, levelCount.get(level))); > out.append(p.getText()); > } >- while(true) { >+ while(true) { > nextp = (index + 1) == _paragraphs.size() ? null : _paragraphs.get(index + 1); > if(nextp == null) break; // out of paragraphs >- if(!(nextp.isBullet() && p.isBulletAutoNumber())) break; // not an auto-number bullet >- if(nextp.getLevel() > level) { >+ if(!(nextp.isBullet() && p.isBulletAutoNumber())) break; // not an auto-number bullet >+ if(nextp.getLevel() > level) { > // recurse into the new level group > if (out.length() > 0) out.append('\n'); > index = processAutoNumGroup(index + 1, nextp.getLevel(), levelCount, out); > continue; // restart the loop given the new index > } else if(nextp.getLevel() < level) { >- break; // changed level >+ break; // changed level > } > nextScheme = nextp.getBulletAutoNumberScheme(); > nextStartAt = nextp.getBulletAutoNumberStart(); >- >+ > if(nextScheme == scheme && nextStartAt == startAt) { >- // bullet is valid, so increment i >+ // bullet is valid, so increment i > ++index; > if (out.length() > 0) out.append('\n'); > // indent for the level >@@ -252,13 +254,13 @@ > } > } else { > // something doesn't match so stop >- break; >+ break; > } > } >- // end of the group so reset the count for this level >- levelCount.set(level, 0); >- >- return index; >+ // end of the group so reset the count for this level >+ levelCount.set(level, 0); >+ >+ return index; > } > /** > * Returns a string containing an appropriate prefix for an auto-numbering bullet >@@ -268,7 +270,7 @@ > */ > private String getBulletPrefix(ListAutoNumber scheme, int value){ > StringBuilder out = new StringBuilder(); >- >+ > switch(scheme) { > case ALPHA_LC_PARENT_BOTH: > case ALPHA_LC_PARENT_R: >@@ -281,7 +283,7 @@ > if(scheme == ListAutoNumber.ALPHA_UC_PARENT_BOTH) out.append('('); > out.append(valueToAlpha(value)); > out.append(')'); >- break; >+ break; > case ALPHA_LC_PERIOD: > out.append(valueToAlpha(value).toLowerCase()); > out.append('.'); >@@ -302,7 +304,7 @@ > break; > case ARABIC_PLAIN: > out.append(value); >- break; >+ break; > case ROMAN_LC_PARENT_BOTH: > case ROMAN_LC_PARENT_R: > if(scheme == ListAutoNumber.ROMAN_LC_PARENT_BOTH) out.append('('); >@@ -314,7 +316,7 @@ > if(scheme == ListAutoNumber.ROMAN_UC_PARENT_BOTH) out.append('('); > out.append(valueToRoman(value)); > out.append(')'); >- break; >+ break; > case ROMAN_LC_PERIOD: > out.append(valueToRoman(value).toLowerCase()); > out.append('.'); >@@ -325,12 +327,12 @@ > break; > default: > out.append('\u2022'); // can't set the font to wingdings so use the default bullet character >- break; >+ break; > } >- out.append(" "); >+ out.append(" "); > return out.toString(); > } >- >+ > /** > * Convert an integer to its alpha equivalent e.g. 1 = A, 2 = B, 27 = AA etc > */ >@@ -344,10 +346,10 @@ > } > return alpha; > } >- >+ > private static String[] _romanChars = new String[] { "M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I" }; > private static int[] _romanAlphaValues = new int[] { 1000,900,500,400,100,90,50,40,10,9,5,4,1 }; >- >+ > /** > * Convert an integer to its roman equivalent e.g. 1 = I, 9 = IX etc > */ >@@ -361,7 +363,7 @@ > } > return out.toString(); > } >- >+ > /** > * Clear all text from this shape > */ >@@ -370,7 +372,7 @@ > CTTextBody txBody = ctShape.getTxBody(); > txBody.setPArray(null); // remove any existing paragraphs > } >- >+ > /** > * Set a single paragraph of text on the shape. Note this will replace all existing paragraphs created on the shape. > * @param text string representing the paragraph text >@@ -413,15 +415,15 @@ > r.setT(lt.getT()); > } > } >- >- clearText(); >+ >+ clearText(); > ctShape.getTxBody().setPArray(new CTTextParagraph[]{p}); > _paragraphs.add(new XSSFTextParagraph(ctShape.getTxBody().getPArray(0), ctShape)); >- } >- >+ } >+ > /** > * Returns a collection of the XSSFTextParagraphs that are attached to this shape >- * >+ * > * @return text paragraphs in this shape > */ > public List<XSSFTextParagraph> getTextParagraphs() { >@@ -439,7 +441,7 @@ > XSSFTextParagraph paragraph = new XSSFTextParagraph(p, ctShape); > _paragraphs.add(paragraph); > return paragraph; >- } >+ } > > /** > * Add a new paragraph run to this shape, set to the provided string >@@ -450,10 +452,10 @@ > XSSFTextParagraph paragraph = addNewTextParagraph(); > paragraph.addNewTextRun().setText(text); > return paragraph; >- } >- >+ } >+ > /** >- * Add a new paragraph run to this shape, set to the provided rich text string >+ * Add a new paragraph run to this shape, set to the provided rich text string > * > * @return created paragraph run > */ >@@ -460,7 +462,7 @@ > public XSSFTextParagraph addNewTextParagraph(XSSFRichTextString str) { > CTTextBody txBody = ctShape.getTxBody(); > CTTextParagraph p = txBody.addNewP(); >- >+ > if(str.numFormattingRuns() == 0){ > CTRegularTextRun r = p.addNewR(); > CTTextCharacterProperties rPr = r.addNewRPr(); >@@ -483,11 +485,11 @@ > r.setT(lt.getT()); > } > } >- >+ > // Note: the XSSFTextParagraph constructor will create its required XSSFTextRuns from the provided CTTextParagraph > XSSFTextParagraph paragraph = new XSSFTextParagraph(p, ctShape); > _paragraphs.add(paragraph); >- >+ > return paragraph; > } > >@@ -518,11 +520,11 @@ > if(bodyPr != null) { > if(bodyPr.isSetHorzOverflow()){ > return TextHorizontalOverflow.values()[bodyPr.getVertOverflow().intValue() - 1]; >- } >+ } > } > return TextHorizontalOverflow.OVERFLOW; >- } >- >+ } >+ > /** > * Sets the type of vertical overflow for the text. > * >@@ -550,11 +552,11 @@ > if(bodyPr != null) { > if(bodyPr.isSetVertOverflow()){ > return TextVerticalOverflow.values()[bodyPr.getVertOverflow().intValue() - 1]; >- } >+ } > } > return TextVerticalOverflow.OVERFLOW; >- } >- >+ } >+ > /** > * Sets the type of vertical alignment for the text within the shape. > * >@@ -582,7 +584,7 @@ > if(bodyPr != null) { > if(bodyPr.isSetAnchor()){ > return VerticalAlignment.values()[bodyPr.getAnchor().intValue() - 1]; >- } >+ } > } > return VerticalAlignment.TOP; > } >@@ -589,7 +591,7 @@ > > /** > * Sets the vertical orientation of the text >- * >+ * > * @param orientation vertical orientation of the text > * A <code>null</code> values unsets this property. > */ >@@ -606,7 +608,7 @@ > > /** > * Gets the vertical orientation of the text >- * >+ * > * @return vertical orientation of the text > */ > public TextDirection getTextDirection(){ >@@ -635,7 +637,7 @@ > } > } > // If this attribute is omitted, then a value of 0.05 inches is implied >- return 3.6; >+ return 3.6; > } > > /** >@@ -688,7 +690,7 @@ > } > } > // If this attribute is omitted, then a value of 0.05 inches is implied >- return 3.6; >+ return 3.6; > } > > /** >@@ -807,7 +809,7 @@ > } > return TextAutofit.NORMAL; > } >- >+ > /** > * Gets the shape type, one of the constants defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}. > * >@@ -856,7 +858,7 @@ > int sz = (int)(pr.getSzArray(0).getVal()*100); > rPr.setSz(sz); > } >- >+ > if(pr.sizeOfColorArray() > 0) { > CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill(); > org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor xlsColor = pr.getColorArray(0); >Index: src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java >=================================================================== >diff --git a/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java b/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java >--- a/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java (revision 1572083) >+++ b/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java (working copy) >@@ -120,7 +120,7 @@ > // Check > dr1 = sheet.createDrawingPatriarch(); > CTDrawing ctDrawing = dr1.getCTDrawing(); >- >+ > // Connector, shapes and text boxes are all two cell anchors > assertEquals(0, ctDrawing.sizeOfAbsoluteAnchorArray()); > assertEquals(0, ctDrawing.sizeOfOneCellAnchorArray()); >@@ -137,10 +137,10 @@ > String xml = ctDrawing.toString(); > assertTrue(xml.contains("xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\"")); > assertTrue(xml.contains("xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"")); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } >- >+ > public void testMultipleDrawings(){ > XSSFWorkbook wb = new XSSFWorkbook(); > for (int i = 0; i < 3; i++) { >@@ -150,7 +150,7 @@ > } > OPCPackage pkg = wb.getPackage(); > assertEquals(3, pkg.getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size()); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } > >@@ -159,7 +159,7 @@ > XSSFSheet sheet1 = wb.getSheetAt(0); > > XSSFSheet sheet2 = wb.cloneSheet(0); >- >+ > //the source sheet has one relationship and it is XSSFDrawing > List<POIXMLDocumentPart> rels1 = sheet1.getRelations(); > assertEquals(1, rels1.size()); >@@ -184,7 +184,7 @@ > assertTrue(sh1.getClass() == sh2.getClass()); > assertEquals(sh1.getShapeProperties().toString(), sh2.getShapeProperties().toString()); > } >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } > >@@ -221,7 +221,7 @@ > assertTrue(Arrays.equals( > new byte[]{0, (byte)128, (byte)128} , > rPr.getSolidFill().getSrgbClr().getVal())); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } > >@@ -253,10 +253,10 @@ > assertEquals(shapes.get(0).getAnchor(), anchor1); > assertEquals(shapes.get(1).getAnchor(), anchor2); > assertEquals(shapes.get(2).getAnchor(), anchor3); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } >- >+ > /** > * ensure that font and color rich text attributes defined in a XSSFRichTextString > * are passed to XSSFSimpleShape. >@@ -286,7 +286,7 @@ > assertTrue(Arrays.equals( > new byte[]{0, (byte)128, (byte)128} , > rPr.getSolidFill().getSrgbClr().getVal())); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } > >@@ -307,25 +307,25 @@ > rt.applyFont(font); > > shape.setText(rt); >- >+ > List<XSSFTextParagraph> paras = shape.getTextParagraphs(); > assertEquals(1, paras.size()); > assertEquals("Test String", paras.get(0).getText()); >- >+ > List<XSSFTextRun> runs = paras.get(0).getTextRuns(); > assertEquals(1, runs.size()); > assertEquals("Arial", runs.get(0).getFontFamily()); >- >- Color clr = runs.get(0).getFontColor(); >+ >+ Color clr = runs.get(0).getFontColor(); > assertTrue(Arrays.equals( > new int[] { 0, 255, 255 } , > new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() })); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } >- >+ > /** >- * Test addNewTextParagraph >+ * Test addNewTextParagraph > */ > public void testAddNewTextParagraph() { > XSSFWorkbook wb = new XSSFWorkbook(); >@@ -333,17 +333,17 @@ > XSSFDrawing drawing = sheet.createDrawingPatriarch(); > > XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)); >- >+ > XSSFTextParagraph para = shape.addNewTextParagraph(); > para.addNewTextRun().setText("Line 1"); >- >+ > List<XSSFTextParagraph> paras = shape.getTextParagraphs(); > assertEquals(2, paras.size()); // this should be 2 as XSSFSimpleShape creates a default paragraph (no text), and then we add a string to that. >- >+ > List<XSSFTextRun> runs = para.getTextRuns(); > assertEquals(1, runs.size()); > assertEquals("Line 1", runs.get(0).getText()); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } > >@@ -358,17 +358,17 @@ > XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)); > XSSFRichTextString rt = new XSSFRichTextString("Test Rich Text String"); > >- XSSFFont font = wb.createFont(); >+ XSSFFont font = wb.createFont(); > font.setColor(new XSSFColor(new Color(0, 255, 255))); > font.setFontName("Arial"); > rt.applyFont(font); >- >+ > XSSFFont midfont = wb.createFont(); > midfont.setColor(new XSSFColor(new Color(0, 255, 0))); > rt.applyFont(5, 14, midfont); // set the text "Rich Text" to be green and the default font >- >+ > XSSFTextParagraph para = shape.addNewTextParagraph(rt); >- >+ > // Save and re-load it > wb = XSSFTestDataSamples.writeOutAndReadBack(wb); > sheet = wb.getSheetAt(0); >@@ -375,48 +375,48 @@ > > // Check > drawing = sheet.createDrawingPatriarch(); >- >+ > List<XSSFShape> shapes = drawing.getShapes(); > assertEquals(1, shapes.size()); >- assertTrue(shapes.get(0) instanceof XSSFSimpleShape); >- >+ assertTrue(shapes.get(0) instanceof XSSFSimpleShape); >+ > XSSFSimpleShape sshape = (XSSFSimpleShape) shapes.get(0); >- >+ > List<XSSFTextParagraph> paras = sshape.getTextParagraphs(); >- assertEquals(2, paras.size()); // this should be 2 as XSSFSimpleShape creates a default paragraph (no text), and then we add a string to that. >- >+ assertEquals(2, paras.size()); // this should be 2 as XSSFSimpleShape creates a default paragraph (no text), and then we add a string to that. >+ > List<XSSFTextRun> runs = para.getTextRuns(); > assertEquals(3, runs.size()); >- >+ > // first run properties > assertEquals("Test ", runs.get(0).getText()); > assertEquals("Arial", runs.get(0).getFontFamily()); > >- Color clr = runs.get(0).getFontColor(); >+ Color clr = runs.get(0).getFontColor(); > assertTrue(Arrays.equals( > new int[] { 0, 255, 255 } , > new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() })); > >- // second run properties >+ // second run properties > assertEquals("Rich Text", runs.get(1).getText()); > assertEquals(XSSFFont.DEFAULT_FONT_NAME, runs.get(1).getFontFamily()); > >- clr = runs.get(1).getFontColor(); >+ clr = runs.get(1).getFontColor(); > assertTrue(Arrays.equals( > new int[] { 0, 255, 0 } , >- new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() })); >- >+ new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() })); >+ > // third run properties > assertEquals(" String", runs.get(2).getText()); > assertEquals("Arial", runs.get(2).getFontFamily()); >- clr = runs.get(2).getFontColor(); >+ clr = runs.get(2).getFontColor(); > assertTrue(Arrays.equals( > new int[] { 0, 255, 255 } , > new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() })); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); >- } >- >+ } >+ > /** > * Test add multiple paragraphs and retrieve text > */ >@@ -426,23 +426,23 @@ > XSSFDrawing drawing = sheet.createDrawingPatriarch(); > > XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)); >- >+ > XSSFTextParagraph para = shape.addNewTextParagraph(); > para.addNewTextRun().setText("Line 1"); >- >+ > para = shape.addNewTextParagraph(); > para.addNewTextRun().setText("Line 2"); >- >+ > para = shape.addNewTextParagraph(); > para.addNewTextRun().setText("Line 3"); >- >+ > List<XSSFTextParagraph> paras = shape.getTextParagraphs(); > assertEquals(4, paras.size()); // this should be 4 as XSSFSimpleShape creates a default paragraph (no text), and then we added 3 paragraphs >- assertEquals("Line 1\nLine 2\nLine 3", shape.getText()); >- >+ assertEquals("Line 1\nLine 2\nLine 3", shape.getText()); >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } >- >+ > /** > * Test setting the text, then adding multiple paragraphs and retrieve text > */ >@@ -452,22 +452,22 @@ > XSSFDrawing drawing = sheet.createDrawingPatriarch(); > > XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)); >- >+ > shape.setText("Line 1"); >- >+ > XSSFTextParagraph para = shape.addNewTextParagraph(); > para.addNewTextRun().setText("Line 2"); >- >+ > para = shape.addNewTextParagraph(); > para.addNewTextRun().setText("Line 3"); >- >+ > List<XSSFTextParagraph> paras = shape.getTextParagraphs(); > assertEquals(3, paras.size()); // this should be 3 as we overwrote the default paragraph with setText, then added 2 new paragraphs > assertEquals("Line 1\nLine 2\nLine 3", shape.getText()); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } >- >+ > /** > * Test reading text from a textbox in an existing file > */ >@@ -493,13 +493,13 @@ > > assertTrue(shapes.get(4) instanceof XSSFSimpleShape); > >- XSSFSimpleShape textbox = (XSSFSimpleShape) shapes.get(4); >+ XSSFSimpleShape textbox = (XSSFSimpleShape) shapes.get(4); > assertEquals("Sheet with various pictures\n(jpeg, png, wmf, emf and pict)", textbox.getText()); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } > >- >+ > /** > * Test reading multiple paragraphs from a textbox in an existing file > */ >@@ -509,11 +509,11 @@ > //the sheet has one relationship and it is XSSFDrawing > List<POIXMLDocumentPart> rels = sheet.getRelations(); > assertEquals(1, rels.size()); >- >+ > assertTrue(rels.get(0) instanceof XSSFDrawing); > > XSSFDrawing drawing = (XSSFDrawing)rels.get(0); >- >+ > //sheet.createDrawingPatriarch() should return the same instance of XSSFDrawing > assertSame(drawing, sheet.createDrawingPatriarch()); > String drawingId = drawing.getPackageRelationship().getId(); >@@ -528,34 +528,34 @@ > assertTrue(shapes.get(0) instanceof XSSFSimpleShape); > > XSSFSimpleShape textbox = (XSSFSimpleShape) shapes.get(0); >- >+ > List<XSSFTextParagraph> paras = textbox.getTextParagraphs(); > assertEquals(3, paras.size()); >- >+ > assertEquals("Line 2", paras.get(1).getText()); // check content of second paragraph > > assertEquals("Line 1\nLine 2\nLine 3", textbox.getText()); // check content of entire textbox >- >+ > // check attributes of paragraphs > assertEquals(TextAlign.LEFT, paras.get(0).getTextAlign()); > assertEquals(TextAlign.CENTER, paras.get(1).getTextAlign()); > assertEquals(TextAlign.RIGHT, paras.get(2).getTextAlign()); >- >- Color clr = paras.get(0).getTextRuns().get(0).getFontColor(); >+ >+ Color clr = paras.get(0).getTextRuns().get(0).getFontColor(); > assertTrue(Arrays.equals( > new int[] { 255, 0, 0 } , > new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() })); >- >- clr = paras.get(1).getTextRuns().get(0).getFontColor(); >+ >+ clr = paras.get(1).getTextRuns().get(0).getFontColor(); > assertTrue(Arrays.equals( > new int[] { 0, 255, 0 } , > new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() })); >- >- clr = paras.get(2).getTextRuns().get(0).getFontColor(); >+ >+ clr = paras.get(2).getTextRuns().get(0).getFontColor(); > assertTrue(Arrays.equals( > new int[] { 0, 0, 255 } , > new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() })); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } > >@@ -563,13 +563,13 @@ > * Test adding and reading back paragraphs as bullet points > */ > public void testAddBulletParagraphs() { >- >+ > XSSFWorkbook wb = new XSSFWorkbook(); > XSSFSheet sheet = wb.createSheet(); > XSSFDrawing drawing = sheet.createDrawingPatriarch(); > > XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 10, 20)); >- >+ > String paraString1 = "A normal paragraph"; > String paraString2 = "First bullet"; > String paraString3 = "Second bullet (level 1)"; >@@ -580,7 +580,7 @@ > String paraString8 = "Third bullet (level 1)"; > String paraString9 = "Fourth bullet (level 1)"; > String paraString10 = "Fifth Bullet"; >- >+ > XSSFTextParagraph para = shape.addNewTextParagraph(paraString1); > para = shape.addNewTextParagraph(paraString2); > para.setBullet(true); >@@ -591,7 +591,7 @@ > > para = shape.addNewTextParagraph(paraString4); > para.setBullet(true); >- >+ > para = shape.addNewTextParagraph(paraString5); > para = shape.addNewTextParagraph(paraString6); > para.setBullet(ListAutoNumber.ARABIC_PERIOD); >@@ -599,7 +599,7 @@ > para = shape.addNewTextParagraph(paraString7); > para.setBullet(ListAutoNumber.ARABIC_PERIOD, 3); > para.setLevel(1); >- >+ > para = shape.addNewTextParagraph(paraString8); > para.setBullet(ListAutoNumber.ARABIC_PERIOD, 3); > para.setLevel(1); >@@ -607,14 +607,14 @@ > para = shape.addNewTextParagraph(""); > para.setBullet(ListAutoNumber.ARABIC_PERIOD, 3); > para.setLevel(1); >- >+ > para = shape.addNewTextParagraph(paraString9); > para.setBullet(ListAutoNumber.ARABIC_PERIOD, 3); > para.setLevel(1); >- >+ > para = shape.addNewTextParagraph(paraString10); > para.setBullet(ListAutoNumber.ARABIC_PERIOD); >- >+ > // Save and re-load it > wb = XSSFTestDataSamples.writeOutAndReadBack(wb); > sheet = wb.getSheetAt(0); >@@ -621,18 +621,18 @@ > > // Check > drawing = sheet.createDrawingPatriarch(); >- >+ > List<XSSFShape> shapes = drawing.getShapes(); > assertEquals(1, shapes.size()); >- assertTrue(shapes.get(0) instanceof XSSFSimpleShape); >- >+ assertTrue(shapes.get(0) instanceof XSSFSimpleShape); >+ > XSSFSimpleShape sshape = (XSSFSimpleShape) shapes.get(0); >- >+ > List<XSSFTextParagraph> paras = sshape.getTextParagraphs(); > assertEquals(12, paras.size()); // this should be 12 as XSSFSimpleShape creates a default paragraph (no text), and then we added to that >- >+ > StringBuilder builder = new StringBuilder(); >- >+ > builder.append(paraString1); > builder.append("\n"); > builder.append("\u2022 "); >@@ -662,12 +662,12 @@ > builder.append("\n"); > builder.append("2. "); > builder.append(paraString10); >- >+ > assertEquals(builder.toString(), sshape.getText()); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); >- } >- >+ } >+ > /** > * Test reading bullet numbering from a textbox in an existing file > */ >@@ -690,7 +690,14 @@ > sb.append("\t\n\t\n\t\n\t"); > > assertEquals(sb.toString(), extracted); >- >+ > assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); > } >+ >+ public void testNPEWhenReadingShape(){ >+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("testShapeNPE.xlsx"); >+ XSSFSheet sheet = wb.getSheetAt(1); >+ XSSFDrawing drawing = sheet.createDrawingPatriarch(); >+ assertEquals(131, drawing.getShapes().size()); >+ } > } >Index: test-data/spreadsheet/testShapeNPE.xlsx >=================================================================== >Cannot display: file marked as a binary type. >svn:mime-type = application/octet-stream >Index: test-data/spreadsheet/testShapeNPE.xlsx >=================================================================== >diff --git a/poi/trunk/test-data/spreadsheet/testShapeNPE.xlsx b/poi/trunk/test-data/spreadsheet/testShapeNPE.xlsx >--- a/poi/trunk/test-data/spreadsheet/testShapeNPE.xlsx (revision 0) >+++ b/poi/trunk/test-data/spreadsheet/testShapeNPE.xlsx (working copy) > >Property changes on: poi/trunk/test-data/spreadsheet/testShapeNPE.xlsx >___________________________________________________________________ >Added: svn:mime-type >## -0,0 +1 ## >+application/octet-stream >\ No newline at end of property
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 56218
: 31367