You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by ja...@apache.org on 2026/02/28 23:36:38 UTC
(grails-core) branch fix/dataservice-null-datastore-guard created (now b2aee98886)
This is an automated email from the ASF dual-hosted git repository.
jamesfredley pushed a change to branch fix/dataservice-null-datastore-guard
in repository https://gitbox.apache.org/repos/asf/grails-core.git
at b2aee98886 fix: add null safety for getDatastoreForConnection in data service factory bean
This branch includes the following new commits:
new b2aee98886 fix: add null safety for getDatastoreForConnection in data service factory bean
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(grails-core) 01/01: fix: add null safety for getDatastoreForConnection in data service factory bean
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jamesfredley pushed a commit to branch fix/dataservice-null-datastore-guard
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit b2aee988861a22f991235411b4b9afd998f62eaf
Author: James Fredley <ja...@users.noreply.github.com>
AuthorDate: Sat Feb 28 18:36:26 2026 -0500
fix: add null safety for getDatastoreForConnection in data service factory 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 <Cl...@Claude.ai>
---
...atastoreServiceMethodInvokingFactoryBean.groovy | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/config/DatastoreServiceMethodInvokingFactoryBean.groovy b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/config/DatastoreServiceMethodInvokingFactoryBean.groovy
index ca2bfa88b6..973afd25c7 100644
--- a/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/config/DatastoreServiceMethodInvokingFactoryBean.groovy
+++ b/grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/config/DatastoreServiceMethodInvokingFactoryBean.groovy
@@ -31,6 +31,7 @@ import org.grails.datastore.mapping.core.Datastore
import org.grails.datastore.mapping.core.connections.ConnectionSource
import org.grails.datastore.mapping.core.connections.ConnectionSourcesSupport
import org.grails.datastore.mapping.core.connections.MultipleConnectionSourceCapableDatastore
+import org.grails.datastore.mapping.core.exceptions.ConfigurationException
import org.grails.datastore.mapping.services.Service
/**
@@ -83,8 +84,16 @@ class DatastoreServiceMethodInvokingFactoryBean extends MethodInvokingFactoryBea
if (serviceConnection != null
&& ConnectionSource.DEFAULT != serviceConnection
&& ConnectionSource.ALL != serviceConnection) {
- return ((MultipleConnectionSourceCapableDatastore) defaultDatastore)
+ Datastore resolved = ((MultipleConnectionSourceCapableDatastore) defaultDatastore)
.getDatastoreForConnection(serviceConnection)
+ if (resolved == null) {
+ throw new ConfigurationException(
+ "DataSource not found for connection name [${serviceConnection}] " +
+ "specified via @Transactional on service [${serviceClass.name}]. " +
+ 'Please check your multiple data sources configuration and try again.'
+ )
+ }
+ return resolved
}
// Fall back to domain class mapping datasource
@@ -102,8 +111,17 @@ class DatastoreServiceMethodInvokingFactoryBean extends MethodInvokingFactoryBea
if (domainConnection != null
&& ConnectionSource.DEFAULT != domainConnection
&& ConnectionSource.ALL != domainConnection) {
- return ((MultipleConnectionSourceCapableDatastore) defaultDatastore)
+ Datastore resolved = ((MultipleConnectionSourceCapableDatastore) defaultDatastore)
.getDatastoreForConnection(domainConnection)
+ if (resolved == null) {
+ throw new ConfigurationException(
+ "DataSource not found for connection name [${domainConnection}] " +
+ "mapped on domain class [${domainClass.name}] " +
+ "used by service [${serviceClass.name}]. " +
+ 'Please check your multiple data sources configuration and try again.'
+ )
+ }
+ return resolved
}
return defaultDatastore