-
Notifications
You must be signed in to change notification settings - Fork 39
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 in NewlinesRule: #1050
NPE in NewlinesRule: #1050
Changes from 1 commit
c16fbfe
847dd89
23f76da
32b0037
bb087ee
d802760
3616efb
f68ac35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -527,6 +527,18 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) { | |||||
) | ||||||
} | ||||||
|
||||||
@Test | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create fixer tests (where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Cheshiriks where are tests for fixers? |
||||||
@Tag(WarningNames.WRONG_NEWLINES) | ||||||
fun `should warn for array access expression`() { | ||||||
lintMethod( | ||||||
""" | ||||||
|fun bar(): String { | ||||||
| val a = it.responseBody!!.name | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code basically didn't trigger an NPE before
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I removed this for a test and forgot to return |
||||||
|} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add positive scenarios (that will trigger warnings) |
||||||
""".trimMargin() | ||||||
) | ||||||
} | ||||||
|
||||||
@Test | ||||||
@Tag(WarningNames.WRONG_NEWLINES) | ||||||
fun `long argument list should be split into several lines - positive example`() { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that just workaround?
I looked at this bug before and think, that the main problem is in these lines:
https://github.com/cqfn/diKTat/blob/37b2478924f69d9f4be205bc46a2a12bbed89fb8/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt#L469-L471
For now I didn't catch the logic of this
if
statement - in which cases do we need this, even more it doesn't covered by any test.Probably, we should modify it or get rid of it at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I deleted this piece and. everything continued to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should work, however did you understand the reason, why did we need this before, for which cases?
I can't imagine any other examples for now, which will satisfy this condition, instead of
it.responseBody!![0].name
, for which it doesn't workThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't get how it should fix anything?
If we had an NPE on the further manipulations
val firstChild
orpsi.firstChild
, you should do null-checks and create special logic for it. Not simply hardcodeARRAY_ACCESS_EXPRESSION