`defaultFallback` annotation attribute on class cause `defaultFallback` handling conflicts on methods with different return types.
- Dominant language
- Java
- Stars
- 23.1k
- Forks
- 8.1k
- PR merge metrics
- No merged PRs in 30d
Description
## Issue Description
Type: *bug report*
### Describe what happened
The `defaultFallback` handling on methods with different return types is depend on calling order when `defaultFallback` is defined in annotation on class, like the issue #3386 .
当`defaultFallback` 由类上的注解定义时,不同返回值类型的方法的`defaultFallback` 处理结果与实际方法的被调用顺序相关,这和问题 #3386 类似。
### Describe what you expected to happen
The `defaultFallback` of each method of return type should be correctly handled.
各类型方法的 `defaultFallback` 可以被正确的处理。
### How to reproduce it (as minimally and precisely as possible)
Minimium reproduce demo: https://github.com/dowenliu-xyz/sentinel-default-fallback-on-class-conflict/
- Minimium dependencies: only spring-boot starter and sentinel-annotation-aspectj:
```
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'com.alibaba.csp:sentinel-annotation-aspectj:1.8.7'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
```
- One additial `SentinelResourceAspect` bean definition:
```
@Bean
public SentinelResourceAspect sentinelResourceAspect() {
return new SentinelResourceAspect();
}
```
- Resource/Biz bean definition:
```
@Component
@SentinelResource(defaultFallback = "df")
public class Biz {
@SentinelResource
public int doubled(int a) {
if (a == 0) {
throw new IllegalArgumentException("a should not be 0");
}
return a * 2;
}
public String df() {
return "fallback";
}
@SentinelResource
public String doubled(String a) {
if (a == null || a.isEmpty()) {
throw new IllegalArgumentException("a should not be empty");
}
return a + a;
}
}
```
- Method calls
```
@Component
public class RunBiz implements CommandLineRunner {
private static final Logger LOG = LoggerFactory.getLogger(RunBiz.class);
@Resource
private Biz biz;
@Override
public void run(String... args) throws Exception {
//*/
// 先执行实际 defaultFallback 不存在的方法, 会导致后面有 defaultFallback 的方法不执行 defaultFallback
try {
LOG.error("[1] should not output: {}", biz.doubled(0)); // no output
} catch (IllegalArgumentException e) {
LOG.info("[2] exception: {}", e.getMessage()); // go here
}
try {
LOG.info("[3] expect fallback: {}" , biz.doubled("")); // no output
} catch (IllegalArgumentException e) {
LOG.error("[4] IllegalArgumentException: {}", e.getMessage()); // go here, an IllegalArgumentException
}
/*/
// 先执行实际 defaultFallback 存在的方法, 会导致后面无回调的方法报错 (报错与业务方法内报错无关,业务异常信息丢失)
try {
LOG.info("[5] fallback: {}", biz.doubled("")); // fallback
} catch (Exception e) {
LOG.error("[6] should not output: {}", e.getMessage()); // no output
}
try {
LOG.error("[7] should not output: {}", biz.doubled(0)); // no output
} catch (ClassCastException e) {
LOG.error("[8] unexpected ClassCastException: {}", e.getMessage()); // go here, a ClassCastException
} catch (IllegalArgumentException e) {
LOG.info("[9] expected exception: {}", e.getMessage()); // no output
}
//*/
}
}
```
### Tell us your environment
MacOS 14.3
Temurin 17.0.10
Gradle wrapper 8.7
### Anything else we need to know?
Additionally, I really don't understand what the design intent is and what the usage scenarios are for supporting annotations at the class level.
另外,我实在不明白在类级别支持注解是什么设计意图、有什么使用场景。
Contributor guide
Assessment
This issue has not been assessed yet.