-
Notifications
You must be signed in to change notification settings - Fork 4
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
Feature: Robust service provider loading #27
Conversation
WalkthroughThe changes focus on enhancing the resilience of the Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files selected for processing (2)
- src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java (3 hunks)
- src/test/java/org/cryptomator/integrations/common/IntegrationsLoaderTest.java (2 hunks)
Additional comments: 6
src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java (5)
- 12-12: The addition of
java.util.Objects
import is appropriate for the use ofObjects::nonNull
in the stream operation to filter out null instances of service providers. This ensures that only successfully instantiated service providers are considered for further processing.- 14-14: The addition of
java.util.ServiceConfigurationError
import supports the new exception handling logic within theinstantiateServiceProvider
method. This is crucial for catching errors related to service provider configuration issues, aligning with the PR's objective to enhance resilience in the service loading process.- 52-53: The use of
map
to instantiate service providers followed byfilter(Objects::nonNull)
is a good practice. It ensures that any service provider that fails to instantiate and returnsnull
is excluded from further processing. This approach contributes to the robustness of the service loading mechanism.- 89-94: The handling of
ExceptionInInitializerError
,NoClassDefFoundError
, andRuntimeException
inpassesStaticAvailabilityCheck
method is a significant improvement. It ensures that any issues encountered during the static availability check of a service provider do not cause the entire loading process to fail. Logging the warning with the specific service provider's name provides valuable debugging information.- 99-104: Similar to the static availability check, the instance availability check method
passesInstanceAvailabilityCheck
also appropriately handlesRuntimeException
. This consistent approach in handling exceptions across both static and instance checks contributes to the overall robustness of the service loading mechanism.src/test/java/org/cryptomator/integrations/common/IntegrationsLoaderTest.java (1)
- 206-223: The addition of the
testPassesAvailabilityCheckThrowing
test method in theInstanceAvailabilityChecks
nested class is crucial for ensuring that theIntegrationsLoader
correctly handles exceptions thrown by instance methods annotated with@CheckAvailability
. This test method complements the static checks by covering instance method scenarios, thereby ensuring comprehensive testing of the new functionality. The inclusion of different classes (C1
andC2
) to test various exception scenarios is a good practice.This test method effectively validates that the service loading process is resilient to exceptions thrown during the availability checks of service providers, aligning with the PR's objectives.
src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java
Outdated
Show resolved
Hide resolved
src/test/java/org/cryptomator/integrations/common/IntegrationsLoaderTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/test/java/org/cryptomator/integrations/common/InitExceptionTestClass.java (1 hunks)
Additional comments: 2
src/test/java/org/cryptomator/integrations/common/InitExceptionTestClass.java (2)
- 8-10: The static block intentionally throws a
RuntimeException
to simulate a failure during class initialization. This approach is effective for testing the system's behavior in the face of initialization errors. Ensure that this behavior aligns with the testing framework's capabilities and that the exception is handled or expected in test cases to avoid unintended test failures.- 20-23: The
test()
method is annotated with@CheckAvailability
, which suggests it plays a role in determining the class's availability or readiness. Given the context of this class being used for testing exception handling during initialization, this method's implementation and annotation usage seem appropriate. However, ensure that the annotation's behavior is well-documented and understood within the broader system.
src/test/java/org/cryptomator/integrations/common/InitExceptionTestClass.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/test/java/org/cryptomator/integrations/common/InitExceptionTestClass.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/test/java/org/cryptomator/integrations/common/InitExceptionTestClass.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too happy with ServiceLoader.Provider#get
throwing an Error
instead of an Exception
. But since we can't change this, I'm ok with this approach.
src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java
Show resolved
Hide resolved
src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Sebastian Stenzel <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java
src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java
Closes #26.
This PR improves discovery and loading of supported service providers by catching common exceptions/errors during this process (
ExceptionInInitializationError
,NoClassDefFoundError
,RuntimeException
).If one of those throwables are thrown, the service provider is considered as "not supported" and filtered out.
Summary by CodeRabbit