Skip to content

Conversation

markpollack
Copy link
Member

Summary

Fixes the IllegalAccessException introduced by the StackOverflowError fix in commit 03d475e by replacing complex MethodHandles reflection with simple interface delegation.

Problem

The original fix used MethodHandles.unreflectSpecial() incorrectly for interface default methods, causing:

IllegalAccessException: no private access for invokespecial: interface 
org.springframework.boot.autoconfigure.mongo.MongoConnectionDetails

Root Cause

  • unreflectSpecial() is designed for superclass method calls, not interface default methods
  • The lookup context lacked the required private access for invokespecial calls
  • Access privilege conflict between interface public method and parent class method

Solution

Replaced 24 lines of complex reflection code with 3 lines of elegant interface delegation:

@Override
public SslBundle getSslBundle() {
    return MongoConnectionDetails.super.getSslBundle();
}

Benefits

  • ✅ Eliminates IllegalAccessException by properly overriding with public access
  • ✅ Avoids the original 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

Test Results

  • MongoDbAtlasLocalContainerConnectionDetailsFactoryIT.addAndSearch passes
  • ✅ All testcontainer module tests pass
  • ✅ No regressions introduced

Fixes

…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 <mark.pollack@broadcom.com>
@markpollack
Copy link
Member Author

this is on top of an old base it seems, i'm creating a new PR.

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.

2 participants