eclipse-ee4j / eclipse-ee4j/jersey
Supplier bindings are missing rank support
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Expected:
bind Supplier A with rank 1, then bind Supplier B with rank 10, then serviceLocator.getService(X.class) should return supplier B's object.
Actual:
return Supplier A's object.
Hk2Helper.java
```
private static void bindSupplierClassBinding(ServiceLocator locator, SupplierClassBinding binding) {
Consumer bindConsumer = binder -> {
boolean disposable = DisposableSupplier.class.isAssignableFrom(binding.getSupplierClass());
// Bind the Supplier itself to be able to inject - Supplier supplier;
// The contract of the supplier is not registered that means that the instance of the supplier can be retrieved
// only using Supplier interface and not using implementation class itself. Supplier can be registered only once with
// all provided contracts.
ServiceBindingBuilder supplierBuilder = binder.bind(binding.getSupplierClass());
binding.getContracts().forEach(contract -> {
supplierBuilder.to(new ParameterizedTypeImpl(Supplier.class, contract));
if (disposable) {
supplierBuilder.to(new ParameterizedTypeImpl(DisposableSupplier.class, contract));
}
});
binding.getQualifiers().forEach(supplierBuilder::qualifiedBy);
supplierBuilder.named(binding.getName());
supplierBuilder.in(transformScope(binding.getSupplierScope()));
//The supplier binding doesn't have rank set
binder.bind(supplierBuilder);
// Register wrapper for factory functionality, wrapper automatically call service locator which is able to retrieve
// the service in the proper context and scope. Bridge is registered for all contracts but is able to lookup from
// service locator only using the first contract.
Type contract = null;
if (binding.getContracts().iterator().hasNext()) {
contract = binding.getContracts().iterator().next();
}
ServiceBindingBuilder builder = binder.bindFactory(
new SupplierFactoryBridge<>(locator, contract, binding.getName(), disposable));
setupSupplierFactoryBridge(binding, builder);
if (binding.getImplementationType() != null) {
builder.asType(binding.getImplementationType());
}
};
ServiceLocatorUtilities.bind(locator, createBinder(bindConsumer));
}
```
Contributor guide
Research direction
Start in Hk2Helper.java at bindSupplierClassBinding and trace how the SupplierClassBinding rank is transferred into the supplier binding. Reproduce the issue with Supplier A at rank 1 and Supplier B at rank 10, then verify that serviceLocator.getService(X.class) returns B's object when the rank is honored.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100