Bug 53282 - Hyperlink with a non-breaking space throws java.lang.IllegalStateException: The hyperlink for cell A2 references relation rId2, but that didn't exist!
Summary: Hyperlink with a non-breaking space throws java.lang.IllegalStateException: T...
Status: REOPENED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.8-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-23 21:13 UTC by lakshmi
Modified: 2016-07-28 06:23 UTC (History)
5 users (show)



Attachments
Excel file containing the hyperlink with a non-breaking space (37 bytes, text/plain)
2012-05-23 21:24 UTC, lakshmi
Details
Excel file with a non-breaking space hyperlink (10.77 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2012-05-24 16:25 UTC, lakshmi
Details
Excel sample with hyperlinks (8.49 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2013-06-04 09:59 UTC, Siva Kovvuri
Details
Excel file containing invalid hyperlink (9.10 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2013-08-07 02:51 UTC, kayulai2
Details
hyperlink error (53.89 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2015-02-13 03:36 UTC, ameetchaubal
Details

Note You need to log in before you can comment on or make changes to this bug.
Description lakshmi 2012-05-23 21:13:23 UTC
I sent this query to the POI mailing list couple of days back and was advised to open a bug here.

I tested hyperlinks with Apache POI (3.8 version) and it throws java.lang.IllegalStateException: The hyperlink for cell A2 references relation rId2, but that didn't exist!
for hyperlinks with non-breaking spaces. The non-breaking space in an hyperlink relation is not a valid java URI. These invalid characters should also be encoded for valid URI. Looks like the issue with white space in target URI was fixed in r1036215. 

When trying to convert such hyperlink to URI, a URISyntaxException is thrown.

Please find the attachment of the excel file including the hyperlink with a non-breaking space. 

Below is the sample java code to demonstrate the issue.

import java.io.FileInputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

public class DemonstrateHyperlinkIssue {
	
	public static Workbook getCell(String fileName) throws Exception{
		
		FileInputStream input = null;
		Workbook excelDoc = null;
		
		try {
			input = new FileInputStream(fileName);
			excelDoc = WorkbookFactory.create(input);
			input.close();
		}
		catch(IOException e)
		{
			throw e;
		}
		finally
		{
			if (input != null) {
				input.close();
			}
		}
		
		return excelDoc;
	}

	public static void main(String [] args) {
		try {
			Workbook wb = getCell("C:\\pathToFile\\test.xlsx");
			System.out.println(wb);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
Comment 1 lakshmi 2012-05-23 21:24:02 UTC
Created attachment 28827 [details]
Excel file containing the hyperlink with a non-breaking space
Comment 2 lakshmi 2012-05-23 21:27:39 UTC
Comment on attachment 28827 [details]
Excel file containing the hyperlink with a non-breaking space

please ignore this attachment.
Comment 3 lakshmi 2012-05-23 21:29:59 UTC
Unable to attach the excel file.

To reproduce the error, copy/paste the below in an excel file

nobody@nowhere.uk 
nobody@nowhere.com
Comment 4 Yegor Kozlov 2012-05-24 08:28:06 UTC
I can't reproduce it. 
Please try again to attach a sample file with a nbsp . 

Yegor

(In reply to comment #3)
> Unable to attach the excel file.
> 
> To reproduce the error, copy/paste the below in an excel file
> 
> nobody@nowhere.uk 
> nobody@nowhere.com
Comment 5 lakshmi 2012-05-24 16:25:39 UTC
Created attachment 28830 [details]
Excel file with a non-breaking space hyperlink
Comment 6 Yegor Kozlov 2012-10-29 08:44:24 UTC
Fixed in r1403195. I included your sample in our collection of test files.

Yegor
Comment 7 Siva Kovvuri 2013-06-04 09:59:13 UTC
Created attachment 30385 [details]
Excel sample with hyperlinks

Excel sample with hyperlinks
Comment 8 Siva Kovvuri 2013-06-04 10:00:43 UTC
We have tried with version 3.9 and 3.10 beta. Seems still issue is there. Attached a sample file the japanese hyperlink with a space.
Comment 9 Nick Burch 2013-06-12 15:33:58 UTC
Are you able to produce a unit test, similar to the one Yegor did for r1403195, which shows how the problem still remains? That will help us track down what's still incorrect.
Comment 10 kayulai2 2013-08-07 02:51:38 UTC
Created attachment 30683 [details]
Excel file containing invalid hyperlink
Comment 11 kayulai2 2013-08-07 02:53:48 UTC
Comment on attachment 30683 [details]
Excel file containing invalid hyperlink

This file contain a invalid email address hyperlink which can reproduce the probelm.
Comment 12 Andreas Beeker 2014-02-02 02:01:19 UTC
Fixed by svn rev r1563540.

Although the last sample file containing the invalid hyperlink seems to be a bit hypothetical, I think it's better to receive/return an invalid-url, in case such a malformed uri is really generated, opposed to throwing an IllegalStateException
Comment 13 Peng 2014-07-03 12:34:43 UTC
It seems that the bug still exists in 3.10 final.
I got a file from a customer where value like "xxx@company.com; 
 TEL: +001-123-456789" is given as email address hyperlink in it. Try to import this file a IllegalStateException is thrown at the beginning and there is no way to correct the value afterwards in program.
Comment 14 Debashis 2014-12-11 18:49:13 UTC
I have been facing the same issue as well and I am using POI 3.10.1.
The excel that I have has autogenerated hyperlinks and some of them have spaces in the hyperlink.
Comment 15 ameetchaubal 2015-02-13 03:36:46 UTC
Created attachment 32471 [details]
hyperlink error

I am getting a similar error on workbook.cloneSheet
The hyperlink for cell O2 references relation rId1, but that didn't exist!