saveourtool / diktat

Strict coding standard for Kotlin and a custom set of rules for detecting code smells, code style issues and bugs
https://diktat.saveourtool.com
MIT License
537 stars 39 forks source link

index out of bounds #1139

Open reberthkss opened 2 years ago

reberthkss commented 2 years ago

Describe the bug

This error occur when executing spotlessApply task

Expected behavior

Complete the spotlessApplytask

Observed behavior

View stack trace ``` Step 'diktat' found problem in 'src/main/kotlin/br/com/rico/mobile/extract/presentation/ExtractActivity.kt': java.lang.IndexOutOfBoundsException: Index: 27, Size: 27 com.pinterest.ktlint.core.RuleExecutionException: java.lang.IndexOutOfBoundsException: Index: 27, Size: 27 at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:285) at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:23) at com.pinterest.ktlint.core.KtLint$visitor$2$2.invoke(KtLint.kt:212) at com.pinterest.ktlint.core.KtLint$visitor$2$2.invoke(KtLint.kt:23) at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:224) at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:225) at com.pinterest.ktlint.core.ast.PackageKt.visit(package.kt:225) at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:211) at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:23) at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:264) at sun.reflect.GeneratedMethodAccessor2695.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.diffplug.spotless.kotlin.DiktatStep$State.lambda$createFormat$1(DiktatStep.java:163) at com.diffplug.spotless.FormatterFunc$NeedsFile.apply(FormatterFunc.java:154) at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:78) at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:76) at com.diffplug.spotless.Formatter.compute(Formatter.java:230) at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:201) at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:188) at com.diffplug.gradle.spotless.SpotlessTaskImpl.processInputFile(SpotlessTaskImpl.java:88) at com.diffplug.gradle.spotless.SpotlessTaskImpl.performAction(SpotlessTaskImpl.java:74) at sun.reflect.GeneratedMethodAccessor1546.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104) at org.gradle.api.internal.project.taskfactory.IncrementalInputsTaskAction.doExecute(IncrementalInputsTaskAction.java:32) at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:42) at org.gradle.api.internal.project.taskfactory.AbstractIncrementalTaskAction.execute(AbstractIncrementalTaskAction.java:25) at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:28) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.run(ExecuteActionsTaskExecuter.java:568) at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402) at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394) at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165) at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250) at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158) at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92) at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:553) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:536) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$300(ExecuteActionsTaskExecuter.java:109) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.executeWithPreviousOutputFiles(ExecuteActionsTaskExecuter.java:276) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:265) at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$0(ExecuteStep.java:32) at java.util.Optional.map(Optional.java:215) at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:32) at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:26) at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:63) at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:35) at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:49) at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:34) at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:43) at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:73) at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:54) at org.gradle.internal.execution.steps.CatchExceptionStep.execute(CatchExceptionStep.java:34) at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:44) at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:54) at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:38) at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:49) at org.gradle.internal.execution.steps.CacheStep.executeWithoutCache(CacheStep.java:153) at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:67) at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:41) at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:44) at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:33) at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:38) at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:24) at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:92) at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:85) at java.util.Optional.map(Optional.java:215) at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:55) at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:39) at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:76) at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:37) at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36) at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26) at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:94) at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:49) at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:79) at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:53) at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:74) at org.gradle.internal.execution.steps.SkipEmptyWorkStep.lambda$execute$2(SkipEmptyWorkStep.java:78) at java.util.Optional.orElseGet(Optional.java:267) at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:78) at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:34) at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:39) at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:40) at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:28) at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:192) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:184) at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:109) at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46) at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:62) at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57) at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56) at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52) at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416) at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406) at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165) at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250) at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158) at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102) at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52) at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:41) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:372) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:359) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:352) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:338) at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127) at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191) at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182) at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64) at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IndexOutOfBoundsException: Index: 27, Size: 27 at java.util.ArrayList.rangeCheck(ArrayList.java:659) at java.util.ArrayList.get(ArrayList.java:435) at org.cqfn.diktat.ruleset.rules.chapter3.ClassLikeStructuresOrderRule.checkDeclarationsOrderInClass(ClassLikeStructuresOrderRule.kt:103) at org.cqfn.diktat.ruleset.rules.chapter3.ClassLikeStructuresOrderRule.visit(ClassLikeStructuresOrderRule.kt:56) at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:271) ... 121 more ```

Steps to Reproduce

1 - Implement spotless configuration with given config:

View diktat config ``` - name: DIKTAT_COMMON configuration: # put your package name here - it will be autofixed and checked domainName: your.name.here testDirs: test # expected values: disabledChapters: "Naming, Comments, General, Variables, Functions, Classes" # or: "1, 2, 3, 4, 5, 6" disabledChapters: "" kotlinVersion: 1.5 srcDirectories: "main" - name: CONFUSING_IDENTIFIER_NAMING enabled: false - name: LONG_LINE enabled: false - name: LOCAL_VARIABLE_EARLY_DECLARATION enabled: false - name: FILE_WILDCARD_IMPORTS enabled: false - name: TOO_LONG_FUNCTION enabled: false - name: MISSING_KDOC_TOP_LEVEL enabled: false - name: MISSING_KDOC_ON_FUNCTION enabled: false - name: MISSING_KDOC_CLASS_ELEMENTS enabled: false - name: EMPTY_BLOCK_STRUCTURE_ERROR enabled: false - name: FLOAT_IN_ACCURATE_CALCULATIONS enabled: false - name: GENERIC_VARIABLE_WRONG_DECLARATION enabled: false - name: HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE enabled: false - name: TYPE_ALIAS enabled: false - name: TOO_MANY_LINES_IN_LAMBDA enabled: false - name: IDENTIFIER_LENGTH enabled: false - name: TOO_MANY_PARAMETERS enabled: false - name: STRING_CONCATENATION enabled: false - name: SAY_NO_TO_VAR enabled: false - name: CUSTOM_GETTERS_SETTERS enabled: false - name: KDOC_NO_EMPTY_TAGS enabled: false - name: KDOC_TRIVIAL_KDOC_ON_FUNCTION enabled: false - name: KDOC_WITHOUT_PARAM_TAG enabled: false - name: KDOC_TRIVIAL_KDOC_ON_FUNCTION enabled: false - name: INLINE_CLASS_CAN_BE_USED enabled: false - name: WRONG_NEWLINES enabled: false - name: VARIABLE_NAME_INCORRECT_FORMAT enabled: false - name: INLINE_CLASS_CAN_BE_USED enabled: false - name: LAMBDA_IS_NOT_LAST_PARAMETER enabled: false - name: FILE_NAME_INCORRECT enabled: false - name: COMPLEX_EXPRESSION enabled: false - name: FUNCTION_BOOLEAN_PREFIX enabled: false - name: FILE_NAME_MATCH_CLASS enabled: false - name: WRONG_NEWLINES_AROUND_KDOC enabled: false - name: WRONG_OVERLOADING_FUNCTION_ARGUMENTS enabled: false - name: NO_BRACES_IN_CONDITIONALS_AND_LOOPS enabled: false - name: NESTED_BLOCK enabled: false ```
View Spotless config ``` apply from: "$rootProject.projectDir/dependencies.gradle" configurations { spotless } android { lintOptions { abortOnError false } } apply plugin: 'com.diffplug.spotless' spotless { enforceCheck false ratchetFrom 'origin/develop' kotlin { target '**/*.kt' targetExclude("$buildDir/**/*.kt") targetExclude('bin/**/*.kt') diktat().configFile("$rootDir/filters/diktat.yml") licenseHeaderFile(rootProject.file('spotless/copyright.txt'), '(package|//)') } groovyGradle { target '*.gradle' } } ```

Environment information

orchestr7 commented 2 years ago

Hi! thank you for your report. Sorry for a long response, we were all busy with regular work 😢 We tried to investigate this, but it looks like Spotless is using some old version of diktat and it was fixed.

We will continue investigation and will return to you

orchestr7 commented 2 years ago

@reberthkss Is there any chance to reproduce it with latest diktat? You can check it online: https://ktlint-demo.herokuapp.com/

Will be also great if you will provide the code, that triggers an error...

reberthkss commented 2 years ago

hey @akuleshov7! Thanks for your effort. I will try again soon and maybe come with some code samples.