Skip to content

Commit

Permalink
[bugfix] Return the correct error code from XQuery Functions that can…
Browse files Browse the repository at this point in the history
…not find the indicated Collator
  • Loading branch information
adamretter committed Jun 2, 2023
1 parent 4440873 commit 6b566e2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
33 changes: 22 additions & 11 deletions exist-core/src/main/java/org/exist/interpreter/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,11 @@
import org.exist.storage.lock.LockedDocumentMap;
import org.exist.util.hashtable.NamePool;
import org.exist.xmldb.XmldbURI;
import org.exist.xquery.AnalyzeContextInfo;
import org.exist.xquery.Expression;
import org.exist.xquery.*;
import org.exist.xquery.FunctionCall;
import org.exist.xquery.FunctionSignature;
import org.exist.xquery.LocalVariable;
import org.exist.xquery.Module;
import org.exist.xquery.Option;
import org.exist.xquery.Pragma;
import org.exist.xquery.Profiler;
import org.exist.xquery.TerminatedException;
import org.exist.xquery.UserDefinedFunction;
import org.exist.xquery.Variable;
import org.exist.xquery.XPathException;
import org.exist.xquery.XQueryContext;
import org.exist.xquery.XQueryWatchDog;
import org.exist.xquery.value.AnyURIValue;
import org.exist.xquery.value.BinaryValue;
import org.exist.xquery.value.NodeValue;
Expand Down Expand Up @@ -260,8 +250,29 @@ public interface Context {

String getDefaultCollation();

/**
* Get the Collator.
*
* @param uri The URI describing the collation and settings
*
* @return The Collator for the URI
*
* @throws XPathException if the collation is unknown.
*/
Collator getCollator(String uri) throws XPathException;

/**
* Get the Collator.
*
* @param uri The URI describing the collation and settings
* @param errorCode the error code if the URI cannot be resolved
*
* @return The Collator for the URI
*
* @throws XPathException if the collation is unknown.
*/
Collator getCollator(String uri, ErrorCodes.ErrorCode errorCode) throws XPathException;

Collator getDefaultCollator();

/**
Expand Down
7 changes: 6 additions & 1 deletion exist-core/src/main/java/org/exist/xquery/XQueryContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,11 @@ public String getDefaultCollation() {

@Override
public Collator getCollator(String uri) throws XPathException {
return getCollator(uri, ErrorCodes.XQST0076);
}

@Override
public Collator getCollator(String uri, final ErrorCodes.ErrorCode errorCode) throws XPathException {
if (uri == null) {
return defaultCollator;
}
Expand All @@ -1076,7 +1081,7 @@ public Collator getCollator(String uri) throws XPathException {
// no-op
}

return Collations.getCollationFromURI(uri, rootExpression);
return Collations.getCollationFromURI(uri, rootExpression, errorCode);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
package org.exist.xquery.functions.fn;

import com.ibm.icu.text.Collator;
import org.exist.xquery.Function;
import org.exist.xquery.FunctionSignature;
import org.exist.xquery.XPathException;
import org.exist.xquery.XQueryContext;
import org.exist.xquery.*;
import org.exist.xquery.value.Item;
import org.exist.xquery.value.Sequence;

Expand Down Expand Up @@ -53,7 +50,7 @@ protected Collator getCollator(Sequence contextSequence, Item contextItem,
if (getSignature().getArgumentCount() == arg) {
final String collationURI = getArgument(arg - 1).eval(contextSequence,
contextItem).getStringValue();
return context.getCollator(collationURI);
return context.getCollator(collationURI, ErrorCodes.FOCH0002);
} else {
return context.getDefaultCollator();
}
Expand Down

0 comments on commit 6b566e2

Please sign in to comment.