]> source.dussan.org Git - poi.git/commitdiff
Fix bug #50718 - More helpful error message when you try to create a CellReference...
authorNick Burch <nick@apache.org>
Fri, 4 Mar 2011 16:17:21 +0000 (16:17 +0000)
committerNick Burch <nick@apache.org>
Fri, 4 Mar 2011 16:17:21 +0000 (16:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1078039 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/ss/util/CellReference.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java
src/testcases/org/apache/poi/ss/util/TestCellReference.java

index 8ddac5f12e0f3b98a5c97719e35c4a294b24f06c..8ef8414dbbadb41b03f516e37672a1a1e2565838 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta2" date="2011-??-??">
+           <action dev="poi-developers" type="fix">50718 - More helpful error message when you try to create a CellReference with #REF!</action>
            <action dev="poi-developers" type="fix">50784 - XSSFColors return by XSSFFont now have theme information applied to them</action>
            <action dev="poi-developers" type="fix">50846 - Improve how XSSFColor inherits from Themes</action>
            <action dev="poi-developers" type="fix">50847 - XSSFFont now accepts the full range of Charsets from FontChartset</action>
index 67f8fa0b1510c126e33de0d6cefd8a00d2aae0c8..12120b748987a96fb33b74d552704b20d2531fd4 100644 (file)
@@ -85,6 +85,10 @@ public class CellReference {
         * delimited and escaped as per normal syntax rules for formulas.
         */
        public CellReference(String cellRef) {
+      if(cellRef.endsWith("#REF!")) {
+         throw new IllegalArgumentException("Cell reference invalid: " + cellRef);
+      }
+
                String[] parts = separateRefParts(cellRef);
                _sheetName = parts[0];
                String colRef = parts[1];
@@ -335,7 +339,6 @@ public class CellReference {
         * name still in ALPHA-26 number format.  The third element is the row.
         */
        private static String[] separateRefParts(String reference) {
-
                int plingPos = reference.lastIndexOf(SHEET_NAME_DELIMITER);
                String sheetName = parseSheetName(reference, plingPos);
                int start = plingPos+1;
index 45da3e7e9cb62fa35895add465b614b988388eab..3a61f3cd3ff5b25d49208541b67a6cf393c6a3fc 100644 (file)
@@ -231,7 +231,7 @@ public final class TestHSSFName extends BaseTestNamedRange {
         try {
             new AreaReference(name2.getRefersToFormula());
             fail("attempt to supply an invalid reference to AreaReference constructor results in exception");
-        } catch (StringIndexOutOfBoundsException e) { // TODO - use a different exception for this condition
+        } catch (IllegalArgumentException e) { // TODO - use a stronger typed exception for this condition
             // expected during successful test
         }
     }
index 4c86c0f7408cca6b2469fa796be67af688f35697..c6ad609c54b37e96ac0a25d9267276f0189529c1 100644 (file)
@@ -192,6 +192,23 @@ public final class TestCellReference extends TestCase {
                confirmCrInRange(false, "A", "0", v97);
                confirmCrInRange(false, "A", "0", v2007);
        }
+       
+       public void testInvalidReference() {
+      try {
+         new CellReference("Sheet1!#REF!");
+         fail("Shouldn't be able to create a #REF! refence");
+      } catch(IllegalArgumentException e) {}
+      
+          try {
+             new CellReference("'MySheetName'!#REF!");
+             fail("Shouldn't be able to create a #REF! refence");
+          } catch(IllegalArgumentException e) {}
+          
+          try {
+             new CellReference("#REF!");
+             fail("Shouldn't be able to create a #REF! refence");
+          } catch(IllegalArgumentException e) {}
+       }
 
        private static void confirmCrInRange(boolean expResult, String colStr, String rowStr,
                        SpreadsheetVersion sv) {