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

Fix error on formatting annotation for primary constructor #628

Merged

Conversation

yukukotani
Copy link
Contributor

Resolve #625

Fix error on formatting annotation for primary constructor.

Current

Formatting following code causes the error.

class Foo @Inject internal constructor()
com.pinterest.ktlint.core.RuleExecutionException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:384)
	at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:41)
	at com.pinterest.ktlint.core.KtLint$visitor$2$2.invoke(KtLint.kt:279)
	at com.pinterest.ktlint.core.KtLint$visitor$2$2.invoke(KtLint.kt:41)
	at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:536)
	at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:537)
	at com.pinterest.ktlint.core.KtLint.visit(KtLint.kt:537)
	at com.pinterest.ktlint.core.KtLint.access$visit(KtLint.kt:41)
	at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:278)
	at com.pinterest.ktlint.core.KtLint$visitor$2.invoke(KtLint.kt:41)
	at com.pinterest.ktlint.core.KtLint.format(KtLint.kt:367)
	at com.pinterest.ktlint.internal.FileUtilsKt.formatFile(FileUtils.kt:79)
	at com.pinterest.ktlint.KtlintCommandLine$run$1.invoke(Main.kt:240)
	at com.pinterest.ktlint.KtlintCommandLine$run$4$1.call(Main.kt:306)
	at com.pinterest.ktlint.KtlintCommandLine$run$4$1.call(Main.kt:115)
	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.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(String.java:1929)
	at com.pinterest.ktlint.ruleset.experimental.AnnotationRule.visit(AnnotationRule.kt:97)
	at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:372)
	... 18 more

Patched

Format without any errors.

class Foo @Inject internal constructor()

@shashachu shashachu merged commit 8d4ebca into pinterest:master Oct 29, 2019
@shashachu
Copy link
Contributor

thank you!

@sonahovhannisyan
Copy link

Hi @monchi. Might you know when this fix will be shipped?

@yukukotani
Copy link
Contributor Author

yukukotani commented Nov 25, 2019

@sonahovhannisyan
Hi, I'm afraid I don't know because i'm not a maintainer but just one of the contributors.
Maybe @shashachu or @Tapchicoma knows something about that.

@sonahovhannisyan
Copy link

Ah ok, thanks @monchi. Let's wait to hear from them then.

@Tapchicoma
Copy link
Collaborator

I suppose it will happen this week.

@yukukotani yukukotani deleted the feature/fix-annotation-format-error branch November 26, 2019 09:00
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.

Experimental AnnotationRule crashes on format
4 participants