fix(sdk): findById answers null for an absent id, as documented (#6420) - #6752
Open
delchev wants to merge 1 commit into
Open
fix(sdk): findById answers null for an absent id, as documented (#6420)#6752delchev wants to merge 1 commit into
delchev wants to merge 1 commit into
Conversation
JavaRepository.findById documented "the entity, or null if not found" but delegated to a store method that threw IllegalArgumentException instead, so the documented null never happened and every findById + null-guard was dead code. Callers who followed the javadoc surfaced an absent id as a 500: a controller looking a record up by a path parameter never reached its own 404, a posting handler could not skip a source row deleted between the event and the handler, and a dangling FK in a schedules-notify job killed the whole run instead of skipping one row. The whole generated corpus was written against the documented contract - the glue templates and the generated DAO/REST templates all null-guard the result - so the honest fix is to honour it. An absent id is an ordinary outcome of a lookup, and the caller owns what it means: findOne(id) stays the Optional sibling for a caller that wants to chain its own failure (orElseThrow carrying a 404), and the generated controllers already read single records through it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
delchev
added a commit
to dirigible-io/dirigible-io.github.io
that referenced
this pull request
Aug 15, 2026
JavaRepository.findById answers null for an id that is not there, and findOne answers an empty Optional - neither throws, so the caller decides what absence means. Documents the controller shape that follows from it, including the trap that returning null from a controller method answers 204 and would overwrite a 404 just set. Platform side: eclipse-dirigible/dirigible#6752 (issue #6420). Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6420.
The mismatch
JavaRepository.findById(Object id)documents "the entity, ornullif not found", but delegated to a store method that threwIllegalArgumentExceptioninstead. The documentednullnever happened, so everyfindById+ null-guard was dead code — and the null-guard is the shape the docs teach, so it is everywhere:404; the request came back 500,Posting.java.templateguardsif (source == null || ...) return;— a source row deleted between the event and the handler threw instead of skipping,entity.Customer == null ? null : new CustomerRepository().findById(entity.Customer)— a dangling FK killed the whole job run instead of skipping one row.The fix
Honour the documented contract:
findByIdanswersnullwhen there is no such row.That is the coherent half of the pair, not just the cheap one. An absent id is an ordinary outcome of a lookup, and what it means belongs to the caller — a
404at a controller boundary, a skip in an event handler.findOne(id)stays theOptionalsibling for a caller that wants to chain its own failure (findOne(id).orElseThrow(...)carrying its own status), and the generated REST controllers already read single records through exactly that. Every generated template — the events glue and the DAO/REST templates alike — was written against the documented contract, so this makes their guards live rather than requiring ~40 call sites to be rewritten around a throw the name never suggested. It also keeps the client-Java model's Spring-Boot idiom intact, where afind*that may not find is the norm and a throwing lookup carries a different name.No template, generator or platform caller depended on the throw:
JavaEntityStore.findByIdwas its only site.Verification
New
JavaRepositoryFindByIdIT(HTTP-only, ~30 s) deploys a client-Java project — entity,@Repository extends JavaRepository<T>, and a controller in the documented shape (findById+ null-guard → 404) — and asserts:Optionalvariant,Confirmed to fail without the fix: with the throw restored, the unknown-id request is a 500 and the test errors on that assertion.
Also green:
data-store-java+engine-javaunit tests (101), andJavaEngineIT,JavaComponentIT,JavaTemplateIT,JavaEntityLobColumnIT,NumberingSdkIT.🤖 Generated with Claude Code