diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2016-11-18 23:29:53 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2016-11-18 23:29:53 +0000 |
commit | b93a630aad4c42eed263eddcc08027f3e61ed51b (patch) | |
tree | bb3d45e7655ee41f1c03461bef0b48906264e572 /src | |
parent | a1c9f7f7235c272c99cf345dae66b3452e60eb49 (diff) | |
download | poi-b93a630aad4c42eed263eddcc08027f3e61ed51b.tar.gz poi-b93a630aad4c42eed263eddcc08027f3e61ed51b.zip |
Bug 60373 - TableCell.getTextHeight() returns Null pointer Exception
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1770447 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
4 files changed, 50 insertions, 8 deletions
diff --git a/src/java/org/apache/poi/sl/draw/DrawTableShape.java b/src/java/org/apache/poi/sl/draw/DrawTableShape.java index 970c9b4e0b..947b2ad13c 100644 --- a/src/java/org/apache/poi/sl/draw/DrawTableShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawTableShape.java @@ -137,8 +137,10 @@ public class DrawTableShape extends DrawShape { for (int row=0; row<rows; row++) {
for (int col=0; col<cols; col++) {
TableCell<?,?> tc = ts.getCell(row, col);
- DrawTextShape dts = df.getDrawable(tc);
- dts.drawContent(graphics);
+ if (tc != null) {
+ DrawTextShape dts = df.getDrawable(tc);
+ dts.drawContent(graphics);
+ }
}
}
}
@@ -229,6 +231,9 @@ public class DrawTableShape extends DrawShape { * @param args the border attributes
*/
private static void setEdges(TableCell<?,?> cell, BorderEdge edges[], Object... args) {
+ if (cell == null) {
+ return;
+ }
for (BorderEdge be : edges) {
if (be != null) {
if (args.length == 0) {
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java index 61ab6b44d7..2637381d3e 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java @@ -297,7 +297,7 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow double maxHeight = 0;
for (int col=0; col<cols; col++) {
XSLFTableCell tc = getCell(row, col);
- if (tc.getGridSpan() != 1 || tc.getRowSpan() != 1) {
+ if (tc == null || tc.getGridSpan() != 1 || tc.getRowSpan() != 1) {
continue;
}
// need to set the anchor before height calculation
@@ -314,8 +314,10 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow for (int col=0; col<cols; col++) {
Rectangle2D bounds = new Rectangle2D.Double(newX, newY, colWidths[col], rowHeights[row]);
XSLFTableCell tc = getCell(row, col);
- tc.setAnchor(bounds);
- newX += colWidths[col]+DrawTableShape.borderSize;
+ if (tc != null) {
+ tc.setAnchor(bounds);
+ newX += colWidths[col]+DrawTableShape.borderSize;
+ }
}
newY += rowHeights[row]+DrawTableShape.borderSize;
}
@@ -324,6 +326,9 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow for (int row=0; row<rows; row++) {
for (int col=0; col<cols; col++) {
XSLFTableCell tc = getCell(row, col);
+ if (tc == null) {
+ continue;
+ }
Rectangle2D mergedBounds = tc.getAnchor();
for (int col2=col+1; col2<col+tc.getGridSpan(); col2++) {
assert(col2 < cols);
diff --git a/src/ooxml/testcases/org/apache/poi/sl/TestTable.java b/src/ooxml/testcases/org/apache/poi/sl/TestTable.java index 1dec172dea..ac02a62b46 100644 --- a/src/ooxml/testcases/org/apache/poi/sl/TestTable.java +++ b/src/ooxml/testcases/org/apache/poi/sl/TestTable.java @@ -112,8 +112,10 @@ public class TestTable { int col = 0;
for (TextDirection td : tds) {
TableCell<?,?> c = tbl1.getCell(0, col++);
- c.setTextDirection(td);
- c.setText("bla");
+ if (c != null) {
+ c.setTextDirection(td);
+ c.setText("bla");
+ }
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java index 7c02ba282b..759bbf6fb5 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java @@ -60,6 +60,10 @@ import org.apache.poi.xslf.usermodel.XSLFShape; import org.apache.poi.xslf.usermodel.XSLFSlide; import org.apache.poi.xslf.usermodel.XSLFSlideLayout; import org.apache.poi.xslf.usermodel.XSLFSlideMaster; +import org.apache.poi.xslf.usermodel.XSLFTable; +import org.apache.poi.xslf.usermodel.XSLFTableCell; +import org.apache.poi.xslf.usermodel.XSLFTableRow; +import org.apache.poi.xslf.usermodel.XSLFTextParagraph; import org.apache.poi.xslf.usermodel.XSLFTextRun; import org.junit.Ignore; import org.junit.Test; @@ -556,4 +560,30 @@ public class TestXSLFBugs { rwPptx.close(); ppt.close(); } -} + + + @Test + public void bug60373() throws IOException { + XMLSlideShow ppt = new XMLSlideShow(); + XSLFSlide sl = ppt.createSlide(); + XSLFTable t = sl.createTable(); + XSLFTableRow r = t.addRow(); + bug60373_addCell(r); + bug60373_addCell(r); + r = t.addRow(); + XSLFTableCell c = bug60373_addCell(r); + // call getTextHeight, when table is not fully populated + double th = c.getTextHeight(); + assertTrue(th > 10); + ppt.close(); + } + + private static XSLFTableCell bug60373_addCell(XSLFTableRow r) { + XSLFTableCell cell = r.addCell(); + XSLFTextParagraph p = cell.addNewTextParagraph(); + XSLFTextRun tr = p.addNewTextRun(); + tr.setText("t"); + return cell; + } + +}
\ No newline at end of file |