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

experimental:annotation crash during formatting #868

Closed
shashachu opened this issue Aug 27, 2020 · 5 comments
Closed

experimental:annotation crash during formatting #868

shashachu opened this issue Aug 27, 2020 · 5 comments
Labels
Milestone

Comments

@shashachu
Copy link
Contributor

shashachu commented Aug 27, 2020

Observed Behavior

com.pinterest.ktlint.core.RuleExecutionException: java.lang.IndexOutOfBoundsException: Wrong offset: 29566. Should be in range: [0, 29472]
	at com.pinterest.ktlint.core.KtLint$format$2.invoke(KtLint.kt:386)
	at com.pinterest.ktlint.core.KtLint$format$2.invoke(KtLint.kt:43)
	at com.pinterest.ktlint.core.KtLint$visitor$2$1.invoke(KtLint.kt:248)
	at com.pinterest.ktlint.core.KtLint$visitor$2$1.invoke(KtLint.kt:43)
	at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:574)
	at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:575)
	at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:575)
	at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:575)
	at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:575)
	at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:575)
	at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:575)
	at com.pinterest.ktlint.core.KtLint.access$visit(KtLint.kt:43)
	at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:246)
	at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:43)
	at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:371)
	at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:79)
	at com.pinterest.ktlint.KtlintCommandLine.process(Main.kt:331)
	at com.pinterest.ktlint.KtlintCommandLine.access$process(Main.kt:116)
	at com.pinterest.ktlint.KtlintCommandLine$lintFiles$2$1.call(Main.kt:257)
	at com.pinterest.ktlint.KtlintCommandLine$lintFiles$2$1.call(Main.kt:116)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IndexOutOfBoundsException: Wrong offset: 29566. Should be in range: [0, 29472]
	at org.jetbrains.kotlin.com.intellij.openapi.editor.impl.LineSet.findLineIndex(LineSet.java:178)
	at org.jetbrains.kotlin.com.intellij.openapi.editor.impl.DocumentImpl.getLineNumber(DocumentImpl.java:991)
	at com.pinterest.ktlint.core.ast.PackageKt.lineNumber(package.kt:235)
	at com.pinterest.ktlint.ruleset.experimental.AnnotationRule.visit(AnnotationRule.kt:149)
	at com.pinterest.ktlint.core.KtLint$format$2.invoke(KtLint.kt:376)

Steps to Reproduce

package a.b.c

class Test {
    fun bloop() {
        asdfadsf(asdfadsf, asdfasdf, asdfasdfasdfads,
        asdfasdf, asdfasdf, asdfasdf)
    }

    @Blah
    val test: Int
}

Your Environment

  • Version of ktlint used: 0.38.1

Introduced in 4dda69b

@shashachu shashachu added the bug label Aug 27, 2020
@shashachu
Copy link
Contributor Author

This appears to not play well with other rules (in this case parameter wrapping) that change the number of lines in the file.

@AdamMTGreenberg
Copy link
Contributor

I can take this on and adapt it tonight

@shashachu shashachu added this to the 0.39.0 milestone Aug 29, 2020
@AdamMTGreenberg
Copy link
Contributor

Sorry for the delay - weekend got away from me, hoping to work on this tomorrow

@AdamMTGreenberg
Copy link
Contributor

@shashachu when I add the base test provided, it does not seem to fail - please see: #880

I think the underlying issue is the code above as you pointed out AnnotationRule.visit has me a bit troubled and I think I'm trying to do too much in a single rule, so I feel as if the best path forward is most likely splitting the multi-line rule and auto fix out into its own rule.

shashachu pushed a commit that referenced this issue Sep 11, 2020
* Moving the multi line fixes out to a seperate rule so that we can ensure we aren't doing strange stuff cloning nodes, etc

* Move all the multi line tests to the new rule class to ensure the rule is adapted

* Fixing the unit tests since there was a missing commit somehow in the historical section

* Add the multiline to the RuleSetProvider

* Linting all at once

* Fixing lint issues

* We are able to achieve the same results without the line number checks

* Accidental line delete

* Updated the naming to match the suggestions from code review:

"Maybe a more descriptive name would be 'annotation-spacing' or something similar?"

* Unsure how this passed successfully before, but adapting it to make sure it is only triggering the correct errors for the test and not something with the annotation line rule
shashachu added a commit to shashachu/ktlint that referenced this issue Sep 11, 2020
* Added rule ids into README (pinterest#879)
* Added changelog entry for pinterest#868
@shashachu
Copy link
Contributor Author

Should be fixed by #881

shashachu added a commit that referenced this issue Sep 14, 2020
* Small doc updates
* Added rule ids into README (#879)
* Added changelog entry for #868

* add note about missing PGP signatures

* - Added one more fix for the release, updated info on signature verification
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants