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

NPE on consecutive blank lines in end of file with class without body #1987

Closed
Kantis opened this issue May 4, 2023 · 0 comments · Fixed by #1991
Closed

NPE on consecutive blank lines in end of file with class without body #1987

Kantis opened this issue May 4, 2023 · 0 comments · Fixed by #1991
Milestone

Comments

@Kantis
Copy link
Contributor

Kantis commented May 4, 2023

Expected Behavior

Ktlint should report an error of no-consecutive-blank-lines violation

Observed Behavior

NPE

~/workspace > vim dummy.kt                                                                                                                                                                                                                                                                                                                                                                                             48s 16:32:07
~/workspace > ktlint dummy.kt                                                                                                                                                                                                                                                                                                                                                                                           5s 16:32:18
dummy.kt:1:23: Internal Error (rule 'standard:no-consecutive-blank-lines') in dummy.kt at position '1:23. Please create a ticket at https://github.com/pinterest/ktlint/issues and provide the source code that triggered an error.
com.pinterest.ktlint.rule.engine.api.KtLintRuleException: Rule 'standard:no-consecutive-blank-lines' throws exception in file 'dummy.kt' at position (1:23)
   Rule maintainer: KtLint
   Issue tracker  : https://github.com/pinterest/ktlint/issues
   Repository     : https://github.com/pinterest/ktlint
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRule(RuleExecutionContext.kt:64)
	at com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine$lint$3.invoke(KtLintRuleEngine.kt:100)
	at com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine$lint$3.invoke(KtLintRuleEngine.kt:99)
	at com.pinterest.ktlint.rule.engine.internal.VisitorProvider$visitor$3.invoke(VisitorProvider.kt:46)
	at com.pinterest.ktlint.rule.engine.internal.VisitorProvider$visitor$3.invoke(VisitorProvider.kt:44)
	at com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine.lint(KtLintRuleEngine.kt:99)
	at com.pinterest.ktlint.cli.internal.KtlintCommandLine.lint(KtlintCommandLine.kt:542)
	at com.pinterest.ktlint.cli.internal.KtlintCommandLine.process(KtlintCommandLine.kt:467)
	at com.pinterest.ktlint.cli.internal.KtlintCommandLine.access$process(KtlintCommandLine.kt:64)
	at com.pinterest.ktlint.cli.internal.KtlintCommandLine$lintFiles$3.invoke$lambda$0(KtlintCommandLine.kt:416)
	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)
Caused by: java.lang.NullPointerException: Cannot invoke "org.jetbrains.kotlin.com.intellij.lang.ASTNode.getElementType()" because the return value of "org.jetbrains.kotlin.com.intellij.lang.ASTNode.getTreeNext()" is null
	at com.pinterest.ktlint.ruleset.standard.rules.NoConsecutiveBlankLinesRule.isBetweenClassAndPrimaryConstructor(NoConsecutiveBlankLinesRule.kt:65)
	at com.pinterest.ktlint.ruleset.standard.rules.NoConsecutiveBlankLinesRule.beforeVisitChildNodes(NoConsecutiveBlankLinesRule.kt:30)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext$executeRuleOnNodeRecursively$1.invoke(RuleExecutionContext.kt:93)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext$executeRuleOnNodeRecursively$1.invoke(RuleExecutionContext.kt:92)
	at com.pinterest.ktlint.rule.engine.internal.SuppressHandler.handle-dhiVX_g(SuppressHandler.kt:28)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:92)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.access$executeRuleOnNodeRecursively(RuleExecutionContext.kt:29)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext$executeRuleOnNodeRecursively$2$1.invoke(RuleExecutionContext.kt:100)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext$executeRuleOnNodeRecursively$2$1.invoke(RuleExecutionContext.kt:99)
	at com.pinterest.ktlint.rule.engine.internal.SuppressHandler.handle-dhiVX_g(SuppressHandler.kt:28)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRuleOnNodeRecursively(RuleExecutionContext.kt:99)
	at com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext.executeRule(RuleExecutionContext.kt:61)
	... 13 more

Steps to Reproduce

  1. Create a file with just :
sealed class Hello


  1. run ktlint on the file

Your Environment

  • Version of ktlint used: 0.49.0
  • Relevant parts of the .editorconfig settings: None
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): CLI
  • Version of Gradle used (if applicable): N/A
  • Operating System and version: MacOS
paul-dingemans added a commit that referenced this issue May 5, 2023
… by multiple blank lines until end of file

Closes #1987
@paul-dingemans paul-dingemans added this to the 0.49.1 milestone May 5, 2023
paul-dingemans added a commit that referenced this issue May 5, 2023
… by multiple blank lines until end of file (#1991)

Closes #1987
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 a pull request may close this issue.

2 participants