From 82e268acf37542f43c3d430f71560bb5c5b6000b Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Wed, 10 Oct 2012 15:41:35 +0000 Subject: [PATCH] Bug 53965: Fixed XmlValueOutOfRangeExceptio calling getDataValidations for custom validations with XSSFSheet git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1396650 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../usermodel/XSSFDataValidationHelper.java | 6 ++++- .../usermodel/TestXSSFDataValidation.java | 22 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 1180c5cdf..928e9c317 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 53965 - Fixed XmlValueOutOfRangeExceptio calling getDataValidations for custom validations with XSSFSheet 53974 - Avoid NPE when constructing HSSFWorbook on Google App Engine 53568 - Fixed null returned by XSSFPicture.getPictureData() 53950 - fixed setForceFormulaRecalculation to reset workbook-level "manual" flag diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataValidationHelper.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataValidationHelper.java index 3ef669877..b0bd4e783 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataValidationHelper.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataValidationHelper.java @@ -26,6 +26,7 @@ import org.apache.poi.ss.usermodel.DataValidationConstraint.ValidationType; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddressList; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidation; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataValidationOperator; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataValidationType; /** @@ -146,7 +147,10 @@ public class XSSFDataValidationHelper implements DataValidationHelper { } if (validationType!=ValidationType.ANY && validationType!=ValidationType.LIST) { - newDataValidation.setOperator(XSSFDataValidation.operatorTypeMappings.get(constraint.getOperator())); + STDataValidationOperator.Enum op = XSSFDataValidation.operatorTypeMappings.get(constraint.getOperator()); + if(op != null) { + newDataValidation.setOperator(op); + } if (constraint.getFormula1() != null) { newDataValidation.setFormula1(constraint.getFormula1()); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java index a89c43bd8..35110797d 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; +import java.io.FileOutputStream; import java.math.BigDecimal; import java.util.List; @@ -239,4 +240,25 @@ public class TestXSSFDataValidation extends BaseTestDataValidation { validation.createPromptBox("Prompt", "Enter some value"); validation.setSuppressDropDownArrow(yesNo); } + + public void test53965() throws Exception { + + XSSFWorkbook wb = new XSSFWorkbook(); + XSSFSheet sheet = wb.createSheet(); + List lst = sheet.getDataValidations(); //<-- works + assertEquals(0, lst.size()); + + //create the cell that will have the validation applied + sheet.createRow(0).createCell(0); + + DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper(); + DataValidationConstraint constraint = dataValidationHelper.createCustomConstraint("SUM($A$1:$A$1) <= 3500"); + CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0); + DataValidation validation = dataValidationHelper.createValidation(constraint, addressList); + sheet.addValidationData(validation); + + // this line caused XmlValueOutOfRangeException , see Bugzilla 3965 + lst = sheet.getDataValidations(); + assertEquals(1, lst.size()); + } }