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

WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES issue #1516

Closed
sanyavertolet opened this issue Sep 5, 2022 · 0 comments · Fixed by #1519
Closed

WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES issue #1516

sanyavertolet opened this issue Sep 5, 2022 · 0 comments · Fixed by #1519
Assignees
Labels
bug Something isn't working
Milestone

Comments

@sanyavertolet
Copy link
Member

sanyavertolet commented Sep 5, 2022

Describe the bug

After I try to run diktatFix of grade-plugin on a simple file (simplified example is in Steps to reproduce section) I get stack trace:

 ERROR org.cqfn.diktat.ruleset.rules.DiktatRule - Internal error has occurred in rule [class-like-structures]. Please make an issue on this bug at https://github.com/saveourtool/diKTat/.
                       As a workaround you can disable these inspections in yml config: <[BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES]>.
                       Root cause of the problem is in [/Users/sanyavertolet/StudioProjects/iomt-android1/app/src/main/java/com/iomt/android/SignupActivity.kt] file.
java.lang.IndexOutOfBoundsException: Index 7 out of bounds for length 7
        at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
        at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
        at java.base/java.util.Objects.checkIndex(Objects.java:359)
        at java.base/java.util.ArrayList.get(ArrayList.java:427)
        at org.cqfn.diktat.ruleset.rules.chapter3.ClassLikeStructuresOrderRule.checkAndReorderBlocks(ClassLikeStructuresOrderRule.kt:141)
        at org.cqfn.diktat.ruleset.rules.chapter3.ClassLikeStructuresOrderRule.checkDeclarationsOrderInClass(ClassLikeStructuresOrderRule.kt:80)
        at org.cqfn.diktat.ruleset.rules.chapter3.ClassLikeStructuresOrderRule.logic(ClassLikeStructuresOrderRule.kt:53)
        at org.cqfn.diktat.ruleset.rules.DiktatRule.visit(DiktatRule.kt:52)
        at org.cqfn.diktat.ruleset.rules.OrderedRuleSet$Companion$OrderedRule.visit(OrderedRuleSet.kt:80)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:251)
        at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:244)
        at com.pinterest.ktlint.core.internal.VisitorProvider$sequentialVisitor$1$1$1$1.invoke(VisitorProvider.kt:123)
        at com.pinterest.ktlint.core.internal.VisitorProvider$sequentialVisitor$1$1$1$1.invoke(VisitorProvider.kt:123)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:236)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:237)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:237)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:237)
        at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:237)
        at com.pinterest.ktlint.core.internal.VisitorProvider$sequentialVisitor$1.invoke(VisitorProvider.kt:123)
        at com.pinterest.ktlint.core.internal.VisitorProvider$sequentialVisitor$1.invoke(VisitorProvider.kt:115)
        at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:244)
        at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:202)
        at com.pinterest.ktlint.internal.KtlintCommandLine.process(KtlintCommandLine.kt:355)
        at com.pinterest.ktlint.internal.KtlintCommandLine.access$process(KtlintCommandLine.kt:48)
        at com.pinterest.ktlint.internal.KtlintCommandLine$lintFiles$3.invoke$lambda-1(KtlintCommandLine.kt:274)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)

Expected behavior

Given code should be formatted like that:

class ClassName {

    companion object {
        private const val EMAIL_ERROR_TEXT = "Введите корректно e-mail"
        private const val LOGIN_ERROR_TEXT = "Не менее 2 символов"
        private const val NAME_ERROR_TEXT = "Не менее 2 символов"
        private const val PATRONYMIC_ERROR_TEXT = "Не менее 2 символов"
        private const val PHONE_NUMBER_ERROR_TEXT = "Введите корректно номер телефона"
        private const val SURNAME_ERROR_TEXT = "Не менее 2 символов"
        private const val TAG = "SignupActivity"
    }
}

Observed behavior

Stack trace (you can find it above)

Steps to Reproduce

Run diktatFix task of grade-plugin on this code snippet:

class ClassName {

    companion object {
        private const val TAG = "SignupActivity"

        private const val NAME_ERROR_TEXT = "Не менее 2 символов"
        private const val SURNAME_ERROR_TEXT = "Не менее 2 символов"
        private const val PATRONYMIC_ERROR_TEXT = "Не менее 2 символов"

        private const val LOGIN_ERROR_TEXT = "Не менее 2 символов"
        private const val EMAIL_ERROR_TEXT = "Введите корректно e-mail"
        private const val PHONE_NUMBER_ERROR_TEXT = "Введите корректно номер телефона"
    }
}

Environment information

  • diktat version: diktat 1.2.1 with ktlint 0.46.1
  • build tool (maven/gradle): gradle
  • how is diktat run (CLI, plugin, etc.): gradle plugin
  • kotlin version: 1.6.20-M1
  • operating system: macOS Monterey v.12.3.1

upd: Same issue exists when running diktatCheck

@sanyavertolet sanyavertolet added the bug Something isn't working label Sep 5, 2022
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 added this to the 1.2.4 milestone Sep 12, 2022
0x6675636b796f75676974687562 added a commit that referenced this issue Sep 12, 2022
### What's done:

 * `const` properties named `log` or `logger` are no longer treated as loggers.
 * `lateinit` properties named `log` or `logger` are no longer treated as
   loggers.
 * Arbitrary properties containing `log` or `logger` in their names
   (e.g.: `loginName` or `LOGIN_NAME`) are no longer treated as loggers.
 * A diagnostic check added.
 * An IOOBE is no longer thrown.
 * Closes #1516.
0x6675636b796f75676974687562 added a commit that referenced this issue Sep 12, 2022
### What's done:

 * `const` properties named `log` or `logger` are no longer treated as loggers.
 * `lateinit` properties named `log` or `logger` are no longer treated as
   loggers.
 * Arbitrary properties containing `log` or `logger` in their names
   (e.g.: `loginName` or `LOGIN_NAME`) are no longer treated as loggers.
 * A diagnostic check added.
 * An IOOBE is no longer thrown.
 * Closes #1516.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants