Project

Profile

Help

Bug #3121

closed

NullPointerException in XQuery when defaultCollationName is not a known collation

Added by Michael Kay over 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Internals
Sprint/Milestone:
-
Start date:
2017-01-30
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.7
Fix Committed on Branch:
9.7, trunk
Fixed in Maintenance Release:
Platforms:

Description

This test case throws an NPE:

public void testCollationQuery() throws XPathException {
        Configuration config = Configuration.newConfiguration();
        config.setConfigurationProperty(FeatureKeys.GENERATE_BYTE_CODE, false);
        StaticQueryContext sqc = config.newStaticQueryContext();
        sqc.declareDefaultCollation("");
        DynamicQueryContext dqc = new DynamicQueryContext(config);
        dqc.setApplyFunctionConversionRulesToExternalVariables(false);

        String query = "declare base-uri \"/..../xmark/\";\n" +
                "let $auction := fn:doc(\"xmark1.xml\") return\n" +
                "for $i in $auction/site//item\n" +
                "where contains(string(exactly-one($i/description)), \"gold\")\n" +
                "return $i/name/text()";

        XQueryExpression xqExp = sqc.compileQuery(query);
        SequenceIterator itr = xqExp.iterator(dqc);
        Item item = itr.next();
        assertNotNull(item);
        assertNotNull(item.getStringValue());
    }

The code in CollatingFunctionFixed.setRetainedStaticContext ignores any exception from allocateCollator(), claiming "ignore the failure, it will be reported later" - but this is not the case, the function fails with an NPE at run-time if no collator has been allocated.

It's possible that the code was written on the assumption that although the default collation name isn't known at compile time, it might be known at run-time. But I don't think that logic is followed through.

However, setRetainedStaticContext() isn't defined to throw exceptions, so the fix isn't obvious.

Please register to edit this issue

Also available in: Atom PDF