diff options
author | Dominik Stadler <centic@apache.org> | 2021-09-10 06:15:30 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2021-09-10 06:15:30 +0000 |
commit | 0739e608a86a889f9c7c8c4eaf2ac9b68fe8bbeb (patch) | |
tree | 1fb1e9a67e27dadd4ff589d029586aabc184da63 /poi-ooxml | |
parent | 3e7672d8562a31c285a1ff6344491787e1aacb88 (diff) | |
download | poi-0739e608a86a889f9c7c8c4eaf2ac9b68fe8bbeb.tar.gz poi-0739e608a86a889f9c7c8c4eaf2ac9b68fe8bbeb.zip |
Improve error messages when charting data is not valid
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1893212 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java | 3 | ||||
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSourcesFactory.java | 24 |
2 files changed, 16 insertions, 11 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java index 9bdbe5ab28..e93cd01e1d 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java @@ -166,7 +166,8 @@ public abstract class XDDFChartData { if (categoryData != null && values != null) { int numOfPoints = category.getPointCount(); if (numOfPoints != values.getPointCount()) { - throw new IllegalStateException("Category and values must have the same point count."); + throw new IllegalStateException("Category and values must have the same point count, but had " + + numOfPoints + " categories and " + values.getPointCount() + " values."); } } this.categoryData = category; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSourcesFactory.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSourcesFactory.java index 4cd3bc876f..db5dda65b3 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSourcesFactory.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSourcesFactory.java @@ -47,8 +47,8 @@ public class XDDFDataSourcesFactory { } if (categoryDS.getNumRef() != null && categoryDS.getNumRef().getNumCache() != null) { return new XDDFCategoryDataSource() { - private CTNumData category = (CTNumData) categoryDS.getNumRef().getNumCache().copy(); - private String formatCode = category.isSetFormatCode() ? category.getFormatCode() : null; + private final CTNumData category = (CTNumData) categoryDS.getNumRef().getNumCache().copy(); + private final String formatCode = category.isSetFormatCode() ? category.getFormatCode() : null; @Override public boolean isCellRange() { @@ -72,6 +72,10 @@ public class XDDFDataSourcesFactory { @Override public String getPointAt(int index) { + if (category.getPtArray().length <= index) { + throw new IllegalArgumentException("Cannot access 0-based index " + index + + " in point-array with " + category.getPtArray().length + " items"); + } return category.getPtArray(index).getV(); } @@ -80,7 +84,7 @@ public class XDDFDataSourcesFactory { }; } else if (categoryDS.getStrRef() != null && categoryDS.getStrRef().getStrCache() != null) { return new XDDFCategoryDataSource() { - private CTStrData category = (CTStrData) categoryDS.getStrRef().getStrCache().copy(); + private final CTStrData category = (CTStrData) categoryDS.getStrRef().getStrCache().copy(); @Override public boolean isCellRange() { @@ -107,8 +111,8 @@ public class XDDFDataSourcesFactory { }; } else if (categoryDS.getNumLit() != null) { return new XDDFCategoryDataSource() { - private CTNumData category = (CTNumData) categoryDS.getNumLit().copy(); - private String formatCode = category.isSetFormatCode() ? category.getFormatCode() : null; + private final CTNumData category = (CTNumData) categoryDS.getNumLit().copy(); + private final String formatCode = category.isSetFormatCode() ? category.getFormatCode() : null; @Override public boolean isCellRange() { @@ -150,7 +154,7 @@ public class XDDFDataSourcesFactory { }; } else if (categoryDS.getStrLit() != null) { return new XDDFCategoryDataSource() { - private CTStrData category = (CTStrData) categoryDS.getStrLit().copy(); + private final CTStrData category = (CTStrData) categoryDS.getStrLit().copy(); @Override public boolean isCellRange() { @@ -196,7 +200,7 @@ public class XDDFDataSourcesFactory { } if (valuesDS.getNumRef() != null && valuesDS.getNumRef().getNumCache() != null) { return new XDDFNumericalDataSource<Double>() { - private CTNumData values = (CTNumData) valuesDS.getNumRef().getNumCache().copy(); + private final CTNumData values = (CTNumData) valuesDS.getNumRef().getNumCache().copy(); private String formatCode = values.isSetFormatCode() ? values.getFormatCode() : null; @Override @@ -246,7 +250,7 @@ public class XDDFDataSourcesFactory { }; } else if (valuesDS.getNumLit() != null) { return new XDDFNumericalDataSource<Double>() { - private CTNumData values = (CTNumData) valuesDS.getNumLit().copy(); + private final CTNumData values = (CTNumData) valuesDS.getNumLit().copy(); private String formatCode = values.isSetFormatCode() ? values.getFormatCode() : null; @Override @@ -457,7 +461,7 @@ public class XDDFDataSourcesFactory { private final XSSFSheet sheet; private final CellRangeAddress cellRangeAddress; private final int numOfCells; - private XSSFFormulaEvaluator evaluator; + private final XSSFFormulaEvaluator evaluator; protected AbstractCellRangeDataSource(XSSFSheet sheet, CellRangeAddress cellRangeAddress) { this.sheet = sheet; @@ -530,7 +534,7 @@ public class XDDFDataSourcesFactory { public Double getPointAt(int index) { CellValue cellValue = getCellValueAt(index); if (cellValue != null && cellValue.getCellType() == CellType.NUMERIC) { - return Double.valueOf(cellValue.getNumberValue()); + return cellValue.getNumberValue(); } else { return null; } |