Project

Profile

Help

Bug #4535

Misleading error message when array index out of bound

Added by Norman Tovey-Walsh about 1 year ago. Updated 8 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Diagnostics
Sprint/Milestone:
-
Start date:
2020-05-01
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
10, 9.9
Fix Committed on Branch:
10, 9.9
Fixed in Maintenance Release:

Description

I'm doing some work with arrays. At one point, I got this message

Error at char 0 in expression in xsl:variable/@select on line 336 column 64 of tablecals.xsl:
  FOAY0001  Requested 1, actual size 1

That puzzled me. It took me a long time to add an xsl:message and work out that I was actually asking for item 2 in this array of length 1.

I tried to reproduce this with a very simple test and got a different message

Error FOAY0001 while evaluating xsl:message at line 14 of file:/tmp/out.xsl: Array index (2) out of range (1 to 1)

At a guess, I'd say whatever part of the code generates the former message is reporting the 0-based Java index and not the 1-based XSLT index.

In any event, if you need code to reproduce this, I'll keep a snapshot around.

History

#1 Updated by Michael Kay about 1 year ago

Noted. It seems the "good" message is coming when we do array:get() on a SimpleArrayItem, and the "bad" message is coming when we do array:get() (or put()) on an ImmutableArrayItem. These are just two different internal implementations of XDM arrays; the SimpleArrayItem is used for arrays that have not undergone any incremental modifications, while the ImmutableArrayItem is used when there have been such modifications or where we think they are likely.

#2 Updated by Michael Kay about 1 year ago

For 10.0 I have changed the approach for bounds-checking, which is currently very haphazard.

(a) the code for the specific array function (e.g array:get(), array:put()) checks the subscript before calling underlying methods on the XdmArray object

(b) the XDM array object's methods (get, put, remove) -- which use zero-based subscripts -- are declared to throw IndexOutOfBoundsException if the subscript is out of range; but this won't happen for a direct call from a function such as array:get(), because the value will already have been checked

(c) the responsibility for checking (b) rests with the implementation class, e.g. SimpleArrayItem or ImmutableArrayItem.

(d) we don't attempt to catch the IndexOutOfBoundsException because it should never happen.

For 9.9 I will make a more modest change that only affects ImmutableArrayItem.get().

#3 Updated by Michael Kay about 1 year ago

  • Subject changed from Misleading error message to Misleading error message when array index out of bound

#4 Updated by Michael Kay about 1 year ago

  • Category set to Diagnostics
  • Status changed from New to Resolved
  • Assignee set to Michael Kay
  • Priority changed from Low to Normal
  • Applies to branch 9.9 added
  • Fix Committed on Branch 10, 9.9 added

#5 Updated by Michael Kay about 1 year ago

A further patch has been committed fixing the error handling on array lookup expressions such as $A?23.

#6 Updated by O'Neil Delpratt about 1 year ago

  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 10.1 added

Bug fix committed in the Saxon 10.1 maintenance release.

#7 Updated by O'Neil Delpratt 8 months ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release 10.2, 9.9.1.8 added
  • Fixed in Maintenance Release deleted (10.1)

Bug fix applied on the Saxon 9.9.1.8 maintenance release.

Please register to edit this issue

Also available in: Atom PDF