apache / apache/incubator-seata
Loading SPI instance(singleton )can not use the passed constructor parameters after the first-time call
- Dominant language
- Java
- Stars
- 26k
- Forks
- 8.8k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 4
Description
- [ ] I have searched the [issues](https://github.com/seata/seata/issues) of this repository and believe that this is not a duplicate.
### Ⅰ. Issue Description
When I Load SPI with Singleton-Scope,because that the singleton instance will be cached, except for the first time load(), the constructor parameters passed in later call will not be used to create instance.
### Ⅱ. Describe what happened
```
1. Define a SPI implementation using Singleton-Scope.
2. Load by calling:
public static S load(Class service, String activateName, Class[] argsType, Object[] args)
and passing paramterA, get the instance.
3. Load again by calling the same load() and passing parameterB
4. Expect to get an new instance by using parameterB,but will get the cached instance.
```
### Ⅲ. Describe what you expected to happen
We should know that different parameters means the different state of extension instance, so when we use stateful extension points, we should define it as Prototype-Scope.
But the api in EnhancedServiceLoader allows users to load a Single-Scope extension point by passing different parameteres.
In this case ,the user should get an explicit exception to notify them that the parameters after the first time 's call will not be used . In this way ,we can help them to identify where the problem is:
(1) Usage problem, if the singleton load is called multiple times, they should pass the same parameter.
(2) The Scope() of the extension point was wrong. they should use Prototype-Scope
### Ⅳ. How to reproduce it (as minimally and precisely as possible)
the same as Ⅱ. Describe what happened
### Ⅴ. Anything else we need to know?
### Ⅵ. Environment:
- JDK version :
- OS :
- Others:
Contributor guide
Research direction
Start with the EnhancedServiceLoader.load(Class service, String activateName, Class[] argsType, Object[] args) entry point and trace how Singleton-Scope instances are cached. Reproduce two loads with different constructor parameters, then verify that the completed behavior explicitly reports ignored parameters instead of silently returning the cached instance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100