Skip to content

fix(base-query): fix five indexing and scope bugs; wire @Unique#60

Merged
deer merged 1 commit into
mainfrom
query_fixes
May 11, 2026
Merged

fix(base-query): fix five indexing and scope bugs; wire @Unique#60
deer merged 1 commit into
mainfrom
query_fixes

Conversation

@deer
Copy link
Copy Markdown
Collaborator

@deer deer commented May 11, 2026

Q1 — IsEqualTo fallback path was null-asymmetric: when a queried value was null, the fallback stream filter called Objects.equals(rawValue, NULL_OBJECT) which always returned false. The fix wraps the extracted value with nonNull() before comparing, matching the behaviour of the indexed fast path.

Q2 — Match-level scope was silently ignored by all three terminals (IsEqualTo, IsNotEqualTo, Matches). Each terminal initialised this.scope = Scope.Direct unconditionally, discarding any scope set via Match.scope(). The fix initialises this.scope = where.select.scope so the terminal inherits the match scope, with its own override still taking precedence.

Q3 — Scope.Direct, Scope.BreadthFirst, and Scope.DepthFirst were not additive as their Javadoc promised. If objectByClass contained any entry for the queried class, traverse() was never called. The fix restructures stream(Scope) so Scope.Indexed is the only short-circuit; all other scopes concatenate indexed objects with traversal results, deduplicated by identity.

Q4 — add(Class, T) and remove(Class, T) silently swallowed null arguments via an if (x != null) guard. Null class or value is a programmer error; both parameters are now validated with Objects.requireNonNull.

Q5 — @Unique was annotated @Target(METHOD) but nothing ever read it on methods, making it dead code. The target is changed to FIELD so it can coexist with @Indexable on public static final Function fields. When present, the index stores a direct key → object mapping instead of key → Set<object>, isEqualTo lookups become O(1), and duplicate keys throw IllegalStateException at index time.

@deer deer merged commit 138070f into main May 11, 2026
3 checks passed
@deer deer deleted the query_fixes branch May 11, 2026 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant