Bug 52716 - Hyperlink parser is overly strict causing document open to fail for doc which works in other tools
Summary: Hyperlink parser is overly strict causing document open to fail for doc which...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.11-FINAL
Hardware: PC All
: P2 blocker (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-20 18:38 UTC by Tom Morris
Modified: 2015-02-23 21:25 UTC (History)
1 user (show)



Attachments
Failing document (13.68 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2012-02-20 18:38 UTC, Tom Morris
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Morris 2012-02-20 18:38:29 UTC
Created attachment 28357 [details]
Failing document

The attached document fails to open in POI 3.7.  From a cursory look in the debugger where the IllegalStateException is being thrown, it looks to me like this can be safely ignored since it's an unused reference.  (As an aside, it would be much more polite to your callers to use a checked exception so they'd know it was coming and be able to handle it.)

The stack trace is:

java.lang.IllegalStateException: A sheet hyperlink must either have a location, or a relationship. Found:
<xml-fragment ref="A1" tooltip="Sort on ID" display="ID" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"/>
	at org.apache.poi.xssf.usermodel.XSSFHyperlink.<init>(XSSFHyperlink.java:72)
	at org.apache.poi.xssf.usermodel.XSSFSheet.initHyperlinks(XSSFSheet.java:205)
	at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:159)
	at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:134)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:235)
	at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:190)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:189)
Comment 1 Nick Burch 2012-02-20 18:41:53 UTC
Have you tried with POI 3.8 beta 5?
Comment 2 Tom Morris 2012-02-21 04:39:55 UTC
The behavior is the same with 3.8b5.  It doesn't look like the code has changed at all in this area.  Which bug fix did you think was in beta 5 that would improve this?
Comment 3 Tom Morris 2012-02-21 19:45:09 UTC
The user who provided the file reports that it was created in the following manner: 

"The file was created by dumping an mSQL database (by Hughes) to an HTML page using a simple table. The HTML table was dragged and dropped to Excel 2010."
Comment 4 Yegor Kozlov 2012-02-22 14:15:25 UTC
Should be fixed in r1292295, junit added.

>  (As an aside, it
> would be much more polite to your callers to use a checked exception so they'd
> know it was coming and be able to handle it.)
> 

The only checked exception that can be thrown when constructing XSSFWorkbook is IOException but it is not the case. So we stay with IllegalStateException.

Yegor
Comment 5 Tom Morris 2012-03-07 23:35:03 UTC
Thanks for the quick fix.  I verified the fix in SVN and it works great.

Is there a projected date when 3.8 will be released?  I looked at the web site and checked the dev list mail archive and wasn't able to figure out what the schedule is.

Thanks again!
Comment 6 Yegor Kozlov 2012-03-08 05:12:38 UTC
> 
> Is there a projected date when 3.8 will be released?  I looked at the web site
> and checked the dev list mail archive and wasn't able to figure out what the
> schedule is.
> 

I was planning to roll 3.8-beta6 in March and then release 3.8-final sometime in mid or late April, but there is a good chance we will skip beta6 and release 3.8-final within a month. 

Stay on poi-dev, the release date will be discussed.


Yegor
Comment 7 Vasili 2015-02-13 17:53:01 UTC
I'm reopening the bug (having the same with 3.11):

java.lang.Class - java.lang.IllegalStateException: A sheet hyperlink must either have a location, or a relationship. Found:
<xml-fragment ref="B3" display="Something" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"/>
	at org.apache.poi.xssf.usermodel.XSSFHyperlink.<init>(XSSFHyperlink.java:72)
	at org.apache.poi.xssf.usermodel.XSSFSheet.initHyperlinks(XSSFSheet.java:205)
	at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:159)
	at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:134)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:235)
	at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:190)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:182)
	at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:63)
	at org.is.jxlpoi.JXLPOIWorkbook.getWorkbook(JXLPOIWorkbook.java:80)
Comment 8 Dominik Stadler 2015-02-13 20:43:17 UTC
Please provide a sample document (unless it can be reproduced with the one attached here as well).
Comment 9 Vasili 2015-02-18 15:03:41 UTC
Yes, it is reproducable with the attached document (mfb_a.xlsx):



java.lang.IllegalStateException: A sheet hyperlink must either have a location, or a relationship. Found:
<xml-fragment ref="A1" tooltip="Sort on ID" display="ID" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"/>
	at org.apache.poi.xssf.usermodel.XSSFHyperlink.<init>(XSSFHyperlink.java:72)
	at org.apache.poi.xssf.usermodel.XSSFSheet.initHyperlinks(XSSFSheet.java:205)
	at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:159)
	at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:134)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:235)
	at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:190)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:182)
	at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:63)
Comment 10 Vasili 2015-02-18 15:14:08 UTC
I mean, with the file attached by the previous reporter, the originally submitted file.
Comment 11 Dominik Stadler 2015-02-21 11:10:09 UTC
Hm, there is an active unit-test at TestXSSFHyperlink.test52716() which verifies that this file can still be read correctly. I also tried with WorkbookFactory and it did also work fine.

Are you sure you are using the latest version of POI? If so, please share your code to see if there is any difference in how you load the workbook.
Comment 12 Vasili 2015-02-23 14:45:48 UTC
Hi Dominik,

This particular exception occurs with poi-3.11-FINAL as noted above, i.e. the latest stable version (we were not thinking to put beta to production yet and haven't tested the beta yet), not the latest version from svn.

The WorkbookFactory is used:
			
	FileInputStream fis = new FileInputStream("C:/AAA/mfb_a.xlsx");
	Workbook temp = WorkbookFactory.create(fis);

with both your file (I just double-checked it) and our file, with the same exception.

Due to this thread, I thought that this issue was fixed long before 3.11-FINAL. 

Please let me know if you want more information.

Thanks
Comment 13 Dominik Stadler 2015-02-23 21:06:30 UTC
It is fixed since somewhere around 2012 as far as I see.

So if I look at line "72" of class XSSFHyperlink which is referenced in the exception stacktrace that you posted, I see that since the fix in 2012 the line 72 is not executable code, but rather a bracket ("}"), so I conclude that if you are really seeing the same stacktrace, then you are likely still having some outdated version of POI in use somewhere, i.e. by having an old jar-file in the classpath. 

In fact the error text that is shown in the exception does not even exist any more in all of POI's code since 2012, so I cannot see how it could even appear in a current version of POI.

If you really can reproduce this problem with version 3.11 of POI, then please post the actual stacktrace that you get so we can see what the actual error message is. The "A sheet hyperlink must either ..." is very unlikely to still be possible with 3.11 and newer...
Comment 14 Vasili 2015-02-23 21:25:36 UTC
Ok, here is my fault!

I found a dependency from another imported project which used poi-3.7-20101029.jar.
you are right!

Thank you very much, at least this can be closed.