Return-Path: Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: (qmail 33874 invoked from network); 4 Mar 2011 16:17:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Mar 2011 16:17:46 -0000 Received: (qmail 72719 invoked by uid 500); 4 Mar 2011 16:17:46 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 72688 invoked by uid 500); 4 Mar 2011 16:17:46 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 72681 invoked by uid 99); 4 Mar 2011 16:17:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Mar 2011 16:17:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Mar 2011 16:17:43 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4329323888CF; Fri, 4 Mar 2011 16:17:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1078039 - in /poi/trunk/src: documentation/content/xdocs/status.xml java/org/apache/poi/ss/util/CellReference.java testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java testcases/org/apache/poi/ss/util/TestCellReference.java Date: Fri, 04 Mar 2011 16:17:22 -0000 To: commits@poi.apache.org From: nick@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110304161722.4329323888CF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: nick Date: Fri Mar 4 16:17:21 2011 New Revision: 1078039 URL: http://svn.apache.org/viewvc?rev=1078039&view=rev Log: Fix bug #50718 - More helpful error message when you try to create a CellReference with #REF! Modified: poi/trunk/src/documentation/content/xdocs/status.xml poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java Modified: poi/trunk/src/documentation/content/xdocs/status.xml URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1078039&r1=1078038&r2=1078039&view=diff ============================================================================== --- poi/trunk/src/documentation/content/xdocs/status.xml (original) +++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Mar 4 16:17:21 2011 @@ -34,6 +34,7 @@ + 50718 - More helpful error message when you try to create a CellReference with #REF! 50784 - XSSFColors return by XSSFFont now have theme information applied to them 50846 - Improve how XSSFColor inherits from Themes 50847 - XSSFFont now accepts the full range of Charsets from FontChartset Modified: poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java?rev=1078039&r1=1078038&r2=1078039&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java (original) +++ poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java Fri Mar 4 16:17:21 2011 @@ -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; Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java?rev=1078039&r1=1078038&r2=1078039&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java (original) +++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java Fri Mar 4 16:17:21 2011 @@ -231,7 +231,7 @@ public final class TestHSSFName extends 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 } } Modified: poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java?rev=1078039&r1=1078038&r2=1078039&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java (original) +++ poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java Fri Mar 4 16:17:21 2011 @@ -192,6 +192,23 @@ public final class TestCellReference ext 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) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org