NPE in FuncRef.has(): missing null guard causes crash when imported function is used in .[] step's and-predicate (since 12.2)

Wednesday, 3 June 2026 · 3 messages
AN
Andreas Hengsbach | nexoma3 Jun 2026 13:43 #
Hi everyone, I found a bug and used AI to narrow it down to the smallest possible reproducer. I hope this helps. ### schnipp (: Reproducer for BaseX bug: NPE in Single.has() via Step.get() Affected versions: 12.2, 12.3, 12.4 Not affected: 12.0, 12.1 Required conditions (all three necessary): 1. .[] step — Path.get() converts Filter(ContextValue, preds) to Step.get(SELF, preds) 2. compound `and` predicate — creates an Arr containing the FuncRef 3. imported module function as an operand — unresolved at parse time -> FuncRef(expr=null) FuncRef extends Single but has no has() override -> Single.has() NPEs on null expr
   Fix: add has() override to FuncRef inner class in StaticFuncs.java (analogous to accept()):
     @Override
     public boolean has(final Flag... flags) {
       return expr != null && expr.has(flags);
     }
:)
import module namespace functx = "http://www.functx.com";

<a/>/.[true() and functx:all-whitespace('')]
### schnapp Best regards, Andreas
GR
Gunther Rademacher3 Jun 2026 17:18 #
Hi Andreas, thank you for the concise reproduction. A fix is now available via PR 2687 [1], it takes a slightly different approach than you suggested. Please allow some time for further processing of the PR. Best regards, Gunther [1] https://github.com/BaseXdb/basex/pull/2687 Gesendet: Mittwoch, 3. Juni 2026 um 13:43
Quoted text · Andreas Hengsbach | nexoma · 26 lines
Von: "Andreas Hengsbach | nexoma via BaseX-Talk" <basex-talk at mailman.uni-konstanz.de> An: "BaseX Mailinglist" <basex-talk at mailman.uni-konstanz.de> Betreff: [basex-talk] NPE in FuncRef.has(): missing null guard causes crash when imported function is used in .[] step's and-predicate (since 12.2) Hi everyone, I found a bug and used AI to narrow it down to the smallest possible reproducer. I hope this helps. ### schnipp (: Reproducer for BaseX bug: NPE in Single.has() via Step.get() Affected versions: 12.2, 12.3, 12.4 Not affected: 12.0, 12.1 Required conditions (all three necessary): 1. .[] step — Path.get() converts Filter(ContextValue, preds) to Step.get(SELF, preds) 2. compound `and` predicate — creates an Arr containing the FuncRef 3. imported module function as an operand — unresolved at parse time -> FuncRef(expr=null) FuncRef extends Single but has no has() override -> Single.has() NPEs on null expr Fix: add has() override to FuncRef inner class in StaticFuncs.java (analogous to accept()): @Override public boolean has(final Flag... flags) { return expr != null && expr.has(flags); } :) import module namespace functx = "http://www.functx.com"; <a/>/.[true() and functx:all-whitespace('')] ### schnapp Best regards, Andreas
AN
Andreas Hengsbach | nexoma3 Jun 2026 18:23 #
Hi Gunther,
Quoted text · Gunther Rademacher · 1 line
> it takes a slightly different approach than you suggested.
"My" approach also comes entirely from AI. But it convinced me, so I left it in the bug report. 😉 Thank you for the quick fix. Best regards, Andreas

⚡Generated with XQuery