• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aspectran / aspectran / #4672

19 Oct 2025 12:25PM UTC coverage: 36.339% (-0.001%) from 36.34%
#4672

push

github

topframe
Refactor(bean): Enhance bean scope locking and correctness

This commit introduces several significant improvements to the bean scope implementations, focusing on optimizing locking, correcting a critical logic flaw, enhancing API usability, and improving documentation.

Key changes include:

- **Optimized FactoryBean Locking:** The locking strategy in `AbstractBeanRegistry.getScopedBean` has been refined. Instead of escalating to a write-lock for FactoryBean object creation, it now uses a `synchronized` block on the FactoryBean instance itself. This narrows the
lock scope, reducing contention and improving concurrency when creating beans from a FactoryBean.

- **Fixed Critical Flaw in `SessionScope`:** The `findMatchingBeanRule` method had a serious bug where it could incorrectly match a bean by class name even when a specific ID was provided. The logic has been corrected to enforce a strict match by ID if one exists, and only
match by class name for beans without an ID. This prevents unpredictable behavior in clustered or deserialized sessions.

- **Enabled `destroy(Object bean)` in `SessionScope`:** Removed the `UnsupportedOperationException` thrown by `getBeanRuleByInstance`. This allows developers to manually destroy a specific session-scoped bean, making the API more complete and usable in scenarios like sticky
sessions.

- **Clarified `lazy-destroy` Intention:** Added a detailed Javadoc to the `AbstractScope.destroy()` method to explain that the `lazy-destroy` mechanism is an intentional design. It ensures that critical resources like database connections are released last, after all
dependent beans have been destroyed.

- **Improved Javadocs:** Polished and standardized Javadocs across all scope-related classes (`Scope`, `AbstractScope`, `RequestScope`, `SessionScope`, `SingletonScope`) for better clarity, consistency, and maintainability.

1 of 9 new or added lines in 2 files covered. (11.11%)

591 existing lines in 32 files now uncovered.

15061 of 41446 relevant lines covered (36.34%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/core/src/main/java/com/aspectran/core/support/i18n/message/MessageSourceResourceBundle.java


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc