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

Factory.create should include ServiceLocator Name #681

Open
buko opened this issue Jun 3, 2022 · 2 comments
Open

Factory.create should include ServiceLocator Name #681

buko opened this issue Jun 3, 2022 · 2 comments

Comments

@buko
Copy link

buko commented Jun 3, 2022

Currently if Factory#create throws an exception the result is a stack trace that includes no information about the ServiceLocator:

Exception in thread "main" MultiException stack 1 of 3
java.lang.RuntimeException: test!!!
...
	at org.jvnet.hk2.internal.FactoryCreator.create(FactoryCreator.java:129)
	at org.jvnet.hk2.internal.AutoActiveDescriptor.create(AutoActiveDescriptor.java:148)
	at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:458)
...
MultiException stack 2 of 3
java.lang.IllegalArgumentException: While attempting to resolve the dependencies of Foo errors were found
	at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:224)
	at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:334)
	at org.jvnet.hk2.internal.AutoActiveDescriptor.create(AutoActiveDescriptor.java:148)
	at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:458)

Similar to #491 when HK2 encounters an exception while resolving dependencies it really should include the name amd LocatorId of the ServiceLocator that failed. In applications that include a hierarchy of ServiceLocators this would allow such problems to be quickly tracked down to the source.

@arjantijms
Copy link
Contributor

When I have some time I could take a look, as indeed, obscuring causes makes debugging much more difficult.

What about
:

It's problematic for me because I'm told I shouldn't sign the ECA. Will continue to peek into this.

Has that been resolved? Is it know why you were being told that? What would happen if you sign/accept?

@buko
Copy link
Author

buko commented Jun 6, 2022

What would happen if you sign/accept?

I really don't know, to tell you the truth. Legal looks at this stuff, says "No" and there's not much room for debate. It's not really clear that that they even understand what they're looking at.

If there was a way for me to easily submit a PR I would. There's a single class, FactoryCreator#129 that seems to implement the logic of calling Factory#provide().

The actual fix is pretty straightforwards I think:

  1. A new exception class should be introduced: DependencyProvisioningException extends HK2RuntimeException. This class should have a constructor that takes a ServiceLocator. It should have a static method that formulates a meaningful message to include the ServiceLocator name/locatorId.
  2. If Factory#provide throws an (Runtime)Exception this exception could caught and wrapped in a DependencyProvisioningException as the 'cause'.
  3. UnsatisifedDependencyException could be made to extend DependencyProvisioningException.

The basic idea here is that if Dependency Provisioning does fail whatever reason we get some clear context about which ServiceLocator was involved.

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

No branches or pull requests

2 participants