-
Notifications
You must be signed in to change notification settings - Fork 301
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
NPE from getDirectDependenciesFromSelf() called on a JavaClass stub #397
Comments
To answer your first question, no, you should not be able to get dependencies from a stub class 😉 If you want to analyse a class you should import it. Nevertheless I do agree that a NPE is not particularly nice, so I think we should fix this and give stub classes simply empty dependencies. None of the rules API accesses stub classes that way, that's probably why it hasn't shown so far 😉 |
Thanks, @codecholeric!
Fair enough. When looking for transitive dependencies, I'll anyways limit the recursion to the package I've actually imported.
That would be great! I guess that this will be as simple as providing an API to recognize a stub |
One question is what should happen if you call |
Signed-off-by: Manfred Hanke <[email protected]>
Signed-off-by: Manfred Hanke <[email protected]>
Signed-off-by: Manfred Hanke <[email protected]>
Signed-off-by: Manfred Hanke <[email protected]>
So far, if a user would call `JavaClass.getDirectDependency{From/To}Self()` on a class that was not directly imported (e.g. a class that was not present in the original import, but accessed by a class from that import) it would cause a NPE. While we do want to cut the class graph at that point (i.e. not further track dependencies for classes that are not part of the import), we do not want this exceptional behavior. This change fixes the behavior and sets empty dependencies for all non-directly imported classes, be it classes that have been resolved from the classpath later on, or stub classes, because further resolution has been turned off. Resolves: #397 Signed-off-by: Manfred Hanke <[email protected]>
So far, if a user would call `JavaClass.getDirectDependency{From/To}Self()` on a class that was not directly imported (e.g. a class that was not present in the original import, but accessed by a class from that import) it would cause a NPE. While we do want to cut the class graph at that point (i.e. not further track dependencies for classes that are not part of the import), we do not want this exceptional behavior. This change fixes the behavior and sets empty dependencies for all non-directly imported classes, be it classes that have been resolved from the classpath later on, or stub classes, because further resolution has been turned off. Resolves: #397 Signed-off-by: Manfred Hanke <[email protected]>
I've run into an issue with transitive dependencies not being imported completely.
Here's a simple example (which, admittedly, looks strange on its own 😃) to illustrate it:
Since 85506e2, I'm getting a
The line number is for ArchUnit 0.14.1, but
getDirectDependenciesFromSelf
is currently a one-liner anyways; the issue is thatjavaClassDependencies
is not initialized, i.e. thatJavaClass.completeFrom(ImportContext)
was not called. But here, I don't know what's expected for stubs.Should I be able to
getDirectDependenciesFromSelf()
from a stubJavaClass
? (Anyways, the NPE isn't a nice result for sure.)The hypothesis that the error might be because
Throwable.getStackTrace()
returnsStackTraceElement[]
(which seems to be imported correctly), whereas I'm asking for dependencies fromStackTraceElement
, is supported by the following simpler example:with
I'm still puzzled though why the same issue does not show up in:
The text was updated successfully, but these errors were encountered: