Skip to content

fix: add null safety for getDatastoreForConnection in data service factory bean#15474

Open
jamesfredley wants to merge 1 commit into7.1.xfrom
fix/dataservice-null-datastore-guard
Open

fix: add null safety for getDatastoreForConnection in data service factory bean#15474
jamesfredley wants to merge 1 commit into7.1.xfrom
fix/dataservice-null-datastore-guard

Conversation

@jamesfredley
Copy link
Contributor

Summary

  • Add null guards after getDatastoreForConnection() calls in DatastoreServiceMethodInvokingFactoryBean.resolveEffectiveDatastore(), throwing a clear ConfigurationException with the connection name, domain class, and service class rather than silently setting a null datastore.
  • Covers both the explicit @Transactional(connection=...) path and the domain class mapping inheritance path.

The MultipleConnectionSourceCapableDatastore interface 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.

…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>
@github-actions github-actions bot added the bug label Feb 28, 2026
@jamesfredley jamesfredley self-assigned this Feb 28, 2026
@jamesfredley jamesfredley marked this pull request as ready for review February 28, 2026 23:39
Copilot AI review requested due to automatic review settings February 28, 2026 23:39
@jamesfredley jamesfredley added this to the grails:7.1.0 milestone Feb 28, 2026
@jamesfredley jamesfredley moved this to In Progress in Apache Grails Feb 28, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ConfigurationException error messages intended to provide clearer misconfiguration diagnostics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@jdaugherty jdaugherty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants