Skip to content

split() returns a String[] that most collection methods mishandle: join()/asString() leak the array identity toString, sort() returns it unsorted, first()/last() throw #7027

Closed

Description

@ruispereira

Summary

split() returns a java.lang.String[], and most collection methods do not handle an array receiver. The failures are not uniform: some leak the array's identity toString() into a user-visible result, sort() silently returns the input unsorted, first()/last() throw, and asList() does not convert it. Separately, join() on a Set ignores its separator argument.

Where (HEAD c50338bd8)

engine/src/main/java/com/arcadedb/query/sql/method/** - the collection methods type-test their receiver for java.util.List (or Collection) and fall through to a toString() on anything else. split() is the standard producer of a non-List collection, so the two meet on the most natural chain a user writes.

Repro

Measured at c50338bd8. The receiver matrix for join('-'):

['a','b'].join('-')                    -> "a-b"                            correct
'a,b'.split(',').join('-')             -> "[Ljava.lang.String;@7a8fa663"   array identity toString
['b','a'].asSet().join('-')            -> "[a, b]"                         Set toString, separator ignored
'a,b'.split(',').asList().join('-')    -> "[Ljava.lang.String;@5ce33a58"   asList() did not convert

sort() is worse than an error, because it looks like it worked:

'b,a'.split(',').sort()                -> ["b","a"]     unsorted, no error
['b','a'].asSet().sort()               -> ["a","b"]     correct

The rest of the surface is inconsistent again:

'a,b'.split(',').size()                -> 2                                works
'a,b'.split(',').first()               -> CommandExecutionException
'a,b'.split(',').last()                -> CommandExecutionException
'a,b'.split(',').asString()            -> "[Ljava.lang.String;@75e01201"

So a user chaining split() into any collection method gets, depending on which one, a correct answer, a silently wrong answer, a Java object address in their result set, or an exception. The "[Ljava.lang.String;@..." cases are the most damaging because they reach the client as data.

Suggested fix

Normalize the receiver once, in AbstractSQLMethod or a shared helper: accept Collection, an array (via Arrays.asList) and a scalar (as a singleton), and route every collection method through it. That fixes the whole matrix in one place rather than method by method, and it is the same "one helper so the next hardening reaches all of them" move already applied to SQLAggregatedFunction.accumulateNumeric and to the conversion methods in #6825.

Two separate points worth deciding explicitly:

  • sort() returning the receiver unsorted rather than erroring is the one I would prioritise: a silently unsorted result is worse than a failure.
  • join() on a Set should honour its separator; today it discards the argument and returns the Set's own toString().

Scope / confidence

High - every line above is measured output from this checkout, with the List case in the same run as the control.

Note on scope

I also tested two adjacent claims and they did NOT reproduce, so they are deliberately not part of this report: asRecord() does not mutate the receiver's record (the property was identical before and after the call), and replace() with a null operand returns null rather than its first argument.

Activity

  1. added this to the 26.9.1 milestone on Sep 2, 2026
  2. added
    in progress
    on Sep 3, 2026
  3. self-assigned this
    on Sep 3, 2026
  4. lvca commented on Sep 3, 2026

    @lvca
    Member

    Fixed in #7092 (26.9.1).

    split() now returns a list, like the split() function and Cypher's split() already did, and every collection method (join(), sort(), transform(), asList(), asSet(), asString()) accepts lists, sets, arrays and iterables alike. So 'a,b'.split(',').join('-') gives a-b, 'b,a'.split(',').sort() gives [a, b], and asSet().join('-') honours the separator. first() and last() are now also available as methods, so 'a,b'.split(',').first() works.

    Found while testing: a method chained on a parameter, such as :list.join('-'), was silently ignored and returned the bare parameter. That is fixed too.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  5. removed
    in progress
    on Sep 3, 2026
  6. ruispereira commented on Sep 3, 2026

    @ruispereira
    ContributorAuthor

    Re-validated against main at 4c03d0280: every line of the reported matrix is fixed, and the shared listReceiverOrNull() helper is exactly the structural fix this issue asked for.

    Five collection methods were not routed through it (keys, values, ifEmpty, remove, removeAll - all still instanceof Collection). Much narrower exposure now, since split() answers a List, so it needs an array-valued parameter or property - filed as a follow-up rather than reopening.

  7. added a commit that references this issue on Sep 4, 2026
    e2ab2b5
  8. added a commit that references this issue on Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions