avaje-inject icon indicating copy to clipboard operation
avaje-inject copied to clipboard

Missing dependency error not displaying

Open re-thc opened this issue 1 year ago • 9 comments

If I declare an @Inject without a matching @Singleton or similar, I get the following error:

Caused by: java.lang.NullPointerException: Cannot invoke "String.lastIndexOf(int)" because "fullType" is null

It was pretty hard to realize from that what was missing. Would be good if this error was caught to provide a better message so we can see what to do.

Thanks!

re-thc avatar Sep 22 '24 17:09 re-thc

Got an example class so I can replicate? The missing dependency message is usually quite descriptive, so this feels like something else is the problem.

SentryMan avatar Sep 22 '24 17:09 SentryMan

Yeah, the error message still works for me.

[ERROR] /M:/Dev/avaje-helidon-nima-api-example/src/main/java/com/jojo/helidon/api/Example.java:[6,8] No dependency provided for com.jojo.helidon.api.DependencyClass on com.jojo.helidon.api.Example
[ERROR] Dependencies [com.jojo.helidon.api.DependencyClass] are not provided - there are no @Singleton, @Component, @Factory/@Bean that currently provide this type. If this is an external dependency consider specifying via @External

Tried field/constructor/method injection, but I am unable to replicate your issue.

SentryMan avatar Sep 22 '24 17:09 SentryMan

@re-thc got anything to add? I can't publish a fix if I can't replicate the issue.

SentryMan avatar Sep 29 '24 03:09 SentryMan

Happy to close. It triggers if the class is coming from another project/module/jar and no longer exists. Maybe too convoluted to cater for.

re-thc avatar Sep 30 '24 12:09 re-thc

can you run with mvn compile -X and send the stacktrace.

SentryMan avatar Sep 30 '24 14:09 SentryMan

@re-thc can you explain exactly how you got this? Edge case it may be, but if it happened once it'll happen again to somebody else.

It triggers if the class is coming from another project/module/jar and no longer exists.

what do you mean no longer exists?

SentryMan avatar Oct 01 '24 02:10 SentryMan

can you explain exactly how you got this?

It happens if you reference a class that no longer exists. You do get class not found exceptions also. When there's a long chain of errors it's possible to miss it so was originally confused by this particular error.

what do you mean no longer exists?

Say it gets deleted or renamed.

re-thc avatar Oct 04 '24 06:10 re-thc

Really need the stack trace for this one. Can you provide it?

rbygrave avatar Oct 09 '24 08:10 rbygrave

@re-thc we should be able to fix it if you provide a stack trace

SentryMan avatar Oct 13 '24 18:10 SentryMan

@rbygrave, I figured out how to replicate it using JPMS. All you have to do is remove requires directives for the types you're using. (like blackbox.other in the tests)

SentryMan avatar Nov 02 '24 15:11 SentryMan