Bug 48284 - [PATCH] Raised visibility of FormulaParseException to catch it outside the POI internal.
Summary: [PATCH] Raised visibility of FormulaParseException to catch it outside the PO...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: unspecified
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-25 07:55 UTC by Petr.Udalau
Modified: 2009-11-30 16:17 UTC (History)
0 users



Attachments
Fix. (708 bytes, text/plain)
2009-11-25 07:55 UTC, Petr.Udalau
Details
Revised patch making FormulaParseException a public top-level type (36.44 KB, text/plain)
2009-11-25 17:21 UTC, Josh Micich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Petr.Udalau 2009-11-25 07:55:12 UTC
Created attachment 24614 [details]
Fix.

There is simple example when we set wrong formula and get FormulaParseException.

public class Test {
    public static void main(String[] args) throws Exception{
        HSSFWorkbook wb = new HSSFWorkbook();
        Sheet sheet = wb.createSheet();
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellFormula("Sasd(1)");
    }
}

But we cant catch it because its visibility is package. We can't catch this exception outside the POI internal.

Visibility is raised in patch.
Comment 1 Nick Burch 2009-11-25 09:19:59 UTC
There's a comment on the exception:

	// This class was given package scope until it would become clear that it is useful to
	// general client code.

Probably one for Josh to comment on?
Comment 2 Josh Micich 2009-11-25 17:21:12 UTC
Created attachment 24621 [details]
Revised patch making FormulaParseException a public top-level type

I originally added this exception quite some time back in the patch of bug 44504.  The purpose of the exception is to tell the difference between internal POI errors and parsing errors caused by a bad user-supplied formula.  I deliberately restricted visibility for two reasons - firstly because I didn't want to augment POI's public API and secondly because I wasn't confident that the formula parser did a good job of recognising formula errors yet.

Having said that, I think the formula parser has improved greatly since then (almost thirty bugs fixed and more than a dozen additional enhancements) so it is probably more reliable in throwing FormulaParseException correctly now.

As far as the API is concerned, I'd like to make this class a top level class perhaps:
org.apache.poi.ss.formula.FormulaParseException
It should be OK to make this change since no-one has been able to specifically catch this exception so far.

I see in your patch you left the the exception unchecked (which I agree with).  I'm also considering declaring this exception on Cell.setCellFormula() for clarity.  It's slightly unusual to have declared unchecked exceptions but that seems like the best approach here.


The attached patch file includes the changes described here and some related clean-up.  Let me know if you think it needs further changes.  Otherwise I'll apply it over the weekend.
Comment 3 Petr.Udalau 2009-11-26 01:44:03 UTC
Your patch completely resolves the problem.

Thanks.
Comment 4 Josh Micich 2009-11-30 16:17:27 UTC
Applied in svn r885007.