Skip to content

Commit 7aea093

Browse files
authored
Fix StackOverflowError introduced by MongoDbAtlasLocalContainerConnectionDetails.getSslBundle() (#4149)
Fixes #4133 Auto-cherry-pick to 1.0.x Signed-off-by: Yanming Zhou <[email protected]>
1 parent 8e17a15 commit 7aea093

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

spring-ai-spring-boot-testcontainers/src/main/java/org/springframework/ai/testcontainers/service/connection/mongo/MongoDbAtlasLocalContainerConnectionDetailsFactory.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.ai.testcontainers.service.connection.mongo;
1818

19+
import java.lang.invoke.MethodHandles;
1920
import java.lang.reflect.Method;
2021

2122
import com.mongodb.ConnectionString;
@@ -41,6 +42,7 @@
4142
*
4243
* @author Eddú Meléndez
4344
* @author Soby Chacko
45+
* @author Yanming Zhou
4446
* @since 1.0.0
4547
* @see ContainerConnectionDetailsFactory
4648
* @see MongoConnectionDetails
@@ -80,7 +82,16 @@ public ConnectionString getConnectionString() {
8082
// Conditional implementation based on whether the method exists
8183
public SslBundle getSslBundle() {
8284
if (GET_SSL_BUNDLE_METHOD != null) { // Boot 3.5.x+
83-
return (SslBundle) ReflectionUtils.invokeMethod(GET_SSL_BUNDLE_METHOD, this);
85+
try {
86+
return (SslBundle) MethodHandles.lookup()
87+
.in(GET_SSL_BUNDLE_METHOD.getDeclaringClass())
88+
.unreflectSpecial(GET_SSL_BUNDLE_METHOD, GET_SSL_BUNDLE_METHOD.getDeclaringClass())
89+
.bindTo(this)
90+
.invokeWithArguments();
91+
}
92+
catch (Throwable e) {
93+
throw new RuntimeException(e);
94+
}
8495
}
8596
return null; // Boot 3.4.x (No-Op)
8697
}

0 commit comments

Comments
 (0)