Skip to content

Commit 6a2bc45

Browse files
CodeCasterXclaude
andcommitted
refactor: Add fail-fast validation for BeanContainer in StaticAuthApplier
Add notNull validation at constructor entry point and simplify createAuthorizationFromAnnotation by removing redundant null check, following the fail-fast principle. **Changes:** - Add `notNull(beanContainer, "The bean container cannot be null.")` in constructor - Remove redundant null check in createAuthorizationFromAnnotation method - BeanContainer is guaranteed non-null by AnnotationParser, validate early at entry point **Benefits:** - ✅ Fail-fast: Errors detected immediately at construction time - ✅ Clearer contract: BeanContainer is required, not optional - ✅ Simplified logic: No need for null check in private method - ✅ Consistent validation: Follows same pattern as AnnotationParser **Testing:** ✅ AuthFieldMapperTest: 8/8 tests pass ✅ No behavioral changes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 570595e commit 6a2bc45

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

  • framework/fit/java/fit-builtin/services/fit-http-classic/definition/src/main/java/modelengine/fit/http/client/proxy/support/applier

framework/fit/java/fit-builtin/services/fit-http-classic/definition/src/main/java/modelengine/fit/http/client/proxy/support/applier/StaticAuthApplier.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
package modelengine.fit.http.client.proxy.support.applier;
88

9+
import static modelengine.fitframework.inspection.Validation.notNull;
10+
911
import modelengine.fit.http.annotation.RequestAuth;
1012
import modelengine.fit.http.client.proxy.Authorization;
1113
import modelengine.fit.http.client.proxy.PropertyValueApplier;
@@ -30,9 +32,10 @@ public class StaticAuthApplier implements PropertyValueApplier {
3032
* 使用指定的鉴权注解和 BeanContainer 初始化 {@link StaticAuthApplier} 的新实例。
3133
*
3234
* @param authAnnotation 表示鉴权注解的 {@link RequestAuth}。
33-
* @param beanContainer Bean 容器,用于获取 AuthProvider(可能为 null,如果不使用 Provider)
35+
* @param beanContainer 表示 Bean 容器,用于获取 AuthProvider。
3436
*/
3537
public StaticAuthApplier(RequestAuth authAnnotation, BeanContainer beanContainer) {
38+
notNull(beanContainer, "The bean container cannot be null.");
3639
this.authorization = this.createAuthorizationFromAnnotation(authAnnotation, beanContainer);
3740
}
3841

@@ -45,11 +48,6 @@ public void apply(RequestBuilder requestBuilder, Object value) {
4548
private Authorization createAuthorizationFromAnnotation(RequestAuth annotation, BeanContainer beanContainer) {
4649
// 如果指定了 Provider,需要 BeanContainer
4750
if (annotation.provider() != AuthProvider.class) {
48-
if (beanContainer == null) {
49-
throw new IllegalStateException(
50-
"BeanContainer is required for AuthProvider, but not available. " +
51-
"Provider: " + annotation.provider().getName());
52-
}
5351
AuthProvider provider = beanContainer.beans().get(annotation.provider());
5452
if (provider == null) {
5553
throw new IllegalStateException(

0 commit comments

Comments
 (0)