Conversation
Co-authored-by: huayanYu <16700837+huayanYu@users.noreply.github.com>
Co-authored-by: huayanYu <16700837+huayanYu@users.noreply.github.com>
Co-authored-by: huayanYu <16700837+huayanYu@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix null connectionProxyMap error in nested transactions
Fix NPE in ConnectionFactory when nested REQUIRES_NEW transaction establishes no JDBC connections
Feb 10, 2026
There was a problem hiding this comment.
Pull request overview
This PR addresses an NPE scenario in the dynamic datasource local transaction lifecycle when a REQUIRES_NEW transactional method performs no JDBC work, and adds an integration test reproduction to prevent regressions.
Changes:
- Add a guard in
ConnectionFactory.notify(...)to safely handle transactions with no tracked JDBC connections. - Introduce two Spring test services to reproduce the “
REQUIRES_NEWwithout JDBC connection” case. - Add a Spring Boot 3 starter test that exercises the outer
REQUIRED+ innerREQUIRES_NEW(no JDBC) flow.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
dynamic-datasource-test-common/.../NonDatabaseConnectionService.java |
Adds a test helper service that opens a JDBC connection in an outer REQUIRED transaction and invokes an inner REQUIRES_NEW method. |
dynamic-datasource-test-common/.../NoConnectionService.java |
Adds a test helper service with a REQUIRES_NEW method that performs no JDBC operations. |
dynamic-datasource-spring/.../ConnectionFactory.java |
Adds a null-guard to avoid NPE when committing/rolling back a transaction that never obtained a JDBC connection. |
dynamic-datasource-spring-boot3-starter/.../DsTransactionalTest.java |
Adds an integration test covering the new edge case. |
| @DSTransactional(propagation = DsPropagation.REQUIRES_NEW) | ||
| public void innerRequiresNewWithoutConnection() { | ||
| // No database operations - just business logic | ||
| System.out.println("Business logic without database operations"); |
There was a problem hiding this comment.
Avoid writing to stdout from this Spring @service. It will add noisy console output to the test suite (and potentially to any app that happens to include test-common). Prefer removing the print entirely or using the project’s logger (e.g., Slf4j) if you need an observable side-effect.
Suggested change
| System.out.println("Business logic without database operations"); |
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.
ConnectionFactory.notify()throws NPE when a REQUIRES_NEW transaction nested within a REQUIRED transaction completes without establishing any JDBC connections.Root Cause
When a transaction establishes no connections,
concurrentHashMap.get(xid)returnsnull. Line 150 attempts to iterate overconnectionProxyMap.values()without checking for null:Changes
ConnectionFactory.notify(): Added null check before accessing
connectionProxyMapTest Coverage: Added
NonDatabaseConnectionServiceandNoConnectionServiceto reproduce the scenario where an outer REQUIRED transaction has JDBC connections but inner REQUIRES_NEW does notScenario
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
maven.aliyun.com/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant(dns block)/usr/lib/jvm/temurin-8-jdk-amd64/bin/java /usr/lib/jvm/temurin-8-jdk-amd64/bin/java -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/gradle-daemon-main-8.13.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/agents/gradle-instrumentation-agent-8.13.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.13(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.