]> source.dussan.org Git - poi.git/commitdiff
bug 58996: Don't try to unset fill color if it is not set to avoid invalid access...
authorDominik Stadler <centic@apache.org>
Fri, 12 Feb 2016 09:44:47 +0000 (09:44 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 12 Feb 2016 09:44:47 +0000 (09:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1729964 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java

index ea355756ef52c6f2cbe2f3ceb9f4285131e6f17f..8e47990f12f0724d8472ebc2e43e5d1db9ff1bc7 100644 (file)
@@ -1075,7 +1075,7 @@ public void setBorderTop(short border) {
         CTFill ct = getCTFill();
         CTPatternFill ptrn = ct.getPatternFill();
         if(color == null) {
-            if(ptrn != null) ptrn.unsetBgColor();
+            if(ptrn != null && ptrn.isSetBgColor()) ptrn.unsetBgColor();
         } else {
             if(ptrn == null) ptrn = ct.addNewPatternFill();
             ptrn.setBgColor(color.getCTColor());
@@ -1129,7 +1129,7 @@ public void setBorderTop(short border) {
 
         CTPatternFill ptrn = ct.getPatternFill();
         if(color == null) {
-            if(ptrn != null) ptrn.unsetFgColor();
+            if(ptrn != null && ptrn.isSetFgColor()) ptrn.unsetFgColor();
         } else {
             if(ptrn == null) ptrn = ct.addNewPatternFill();
             ptrn.setFgColor(color.getCTColor());
@@ -1211,8 +1211,8 @@ public void setBorderTop(short border) {
      * @see #setFillForegroundColor(short)
      * @param fp  fill pattern (set to {@link org.apache.poi.ss.usermodel.CellStyle#SOLID_FOREGROUND} to fill w/foreground color)
      */
-   @Override
-public void setFillPattern(short fp) {
+    @Override
+    public void setFillPattern(short fp) {
         CTFill ct = getCTFill();
         CTPatternFill ptrn = ct.isSetPatternFill() ? ct.getPatternFill() : ct.addNewPatternFill();
         if(fp == NO_FILL && ptrn.isSetPatternType()) ptrn.unsetPatternType();
index 21f14bb5d6a15719cd83d91c85f744dfa0521739..5b29d7911d3502edcd1e7c723946cf89dd81c630 100644 (file)
@@ -29,15 +29,7 @@ import java.io.IOException;
 
 import org.apache.poi.hssf.usermodel.HSSFCellStyle;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.DataFormat;
-import org.apache.poi.ss.usermodel.HorizontalAlignment;
-import org.apache.poi.ss.usermodel.IndexedColors;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.VerticalAlignment;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.model.StylesTable;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
@@ -1086,4 +1078,31 @@ public class TestXSSFCellStyle {
         cellStyle.setRotation((short)-90);
         assertEquals(180, cellStyle.getRotation());
     }
+
+    @Test
+    public void bug58996_UsedToWorkIn3_11_ButNotIn3_13() throws IOException {
+        XSSFWorkbook workbook = new XSSFWorkbook();
+
+        XSSFCellStyle cellStyle = workbook.createCellStyle();
+        cellStyle.setFillForegroundColor(null);
+        assertNull(cellStyle.getFillForegroundColorColor());
+
+        cellStyle.setFillBackgroundColor(null);
+        assertNull(cellStyle.getFillBackgroundColorColor());
+
+        cellStyle.setFillPattern(FillPatternType.NO_FILL);
+        assertEquals(FillPatternType.NO_FILL, cellStyle.getFillPatternEnum());
+
+        cellStyle.setBottomBorderColor(null);
+        assertNull(cellStyle.getBottomBorderXSSFColor());
+
+        cellStyle.setTopBorderColor(null);
+        assertNull(cellStyle.getTopBorderXSSFColor());
+
+        cellStyle.setLeftBorderColor(null);
+        assertNull(cellStyle.getLeftBorderXSSFColor());
+
+        cellStyle.setRightBorderColor(null);
+        assertNull(cellStyle.getRightBorderXSSFColor());
+    }
 }