Skip to content

Fix IllegalAccessException in MongoDbAtlasLocalContainerConnectionDetails.getSslBundle() #4186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

markpollack
Copy link
Member

Fixes IllegalAccessException when calling getSslBundle() method in MongoDbAtlasLocalContainerConnectionDetails.

Summary

This PR resolves an IllegalAccessException that occurs when accessing the SSL bundle in MongoDB Atlas container connection details.

Changes

  • Fixed illegal access issue in MongoDbAtlasLocalContainerConnectionDetails.getSslBundle()
  • Updated method implementation to properly handle SSL bundle access

Test Plan

  • Verified fix resolves the IllegalAccessException
  • Existing tests pass

This is a clean recreation of the original PR #4183 to resolve rebase conflicts caused by stale branch history.

…ails.getSslBundle()

The original fix in commit 03d475e introduced a MethodHandles.unreflectSpecial()
approach to resolve a StackOverflowError, but this caused IllegalAccessException
due to incorrect usage of unreflectSpecial() for interface default methods.

The unreflectSpecial() method is designed for superclass method calls, not
interface default methods, and requires private access which caused:
"IllegalAccessException: no private access for invokespecial: interface
org.springframework.boot.autoconfigure.mongo.MongoConnectionDetails"

This fix replaces the complex reflection approach with simple interface
delegation using 'MongoConnectionDetails.super.getSslBundle()'. This solution:

- Eliminates IllegalAccessException by properly overriding with public access
- Avoids StackOverflowError by delegating to interface default method
- Removes all reflection code, making it simpler and more maintainable
- Works across all Spring Boot versions without version-specific checks
- Resolves access privilege conflict between interface and parent class

The interface default method returns null, which is the desired behavior
for SSL configuration when no custom SSL bundle is provided.

Fixes: https://github.com/spring-projects/spring-ai/actions/runs/16981113833

Signed-off-by: Mark Pollack <[email protected]>
@quaff
Copy link
Contributor

quaff commented Aug 21, 2025

Is it compatible with Spring Boot 3.4.x?

@markpollack
Copy link
Member Author

well i only tested on 3.4... we don't yet have a build for 4...

@quaff
Copy link
Contributor

quaff commented Aug 21, 2025

well i only tested on 3.4... we don't yet have a build for 4...

Then it's safe, I will close GH-4175.

@quaff
Copy link
Contributor

quaff commented Aug 21, 2025

well i only tested on 3.4... we don't yet have a build for 4...

MongoConnectionDetails.super.getSslBundle() is introduced since 3.5.0, it won't be compiled against 3.4.x.

@markpollack
Copy link
Member Author

thanks, let me validate all this correctly tomorrow. i was looking for an easy solution to 'patch' vs using reflection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants