Skip to content

Commit d42dbf6

Browse files
committed
[bugfix] Correct the XPath Error Code for array:get
1 parent 852fe9a commit d42dbf6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/org/exist/xquery/functions/array/ArrayType.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ public Sequence get(int n) {
6868
}
6969

7070
@Override
71-
public Sequence get(AtomicValue key) throws XPathException {
71+
public Sequence get(final AtomicValue key) throws XPathException {
7272
if (!Type.subTypeOf(key.getType(), Type.INTEGER)) {
73-
throw new XPathException(ErrorCodes.XPTY0004, "position argument for array lookup must be a positive integer");
73+
throw new XPathException(ErrorCodes.XPTY0004, "Position argument for array lookup must be a positive integer");
7474
}
7575
final int pos = ((IntegerValue)key).getInt();
7676
if (pos <= 0 || pos > getSize()) {
77-
throw new XPathException(ErrorCodes.XPTY0004, "position argument for array lookup must be > 0 and < array:size");
77+
final String startIdx = vector.length() == 0 ? "0" : "1";
78+
final String endIdx = String.valueOf(vector.length());
79+
throw new XPathException(ErrorCodes.FOAY0001, "Array index " + pos + " out of bounds (" + startIdx + ".." + endIdx + ")");
7880
}
7981
return get(pos - 1);
8082
}

0 commit comments

Comments
 (0)