-
Notifications
You must be signed in to change notification settings - Fork 298
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
Method reference is not considered as a dependency #215
Comments
Yeah, you're right, it's a shortcoming at the moment. ArchUnit uses the visitor-API though, but I still think this could be enhanced. I've looked into it, and I think even the case from #131 might be solvable with the current ASM version. For your case, I think the information could be retrieved by checking
While for #131, it might be possible to use
At least with a quick check the first one had a reference to the target class of the method handle within the arguments, the second one was called specifically with the type of the target class. That would actually be cool to add those features somehow 😄 The info could easily be retrieved by extending I guess a Similar a This should be feasible, even though it's not trivial. But at least it should be possible to integrate this into the current ArchUnit code base without having to change much existing code. I'll tag this and keep it here for now, maybe someone wants to jump in and work on this. Otherwise I'll try to get around to it as quickly as possible (which might unfortunately be a while |
@codecholeric I will take a look at this closer a little bit later and if work it out will create a PR. |
@dpfg Okay, cool 😃 Let me know, if I can support you in any way! |
We have the same problem regarding lambda statements. We are trying to check whether methods in some particular inner classes are ever actually accessed at all. We use an ArchRuleDefinition targeting these classes together with an ArchCondition collecting all "JavaMethod"s and checking getCallsOfSelf() on each. If this list is empty, the method has never been accessed and the test fails. (for sake of completeness: we also tried getCallsToSelf(), getAccessesToSelf() and getAccessesFromSelf(), all with the same result) For "normal" method calls this works fine, i.e. the test is successful if the method is used and fails if it doesn't. However, in cases when there is a lamda statement involved (e.g. exampleClass::exampleMethod), the test produces false positives, since it fails even though the method has been called in a lambda statement. |
@codecholeric After reading through the code, I think I understand your idea of introducing an equivalent of There are some things I am not sure about:
|
Yes, but if you simply invoke the same I'm not super sure about how to extend the model though, I think we should sync about it 😉 Then we can also discuss the part about the lambda. |
Hey guys! Thank you for all the hard work you put into the framework. I'm trying to create a rule that forbids throwing exceptions without a message. It is pretty simple to detect such cases: throw new MyCustomExpcetion(); However there are also cases similar to this: Optional
.ofNullable(null)
.orElseThrow(MyCustomExpcetion::new); I wonder if this issue makes it impossible to detect passing constructor without parameter as a reference? Just to be clear, the following piece of code should not violate the rule, because it actually calls another constructor overload: Optional
.ofNullable(null)
.orElseThrow(() -> new MyCustomExpcetion("some details")); BTW I'm eager to contribute to the solution, but unfortunately I don't quite understand the suggestion above |
Hey, sorry, you just need to wait for the next release and it should work! (it's missing #649) I'll try to release within the next 1-2 weeks!! |
This issue should be solved by #649 |
Lets say there are two packages:
where one of classes in integration package has the following code:
and the following rule
Check passes successfully, while when used with regular construction of DomainClass inside IntegrationClass check fails.
Seems like the root cause is the same as in #131. Dependency has been moved to the constant pool at compile time. In this case it gets replaced by invoke dynamic that refers to the constant pool. And this is a huge difference as now we are talking about legitimate not-dead code that violates constraints but not catched.
ASM exposes API to access constant pools so theoretically can be used to detect all references to classes.
Does it make sense to mention this limitations/corner cases in the documentation? Seems like problem doesn't get solution in near future.
The text was updated successfully, but these errors were encountered: