Bug 64750: Do not use CTDataValidations.getCount(), instead only rely on getDataValidationArray

Field "count" seems to be optional according
to the schema, so by using only the array
Apache POI can read data validations from
workbooks that do not populate the
"count" field properly.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1885011 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2021-01-01 15:51:19 +00:00
parent e4b70720be
commit 685af351d1
3 changed files with 10 additions and 2 deletions

View File

@ -80,7 +80,6 @@ import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal; import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
import org.apache.poi.util.Removal;
import org.apache.poi.util.Units; import org.apache.poi.util.Units;
import org.apache.poi.xssf.model.CommentsTable; import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.usermodel.XSSFPivotTable.PivotTableReferenceConfigurator; import org.apache.poi.xssf.usermodel.XSSFPivotTable.PivotTableReferenceConfigurator;
@ -4011,7 +4010,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
public List<XSSFDataValidation> getDataValidations() { public List<XSSFDataValidation> getDataValidations() {
List<XSSFDataValidation> xssfValidations = new ArrayList<>(); List<XSSFDataValidation> xssfValidations = new ArrayList<>();
CTDataValidations dataValidations = this.worksheet.getDataValidations(); CTDataValidations dataValidations = this.worksheet.getDataValidations();
if( dataValidations!=null && dataValidations.getCount() > 0 ) { if (dataValidations != null) {
for (CTDataValidation ctDataValidation : dataValidations.getDataValidationArray()) { for (CTDataValidation ctDataValidation : dataValidations.getDataValidationArray()) {
CellRangeAddressList addressList = new CellRangeAddressList(); CellRangeAddressList addressList = new CellRangeAddressList();
@ -4031,6 +4030,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
xssfValidations.add(xssfDataValidation); xssfValidations.add(xssfDataValidation);
} }
} }
return xssfValidations; return xssfValidations;
} }

View File

@ -3661,4 +3661,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals(CellType.NUMERIC, value.getCellType()); assertEquals(CellType.NUMERIC, value.getCellType());
assertEquals(1, value.getNumberValue(), 0.01); assertEquals(1, value.getNumberValue(), 0.01);
} }
@Test
public void test64750() throws IOException {
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("64750.xlsx")) {
Sheet sheet = wb.getSheet("Sheet1");
assertEquals(1, sheet.getDataValidations().size());
}
}
} }

Binary file not shown.