Skip to content
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

NullPointerException on KDOC inspection #1334

Merged
merged 13 commits into from
Jun 2, 2022
Merged

Conversation

Cheshiriks
Copy link
Member

What's done:

### What's done:
* fixed NullPointerException on KDOC inspection
Closes #1331
@@ -88,7 +88,8 @@ class KdocMethods(configRules: List<RulesConfig>) : DiktatRule(
val config = configRules.getCommonConfiguration()
val filePath = node.getFilePath()
val isTestMethod = node.hasTestAnnotation() || isLocatedInTest(filePath.splitPathToDirs(), config.testAnchors)
if (!isTestMethod && !node.isStandardMethod() && !node.isSingleLineGetterOrSetter()) {
if (!isTestMethod && !node.isStandardMethod() && !node.isSingleLineGetterOrSetter() &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please cover with tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Added

@@ -88,7 +88,8 @@ class KdocMethods(configRules: List<RulesConfig>) : DiktatRule(
val config = configRules.getCommonConfiguration()
val filePath = node.getFilePath()
val isTestMethod = node.hasTestAnnotation() || isLocatedInTest(filePath.splitPathToDirs(), config.testAnchors)
if (!isTestMethod && !node.isStandardMethod() && !node.isSingleLineGetterOrSetter()) {
if (!isTestMethod && !node.isStandardMethod() && !node.isSingleLineGetterOrSetter() &&
node.treeParent.findAllDescendantsWithSpecificType(ElementType.FUNCTION_TYPE).isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that there is node.treeParent exists?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@codecov
Copy link

codecov bot commented May 31, 2022

Codecov Report

Merging #1334 (0d4aec1) into master (d7810d6) will increase coverage by 0.03%.
The diff coverage is 66.66%.

@@             Coverage Diff              @@
##             master    #1334      +/-   ##
============================================
+ Coverage     83.49%   83.52%   +0.03%     
- Complexity     2561     2563       +2     
============================================
  Files           106      106              
  Lines          7275     7278       +3     
  Branches       2014     2017       +3     
============================================
+ Hits           6074     6079       +5     
+ Misses          354      353       -1     
+ Partials        847      846       -1     
Flag Coverage Δ
unittests 83.52% <66.66%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt 93.02% <50.00%> (+0.16%) ⬆️
...tlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt 82.74% <50.00%> (-0.20%) ⬇️
.../diktat/ruleset/rules/chapter1/IdentifierNaming.kt 82.23% <100.00%> (ø)
.../diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt 87.42% <100.00%> (ø)
.../cqfn/diktat/ruleset/utils/FunctionAstNodeUtils.kt 82.14% <0.00%> (+10.71%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7810d6...0d4aec1. Read the comment docs.

### What's done:
* fixed NullPointerException on KDOC inspection
Closes #1331
### What's done:
* fixed NullPointerException on KDOC inspection
Closes #1331
### What's done:
* fixed NullPointerException on KDOC inspection
Closes #1331
### What's done:
* fixed NullPointerException on KDOC inspection
Closes #1331
/**
* Checks if a function is anonymous
*/
fun ASTNode.isAnonymousFunction() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a rule for explicit typing for public function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing explicit type can only mean that the function returns Unit, so there is no need in such rule. Even in the rule that checks @return KDoc tag we allow it to be missing if the function has no explicit return type or explicitly specified Unit.

Copy link
Member

@orchestr7 orchestr7 Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But @Cheshiriks wanted to make a boolean function, no?
He wanted return this.getIdentifierName() == null

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

* Checks if a function is anonymous
*/
fun ASTNode.isAnonymousFunction() {
require(this.elementType == FUN)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be a part of checking of this function instead of assumption?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's needed here. We already everywhere have a check that this value is equal to FUN before calling this method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this function treats to node to be a FUN. it means that it's can be called only
node.elementType == FUN && node.isAnonymousFunction(), otherwise -- exception

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we then move it to KdocMethods.kt as private method, because it contains a specific logic for your cases only

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the point. We do not want the developer to try to call this function on a different type of node, In this case, we will not know what to return

package org.cqfn.diktat

fun foo() {
val sum: (Int, Int, Int,) -> Int = fun(
Copy link
Member

@orchestr7 orchestr7 Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add a unit test (at list for checks), even duplicated. Not only smoke is needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

### What's done:
* fixed NullPointerException on KDOC inspection
closes #1334
### What's done:
* fixed NullPointerException on KDOC inspection
closes #1334
### What's done:
* fixed NullPointerException on KDOC inspection
Closes #1331
### What's done:
* fixed NullPointerException on KDOC inspection
Closes #1331
* Checks if a function is anonymous
*/
fun ASTNode.isAnonymousFunction() {
require(this.elementType == FUN)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we then move it to KdocMethods.kt as private method, because it contains a specific logic for your cases only

@Cheshiriks
Copy link
Member Author

This is not quite the correct name of the error. We initially thought that the error was only in the cdoc rules, but it turned out that we didn’t take into account anonymous functions in many places, so it’s wrong to put them only in KdocMethods.kt

### What's done:
* fixed NullPointerException on KDOC inspection
Closes #1331
### What's done:
* fixed NullPointerException on KDOC inspection
Closes #1331
Copy link
Member

@nulls nulls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved after adding a KDoc about expectation

@Cheshiriks Cheshiriks merged commit 92f2fef into master Jun 2, 2022
@Cheshiriks Cheshiriks deleted the bugfix/npe-on-kdoc branch June 2, 2022 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NullPointerException on KDOC inspection
4 participants