Skip to content

Regression in map implementation #2615

@brandes-pq

Description

@brandes-pq

Description of the Problem

Removing entries from a map may throw an exception: The query

map{'aa':1,'bb':2,'cc':3} => map:remove('aa') => map:remove('bb')

crashes with

java.lang.ClassCastException: class org.basex.query.value.map.TrieBranch cannot be cast to class org.basex.query.value.map.TrieLeaf (org.basex.query.value.map.TrieBranch and org.basex.query.value.map.TrieLeaf are in unnamed module of loader 'app')
	at org.basex.query.value.map.XQTrieMap.keysInternal(XQTrieMap.java:72)
...

The problem is that the assumption that TrieNodes of size 1 are always TrieLeafs. This assumption may be broken when removing the second-to-last entry in a TrieBranch (return new TrieBranch(ks, nu, size - 1); when size is 2).

The regression has been introduced with commit bc73d82 and has thus been present since release 11.7.

Expected Behavior

The correct result would be map{'cc':3} and no uncaught exception.

Steps to Reproduce the Behavior

see above

Do you have an idea how to solve the issue?

In TreeBranch::remove, the last line (return new TrieBranch(ks, nu, size - 1);) should probably specially handle the case size == 2

What is your configuration?

Cloned BaseX repository, running with mvn exec:java

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions