Skip to content
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

Merged
merged 5 commits into from Oct 24, 2020
Merged

Fix optional injection bugs #516

merged 5 commits into from Oct 24, 2020

Conversation

BCSol
Copy link

@BCSol BCSol commented Aug 7, 2020

Add tests and fixes for:

  1. 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.

  2. Trying to inject Optional<Optional> one might expect the following:

    • Binding a literal string results to Optional<Optional>, but actaally Optional<Optional.empty> is injected
    • Binding Optional<Optional results to Optional<Optional, but actually Optional<Optional<Optional>> is injected
      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.
  3. Trying to inject Guice services as Optional into hk2 services always causes the optional to be empty.

@BCSol BCSol changed the title Fix optional injection bug dropping (named) qualifiers WIP Fix optional injection bugs Aug 26, 2020
@BCSol BCSol changed the title WIP Fix optional injection bugs Fix optional injection bugs Aug 26, 2020
@BCSol
Copy link
Author

BCSol commented Aug 26, 2020

I found some more related bugs, which I wrote test for and bundled them here together.

@BCSol BCSol requested a review from smillidge August 30, 2020 21:51
@smillidge
Copy link
Contributor

This is failing Jenkins build

@BCSol
Copy link
Author

BCSol commented Oct 13, 2020

This is failing Jenkins build

tbh, I am a bit confused as to why.

19:01:09  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:testCompile (default-testCompile) on project hk2-locator: Compilation failure: Compilation failure: 
19:01:09  [ERROR] /home/jenkins/agent/workspace/hk2_PR-516/hk2-locator/src/test/java/org/glassfish/hk2/tests/locator/optional/NamedOptionalTest.java:[91,43] cannot find symbol
19:01:09  [ERROR]   symbol:   method isEmpty()
19:01:09  [ERROR]   location: variable providedOptional of type java.util.Optional<java.lang.String>
19:01:09  [ERROR] /home/jenkins/agent/workspace/hk2_PR-516/hk2-locator/src/test/java/org/glassfish/hk2/tests/locator/optional/NamedOptionalTest.java:[106,43] cannot find symbol
19:01:09  [ERROR]   symbol:   method isEmpty()
19:01:09  [ERROR]   location: variable providedOptional of type java.util.Optional<java.lang.String>
19:01:09  [ERROR] /home/jenkins/agent/workspace/hk2_PR-516/hk2-locator/src/test/java/org/glassfish/hk2/tests/locator/optional/NestedOptionalTest.java:[66,53] cannot find symbol
19:01:09  [ERROR]   symbol:   method isEmpty()
19:01:09  [ERROR]   location: class java.util.Optional<java.lang.String>
19:01:09  [ERROR] /home/jenkins/agent/workspace/hk2_PR-516/hk2-locator/src/test/java/org/glassfish/hk2/tests/locator/optional/NestedOptionalTest.java:[102,53] cannot find symbol
19:01:09  [ERROR]   symbol:   method isEmpty()
19:01:09  [ERROR]   location: class java.util.Optional<java.lang.String>
19:01:09  [ERROR] -> [Help 1]
19:01:09  [ERROR] 
19:01:09  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
19:01:09  [ERROR] Re-run Maven using the -X switch to enable full debug logging.
19:01:09  [ERROR] 
19:01:09  [ERROR] For more information about the errors and possible solutions, please read the following articles:

The error log seems to indicate, that java.util.Optional doesn't have the method isEmpty(), which doesn't make much sense.
@smillidge could you rerun the pipeline or do you have an idea what could be causing this?

@smillidge
Copy link
Contributor

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>
@smillidge smillidge merged commit c4e93ff into eclipse-ee4j:master Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants