Repository navigation
fix(#5798): Cypher string functions reject non-STRING arguments - #5901
Conversation
toUpper(), toLower(), trim()/btrim(), lTrim(), rTrim(), split() and replace() declare a STRING input domain but implemented it by calling Object.toString() on the argument, silently converting any value - INTEGER, BOOLEAN, LIST<ANY>, ... - into text instead of rejecting it. This made toUpper(5) observationally identical to the explicit conversion toUpper(toString(5)), hiding invalid type usage as a "successful" result. Add CypherFunctionHelper.requireStringArgument(), mirroring the existing requireNumberArgument/requireListArgument helpers, and use it in the runtime executors for all seven functions. Extend the parse-time static check in CypherSemanticValidator so a statically known non-STRING literal is rejected before the query runs too, matching the existing #5484/#5477/#5476 precedent for other type-domain violations.
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 17 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
ReviewNice, well-documented fix with strong test coverage for the primary scenarios. I traced through all seven touched executors against the parse-time validator and found one correctness gap worth addressing before merge. Bug: the new type check can be silently bypassed when a secondary argument is
|
replace(), split(), and the 2-argument forms of lTrim()/rTrim()/trim()/ btrim() checked every argument for null before calling requireStringArgument() on the primary one, so an out-of-domain primary argument (e.g. replace(5, null, 'b')) silently returned null instead of raising the type error whenever a secondary argument was also null. Reorder so the primary argument is type-checked first, matching the #5484 convention already used by MathBinaryFunction/RoundFunction. Adds a regression test covering the gap for all five affected call sites.
|
Review Went through the diff and read the final state of all touched files (CypherFunctionHelper, the seven function executors, CypherSemanticValidator, and the new test class). Overall this is a well-scoped, well-tested fix that follows the established pattern from issues 5484/5476/5477 closely. Strengths
Minor observations (not blocking)
Test coverage CypherStringFunctionArgumentIssue5798Test is thorough: happy path for all seven functions, null propagation, the explicit toString() escape hatch, the parse-time literal check (including the "no row matches" case mirroring Neo4j), the runtime property-read path, and the primary-vs-secondary null ordering gap fixed in the second commit. One optional addition: a case exercising the alias spellings themselves (upper(5), lower(5), ltrim(5)) directly, since canonicalStringFunctionName's alias mapping is currently only exercised implicitly through toUpper/toLower. No security or performance concerns: the added checks are cheap instanceof tests on the hot path, consistent with the numeric-family precedent, and the error path throws rather than allocating anything expensive. |
Covers upper(), lower(), ltrim() and rtrim() rejecting a non-STRING argument directly, exercising canonicalStringFunctionName()'s alias mapping rather than only its canonical spelling.
ReviewSolid, well-scoped fix. Correctness
Minor / non-blocking observations
Style / process
I reviewed this statically (diff + surrounding code) rather than running the build in this sandbox, so I couldn't independently reproduce the 14/14 pass and full-package regression numbers reported in the PR description, but the logic checks out from a manual trace of every modified call site. |
Adds a regression test for trim(BOTH/LEADING/TRAILING char FROM string) rejecting a non-STRING source, exercising the code path directly modified in the first commit (CypherTrimFunction's args.length == 3 branch) that had no dedicated test. Also updates the PR description with a breaking-change note and a left()/right() follow-up mention, per review feedback.
Review: fix(#5798) - Cypher string functions reject non-STRING argumentsWent through the diff ( OverallSolid, well-scoped fix that follows the established Correctness
Minor / non-blocking observations
Test coverageVery thorough: covers all seven functions, both the parse-time literal path and the runtime (property-read) path, null propagation, explicit Security / performanceNo concerns. Nice work - this closes the gap cleanly and consistently with the established pattern for the numeric and list function families. |
CypherTrimFunction's 3-arg branch collapses the redundant explicit args[2] == null check into requireStringArgument()'s own null handling, matching the style already used by the 1-arg/2-arg branches. No behavior change. Also corrects the tracking doc's stale "14/14 pass" test count (the class grew to 17 tests across review cycles 2-3).
ReviewWent through the diff, the new test class, and the affected call sites ( Overall: this is a clean, well-scoped fix. It correctly mirrors the established Things I checked and confirmed correct
Minor, non-blocking observation
// A literal holding a collection is a LIST, which every function handled below accepts.
if (literal instanceof Collection || (literal != null && literal.getClass().isArray()))
return;That comment is no longer accurate now that STRING-only functions ( Test coverageThe new Style / conventions
Nice, incremental piece of work — consistent with the precedent set by #5484/#5476/#5477, and the multiple review cycles already reflected in the tracking doc show the null-ordering bug and the missing 3-arg-trim/alias test coverage were caught and fixed along the way. No blocking issues from my pass. |
|
Review Clean, well-scoped fix that closes #5798 consistently with the precedent set by #5484/#5476/#5477. Went through the diff (7 functions + validator + helper + new test class) and the existing Correctness
Minor gap (non-blocking) will not be rejected at parse time (unlike Test coverage Other notes
No blocking issues. Nice work. |
Bumps `junit.jupiter.version` from 6.1.2 to 6.1.3. Updates `org.junit:junit-bom` from 6.1.2 to 6.1.3 Release notes *Sourced from [org.junit:junit-bom's releases](https://github.com/junit-team/junit-framework/releases).* > JUnit 6.1.3 = Platform 6.1.3 + Jupiter 6.1.3 + Vintage 6.1.3 > > See [Release Notes](https://docs.junit.org/6.1.3/release-notes.html). > > **Full Changelog**: <junit-team/junit-framework@r6.1.2...r6.1.3> Commits * [`f59f60d`](junit-team/junit-framework@f59f60d) Release 6.1.3 * [`cd8ec92`](junit-team/junit-framework@cd8ec92) Finalize 6.1.3 release notes * [`c8729f2`](junit-team/junit-framework@c8729f2) Restore compatibility with GraalVM 25 ([#5901](https://redirect.github.com/junit-team/junit-framework/issues/5901)) * [`ddc9e74`](junit-team/junit-framework@ddc9e74) Update graalvm/setup-graalvm action to v1.6.4 ([#5959](https://redirect.github.com/junit-team/junit-framework/issues/5959)) * [`fe2c52a`](junit-team/junit-framework@fe2c52a) Update plugin org.graalvm.buildtools.native to v1.1.7 ([#5923](https://redirect.github.com/junit-team/junit-framework/issues/5923)) * [`62afc02`](junit-team/junit-framework@62afc02) Delay GraalVM plugin updates for 3 days * [`0cc2902`](junit-team/junit-framework@0cc2902) Skip `graalVmTest` task if GraalVM env vars are not set * [`f6bbfc5`](junit-team/junit-framework@f6bbfc5) Move GraalVM tests to separate test task ([#5903](https://redirect.github.com/junit-team/junit-framework/issues/5903)) * [`e87e052`](junit-team/junit-framework@e87e052) Update plugin org.graalvm.buildtools.native to v1.1.6 ([#5899](https://redirect.github.com/junit-team/junit-framework/issues/5899)) * [`1cd56df`](junit-team/junit-framework@1cd56df) Update plugin org.graalvm.buildtools.native to v1.1.5 ([#5880](https://redirect.github.com/junit-team/junit-framework/issues/5880)) * Additional commits viewable in [compare view](junit-team/junit-framework@r6.1.2...r6.1.3) Updates `org.junit.jupiter:junit-jupiter` from 6.1.2 to 6.1.3 Release notes *Sourced from [org.junit.jupiter:junit-jupiter's releases](https://github.com/junit-team/junit-framework/releases).* > JUnit 6.1.3 = Platform 6.1.3 + Jupiter 6.1.3 + Vintage 6.1.3 > > See [Release Notes](https://docs.junit.org/6.1.3/release-notes.html). > > **Full Changelog**: <junit-team/junit-framework@r6.1.2...r6.1.3> Commits * [`f59f60d`](junit-team/junit-framework@f59f60d) Release 6.1.3 * [`cd8ec92`](junit-team/junit-framework@cd8ec92) Finalize 6.1.3 release notes * [`c8729f2`](junit-team/junit-framework@c8729f2) Restore compatibility with GraalVM 25 ([#5901](https://redirect.github.com/junit-team/junit-framework/issues/5901)) * [`ddc9e74`](junit-team/junit-framework@ddc9e74) Update graalvm/setup-graalvm action to v1.6.4 ([#5959](https://redirect.github.com/junit-team/junit-framework/issues/5959)) * [`fe2c52a`](junit-team/junit-framework@fe2c52a) Update plugin org.graalvm.buildtools.native to v1.1.7 ([#5923](https://redirect.github.com/junit-team/junit-framework/issues/5923)) * [`62afc02`](junit-team/junit-framework@62afc02) Delay GraalVM plugin updates for 3 days * [`0cc2902`](junit-team/junit-framework@0cc2902) Skip `graalVmTest` task if GraalVM env vars are not set * [`f6bbfc5`](junit-team/junit-framework@f6bbfc5) Move GraalVM tests to separate test task ([#5903](https://redirect.github.com/junit-team/junit-framework/issues/5903)) * [`e87e052`](junit-team/junit-framework@e87e052) Update plugin org.graalvm.buildtools.native to v1.1.6 ([#5899](https://redirect.github.com/junit-team/junit-framework/issues/5899)) * [`1cd56df`](junit-team/junit-framework@1cd56df) Update plugin org.graalvm.buildtools.native to v1.1.5 ([#5880](https://redirect.github.com/junit-team/junit-framework/issues/5880)) * Additional commits viewable in [compare view](junit-team/junit-framework@r6.1.2...r6.1.3) Updates `org.junit.vintage:junit-vintage-engine` from 6.1.2 to 6.1.3 Release notes *Sourced from [org.junit.vintage:junit-vintage-engine's releases](https://github.com/junit-team/junit-framework/releases).* > JUnit 6.1.3 = Platform 6.1.3 + Jupiter 6.1.3 + Vintage 6.1.3 > > See [Release Notes](https://docs.junit.org/6.1.3/release-notes.html). > > **Full Changelog**: <junit-team/junit-framework@r6.1.2...r6.1.3> Commits * [`f59f60d`](junit-team/junit-framework@f59f60d) Release 6.1.3 * [`cd8ec92`](junit-team/junit-framework@cd8ec92) Finalize 6.1.3 release notes * [`c8729f2`](junit-team/junit-framework@c8729f2) Restore compatibility with GraalVM 25 ([#5901](https://redirect.github.com/junit-team/junit-framework/issues/5901)) * [`ddc9e74`](junit-team/junit-framework@ddc9e74) Update graalvm/setup-graalvm action to v1.6.4 ([#5959](https://redirect.github.com/junit-team/junit-framework/issues/5959)) * [`fe2c52a`](junit-team/junit-framework@fe2c52a) Update plugin org.graalvm.buildtools.native to v1.1.7 ([#5923](https://redirect.github.com/junit-team/junit-framework/issues/5923)) * [`62afc02`](junit-team/junit-framework@62afc02) Delay GraalVM plugin updates for 3 days * [`0cc2902`](junit-team/junit-framework@0cc2902) Skip `graalVmTest` task if GraalVM env vars are not set * [`f6bbfc5`](junit-team/junit-framework@f6bbfc5) Move GraalVM tests to separate test task ([#5903](https://redirect.github.com/junit-team/junit-framework/issues/5903)) * [`e87e052`](junit-team/junit-framework@e87e052) Update plugin org.graalvm.buildtools.native to v1.1.6 ([#5899](https://redirect.github.com/junit-team/junit-framework/issues/5899)) * [`1cd56df`](junit-team/junit-framework@1cd56df) Update plugin org.graalvm.buildtools.native to v1.1.5 ([#5880](https://redirect.github.com/junit-team/junit-framework/issues/5880)) * Additional commits viewable in [compare view](junit-team/junit-framework@r6.1.2...r6.1.3) Updates `org.junit.jupiter:junit-jupiter-params` from 6.1.2 to 6.1.3 Release notes *Sourced from [org.junit.jupiter:junit-jupiter-params's releases](https://github.com/junit-team/junit-framework/releases).* > JUnit 6.1.3 = Platform 6.1.3 + Jupiter 6.1.3 + Vintage 6.1.3 > > See [Release Notes](https://docs.junit.org/6.1.3/release-notes.html). > > **Full Changelog**: <junit-team/junit-framework@r6.1.2...r6.1.3> Commits * [`f59f60d`](junit-team/junit-framework@f59f60d) Release 6.1.3 * [`cd8ec92`](junit-team/junit-framework@cd8ec92) Finalize 6.1.3 release notes * [`c8729f2`](junit-team/junit-framework@c8729f2) Restore compatibility with GraalVM 25 ([#5901](https://redirect.github.com/junit-team/junit-framework/issues/5901)) * [`ddc9e74`](junit-team/junit-framework@ddc9e74) Update graalvm/setup-graalvm action to v1.6.4 ([#5959](https://redirect.github.com/junit-team/junit-framework/issues/5959)) * [`fe2c52a`](junit-team/junit-framework@fe2c52a) Update plugin org.graalvm.buildtools.native to v1.1.7 ([#5923](https://redirect.github.com/junit-team/junit-framework/issues/5923)) * [`62afc02`](junit-team/junit-framework@62afc02) Delay GraalVM plugin updates for 3 days * [`0cc2902`](junit-team/junit-framework@0cc2902) Skip `graalVmTest` task if GraalVM env vars are not set * [`f6bbfc5`](junit-team/junit-framework@f6bbfc5) Move GraalVM tests to separate test task ([#5903](https://redirect.github.com/junit-team/junit-framework/issues/5903)) * [`e87e052`](junit-team/junit-framework@e87e052) Update plugin org.graalvm.buildtools.native to v1.1.6 ([#5899](https://redirect.github.com/junit-team/junit-framework/issues/5899)) * [`1cd56df`](junit-team/junit-framework@1cd56df) Update plugin org.graalvm.buildtools.native to v1.1.5 ([#5880](https://redirect.github.com/junit-team/junit-framework/issues/5880)) * Additional commits viewable in [compare view](junit-team/junit-framework@r6.1.2...r6.1.3) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
…ion as HTTP 500 for non-numeric length/start arguments
RETURN left('a', []), right('a', []) and substring('aa', 0, []) reached an
unchecked (Number) args[i] cast on the length/start argument, so a LIST (or
any other non-numeric value) threw a raw java.lang.ClassCastException that
escaped as HTTP 500 "Error on transaction commit" instead of a client-facing
type error, matching Neo4j/Memgraph/FalkorDB which all reject it as a type
error (22N27 in Neo4j).
LeftFunction, RightFunction, CypherSubstringFunction (and its unregistered
twin SubstringFunction) now resolve their numeric argument(s) through the
existing CypherFunctionHelper.requireNumberArgument() helper, the same
runtime check already used by the pure-numeric family (ArcadeData#5484). Extended
NumericSignature with a startArg position so the parse-time static check
(CypherSemanticValidator.checkStaticallyKnownNumericArgs) also covers these
three functions' trailing numeric arguments without misclassifying their
leading STRING argument, so a literal LIST is rejected before the query
runs, same as the rest of the numeric family.
The primary STRING argument of left()/right()/substring() is untouched:
ArcadeData#5901 named it as a follow-up left out of ArcadeData#5798's scope, and ArcadeData#6609 is only
about the numeric argument.
… positions of string functions Issue ArcadeData#5798 (fixed by PR ArcadeData#5901) made split(), replace(), trim()/btrim(), lTrim() and rTrim() reject a non-STRING value in their primary argument position with a client-facing type error. The remaining STRING-typed argument positions of the same functions - split()'s delimiter, replace()'s search and replacement text, and the trim-character argument of trim()/btrim()/lTrim()/rTrim() - still silently coerced any value via toString(). char.length()/char_length() was not covered by ArcadeData#5798 at all. Apply CypherFunctionHelper.requireStringArgument() to those remaining positions, the same helper ArcadeData#5798 introduced for the primary argument, so every STRING-typed argument position now follows the same policy.
What does this PR do?
Makes
toUpper(),toLower(),trim()/btrim(),lTrim(),rTrim(),split()andreplace()reject arguments outside their declared
STRINGinput domain with a client-facingCommandSemanticException(400) instead of silently converting any value -INTEGER,BOOLEAN,LIST<ANY>, ... - to text viaObject.toString().Closes #5798
Motivation
These functions declare a
STRINGinput domain, but their implementation called.toString()onthe argument without checking its runtime type first. That made
toUpper(5)observationallyidentical to the explicit conversion
toUpper(toString(5)), hiding an invalid type usage as anapparently successful result and diverging from Neo4j, which rejects the non-
STRINGinput as atype error.
This is the same class of defect already fixed for the numeric family in #5484 and for
head()/last()/tail()/size()in #5476/#5477.Related issues
Closes #5798. Same class of fix as #5484, #5476 and #5477.
What changed
CypherFunctionHelper.requireStringArgument(Object, String), mirroring the existingrequireNumberArgument/requireListArgumenthelpers: returns the value as aString, returnsnullfor anullargument (Cypher null propagation), or throws aCommandSemanticExceptionviathe shared
typeMismatch()builder.ToUpperFunction,ToLowerFunction,LTrimFunction,RTrimFunction,CypherTrimFunction,CypherSplitFunctionandReplaceFunctionnow callrequireStringArgument()on their primarytext argument instead of blindly calling
.toString().CypherSemanticValidator.checkStaticallyKnownArgType()(already covering
size()/head()/last()/tail()) to reject a statically-known non-STRINGliteral for the single-argument spellings of
toUpper/upper,toLower/lower,trim/btrim,lTrim/ltrimandrTrim/rtrim, soMATCH (n) WHERE false RETURN toUpper(5)fails before thequery runs, matching Neo4j and the existing [OpenCypher] abs() returns HTTP 500 for invalid argument instead of client-facing error #5484/[OpenCypher] size() returns null for unsupported argument types instead of raising a type error #5477/[OpenCypher] head() returns null for a non-list argument instead of rejecting it #5476 precedent.
toString()conversion is still available explicitly, andnullstill propagates tonullperCypher semantics.
Test plan
New test class
CypherStringFunctionArgumentIssue5798Test:INTEGERargument with aCommandSemanticExceptionnaming the function andSTRING;toUpper()additionally coversBOOLEANandLIST<ANY>.nullstill propagates tonullfor every affected function.STRINGargument still works as before (regression guard).toUpper(toString(5))still returns"5"(explicit conversion keeps working).null(e.g.replace(5, null, 'b')), so anullsecondary argument cannot mask an out-of-domain primaryone.
upper,lower,ltrim,rtrim) reject a non-STRING argument too.trim(BOTH/LEADING/TRAILING char FROM string)form rejects anon-STRING source.
Verified with (see
docs/5798-string-function-strict-string-args.mdfor full detail):optional-argument-null [Cypher] Decide whether an explicit null in an optional argument propagates or means "use the default" #5629, and several other Cypher function test classes): all pass.
com.arcadedb.query.opencypher.**package (337 test classes, 7652 tests, including theOpenCypher TCK suite): 0 failures, 0 errors.
Additional Notes
Breaking change: queries that relied on the old implicit
toString()coercion now get aCommandSemanticException(400) instead of a silently converted string, e.g.RETURN toUpper(5)used to return
"5"and now throws. This is intentional and matches the precedent already set by#5484 for the numeric family; callers who need the old behavior can request it explicitly with
toString(), e.g.toUpper(toString(5)).Scope is limited to the primary text argument of each of the seven functions, matching what the
issue reports. Secondary STRING-typed arguments (e.g.
split()'s delimiter,replace()'s searchand replacement text) are unchanged and out of scope for this fix.
left()andright()(
com.arcadedb.function.text.LeftFunction/RightFunction) have the same class of defect but werenot named in #5798 and are left for a follow-up.
Checklist
mvn clean packagecommand