GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [java] NPE in UseCollectionIsEmptyRule with enums by foxmason · Pull Request #2968 · pmd/pmd Conversation
Contributor
Describe the PRThe UseCollectionIsEmptyRule requires finding the first parent of the class I also refactored, cleared-up, and formatted a few test cases. Related issuesReady?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
Generated by 🚫 Danger |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@oowekyala , @adangel , would you be able to review this one?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ASTClassOrInterfaceBody classBody = expr.getFirstParentOfType(ASTClassOrInterfaceBody.class); | ||
| List<ASTVariableDeclarator> varDeclarators = classBody.findDescendantsOfType(ASTVariableDeclarator.class); | ||
| Node classOrEnumBody = expr.getFirstParentOfType(ASTClassOrInterfaceBody.class); | ||
| if (classOrEnumBody == null) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is it the only case when classOrEnumBody can be null? Unfortunately I don't know.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Technically it could also be in an annotation type, but I think it's ok, as annotations may not contain code (at least, not code that this rule would pick up on).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Technically it could also be in an annotation type, but I think it's ok, as annotations may not contain code (at least, not code that this rule would pick up on).
It could also be an ASTRecordBody
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'll add a test case when merging
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| for (ASTVariableDeclarator varDeclarator : varDeclarators) { | ||
| if (varDeclarator.getName().equals(varName)) { | ||
| return varDeclarator.getFirstDescendantOfType(ASTClassOrInterfaceType.class); | ||
| return varDeclarator.getParent().getFirstDescendantOfType(ASTClassOrInterfaceType.class); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What's the reason to go one level up in the hierarchy?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This fetches a LocalVariableDeclaration or FieldDeclaration node. VariableDeclarator nodes never have themselves a type node child.
But the actual right way to do that is varDeclarator.getVariableId().getTypeNode().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This fetches a LocalVariableDeclaration or FieldDeclaration node. VariableDeclarator nodes never have themselves a type node child.
But the actual right way to do that is varDeclarator.getVariableId().getTypeNode().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'll fix that when merging
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| public enum ComponentSize { | ||
|
|
||
| S("s"), | ||
| M("m"), |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Only one field is enough, IMO. Less code in xml is better :)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| public enum ComponentSize { | ||
|
|
||
| S("s"), | ||
| M("m"), |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I suggest removing several fields here too.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Btw, it seems like danger report is incorrect here, I'm not sure how to regenerate it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
- Use better typeres - Add test cases for records and local var
[java] NPE in UseCollectionIsEmptyRule with enums #2968
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[java] NPE in UseCollectionIsEmptyRule with enums
There was an error while loading. Please reload this page.