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
False Negative of ClassFanOutCheck with "new" Keyword #14787
Comments
Ideally this Check description should be updated to explain this metric. |
@Lmh-java , please update test to not use inner class, as inner classes should not be counted, please use some JDK class. |
Updated to use |
@romani I was looking at the code. Basically, the problem comes from Sure, I will also update the documentation along with this change, if this issue is approved. |
I have gone through the issue.
Config file:
After running But you will get error for:
I think in the first case (no error case) there is a problem with visitType method in AbstractClassCoupling. When a token is IDENT, it is added to referencedClassName if it is a class (import is mapped). But that is not happening here even though "File" is being identified as IDENT. |
@Prathamesh-007 Thanks for your analysis. :) It seems that you are focusing on the type parameter of the I am not very sure about why the type parameter is not counted as a "complexity". I haven't gone through that part of code yet, but I feel like that is a very obvious case that is too hard to miss by all these users and tests. I would assume this might be designed this way on purpose? I will look into that and get back to this later. But for this issue we might should focus more on the |
Spotted at #14740 (comment)
I have read check documentation: https://checkstyle.sourceforge.io/checks/metrics/classfanoutcomplexity.html
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run (10.15.0)
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
Compiling test case:
Config file:
/var/tmp $ cat config.xml
Test Java file:
/var/tmp $ cat Test.java
Audit result:
Expected result:
Reasoning: Our Java test case relies on
Constraint
class, so there should be one class dependency counted. This is caused by incorrectly handlednew
keyword inside lambda expression. In other words, it cannot recognizeConstraint::new
as creating an instance of theConstraint
class.I will work on this after PR #14740 is done.
The text was updated successfully, but these errors were encountered: