Bug 50718

Summary: New CellReference created from damaged Name throws misleading "Mismatched quotes" Runtime Ex
Product: POI Reporter: Carl Pritchett <carl.pritchett>
Component: POI OverallAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.7-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Carl Pritchett 2011-02-03 22:37:17 UTC
Creating a CellReference from a Name's "refers to formula" when that named range has been half deleted throws a misleading exception:

"java.lang.RuntimeException: Mismatched quotes: ('MySheetName'!#REF!)"

If a Name has been half deleted (e.g. one row out of the two the Name refers to is deleted) then the method Name.getRefersToFormula() will return something like:

'MySheetName'!#REF!

When creating a CellReference from this string the org.apache.poi.ss.util.CellReference.parseSheetName(CellReference.java:376) method will fail as it does not expect the string to contain two "!" characters.

The CellReference is created as follows:

AreaReference aref = new AreaReference(namedRange.getRefersToFormula());

The exception is misleading as the real error is that the "refers to formula" (the "reference" param in the parseSheetName() method) is really invalid. Both quotes are present thus the error "Mismatched quotes" is not correct.


The relevant stack trace is:

java.lang.RuntimeException: Mismatched quotes: ('MySheetTitle'!#REF!)
	at org.apache.poi.ss.util.CellReference.parseSheetName(CellReference.java:376)
	at org.apache.poi.ss.util.CellReference.separateRefParts(CellReference.java:340)
	at org.apache.poi.ss.util.CellReference.<init>(CellReference.java:88)
	at org.apache.poi.ss.util.AreaReference.<init>(AreaReference.java:55)
	at org.apache.poi.hssf.util.AreaReference.<init>(AreaReference.java:28)
Comment 1 Nick Burch 2011-03-04 11:18:06 UTC
Fixed in r1078039 - now gives a more helpful:
  IllegalArgumentException - Cell reference invalid: Sheet1!#REF!