fix: add null safety for getDatastoreForConnection in data service factory bean#15474
Open
jamesfredley wants to merge 1 commit into7.1.xfrom
Open
fix: add null safety for getDatastoreForConnection in data service factory bean#15474jamesfredley wants to merge 1 commit into7.1.xfrom
jamesfredley wants to merge 1 commit into7.1.xfrom
Conversation
…ctory bean Guard against datastore implementations that may return null from getDatastoreForConnection() by throwing a clear ConfigurationException with the connection name and service class, rather than silently setting a null datastore. Assisted-by: Claude Code <Claude@Claude.ai>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes DatastoreServiceMethodInvokingFactoryBean.resolveEffectiveDatastore() defensive against MultipleConnectionSourceCapableDatastore.getDatastoreForConnection(...) returning null, by throwing a ConfigurationException instead of allowing a null datastore to be set on a data service.
Changes:
- Add null-guards after
getDatastoreForConnection(...)for explicit@Transactional(connection=...)selection. - Add null-guards after
getDatastoreForConnection(...)for domain-class mapping-derived connection selection. - Introduce
ConfigurationExceptionerror messages intended to provide clearer misconfiguration diagnostics.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../groovy/org/grails/datastore/mapping/config/DatastoreServiceMethodInvokingFactoryBean.groovy
Show resolved
Hide resolved
.../groovy/org/grails/datastore/mapping/config/DatastoreServiceMethodInvokingFactoryBean.groovy
Show resolved
Hide resolved
.../groovy/org/grails/datastore/mapping/config/DatastoreServiceMethodInvokingFactoryBean.groovy
Show resolved
Hide resolved
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.
Summary
getDatastoreForConnection()calls inDatastoreServiceMethodInvokingFactoryBean.resolveEffectiveDatastore(), throwing a clearConfigurationExceptionwith the connection name, domain class, and service class rather than silently setting a null datastore.@Transactional(connection=...)path and the domain class mapping inheritance path.The
MultipleConnectionSourceCapableDatastoreinterface doesn't guarantee non-null returns, and some implementations (e.g. Neo4j, SimpleMapDatastore) do a raw map lookup without validation. Hibernate already throws on missing connections, but this makes the factory bean defensive regardless of the underlying datastore implementation.Flagged by Copilot review on #15472.