New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix optional injection bugs #516
Conversation
hk2-locator/src/test/java/org/glassfish/hk2/tests/locator/optional/NamedOptionalInjection.java
Outdated
Show resolved
Hide resolved
I found some more related bugs, which I wrote test for and bundled them here together. |
This is failing Jenkins build |
tbh, I am a bit confused as to why.
The error log seems to indicate, that |
IsEmpty is JDK 11 only and we need to support JDK 8 fir Jakarta EE 9 |
OptionalActiveDescriptor does seem to use @nAmed injection for it's wrapped value. As a consequence both unnamed and other named bindings for the same type are/may be injected when the actual binding is missing/present. Signed-off-by: Balthasar Schüss <mail@bschuess.dev>
Signed-off-by: Balthasar Schüss <mail@bschuess.dev>
Trying to inject Optional<Optional<String>> one might expect the following: bound literal String -> expected Optional<Optional<String> -> actual Optional<Optional.empty> bound Optional<Optional<String> -> expected Optional<Optional<String>> -> actual Optional<Optional<Optional>>> Furthermore, one might expect that more specific bindings take precedence over less specific bindings, that is also not the case It is true that nested Optionals is not a common use case, but the precedence should be implemented either way. Signed-off-by: Balthasar Schüss <mail@bschuess.dev>
If a guice service is injected as optional into a hk2 service. Guice services are never injected and Optional is always empty. Signed-off-by: Balthasar Schüss <mail@bschuess.dev>
Signed-off-by: Balthasar Schüss <mail@bschuess.dev>
Add tests and fixes for:
OptionalActiveDescriptor fails to inject @nAmed optional values, because (name) qualifiers are not propagated for the retrieval of the wrapped value. As a consequence any bound instance (unnamed, with same name, or other name) may be injected.
This is a treacherous bug, in particular when injecting configuration parameters and migrating from previous versions.
Trying to inject Optional<Optional> one might expect the following:
Furthermore, one might expect that more specific bindings take precedence over less specific bindings, that is also not the case.
It is true that nested Optionals are not a common use case, but the precedence should be implemented either way.
Trying to inject Guice services as Optional into hk2 services always causes the optional to be empty.