Bug 57923 - ArrayIndexOutOfBoundsException in org.apache.poi.hssf.record.NameRecord.getExternSheetNumber()
Summary: ArrayIndexOutOfBoundsException in org.apache.poi.hssf.record.NameRecord.getEx...
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.11-FINAL
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2015-05-12 11:33 UTC by GYO
Modified: 2015-06-22 09:37 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description GYO 2015-05-12 11:33:38 UTC
Hey Guys,

We have a problem with the POI API.
We want to check whether the external spreadsheet, to which a formula refers, is integrated properly. For this we call the method HSSFName.getSheetName ().

During this call, we get an ArrayIndexOutOfBoundsException. The reason is that, in this case the object Name (Konrekt HSSFName) does not refer to any formula and there is accordingly no PTGs. That's why flies here
"Ptg PTG = field_13_name_definition.getTokens () [0];" a ArrayIndexOutOfBoundsException.

Our suggestion would be as follows:

The method org.apache.poi.hssf.record.NameRecord.getExternSheetNumer () should be rewritten:

public int getExternSheetNumber(){
                Ptg[] ptgs = field_13_name_definition.getTokens();
		if (ptgs.lenght < 1) {
			return 0;
		Ptg ptg = ptgs[0];

		if (ptg.getClass() == Area3DPtg.class){
			return ((Area3DPtg) ptg).getExternSheetIndex();

		if (ptg.getClass() == Ref3DPtg.class){
			return ((Ref3DPtg) ptg).getExternSheetIndex();
		return 0;
Comment 1 Nick Burch 2015-05-12 12:08:18 UTC
Any chance you could retest with 3.12 final?
Comment 2 GYO 2015-05-13 08:06:35 UTC
The Problem still occurs in the version 3.12 Final
Comment 3 Dominik Stadler 2015-06-21 06:17:55 UTC
Can you provide a sample file and sample code which shows the Exception on HSSFName.getSheetName()
Comment 4 Dominik Stadler 2015-06-21 06:57:09 UTC
Nevermind, the following is sufficient to reproduce the problem:

        NameRecord record = new NameRecord();
        assertEquals(0, record.getExternSheetNumber());

this is fixed via r1686689 now.
Comment 5 GYO 2015-06-22 06:58:24 UTC
Is the fix also available in Version 3.11?
How can i get the actuel POI-Version with the fix?
Comment 6 Andreas Beeker 2015-06-22 09:37:54 UTC
We usually don't backport features, only for CVEs.
So you need to grab a nightly until we push the next beta or final release.
See [1] or [2] for download infos 

[1] http://poi.apache.org/download.html
[2] https://builds.apache.org/job/POI/lastSuccessfulBuild/artifact/build/dist/