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

NoSuchElementException after updating to 1.20.0-RC1 #4604

Closed
eygraber opened this issue Mar 1, 2022 · 5 comments
Closed

NoSuchElementException after updating to 1.20.0-RC1 #4604

eygraber opened this issue Mar 1, 2022 · 5 comments

Comments

@eygraber
Copy link
Contributor

eygraber commented Mar 1, 2022

Just tried out 1.20.0-RC1 and got a few of these exceptions:

java.lang.IllegalStateException: Analyzing /home/eli/workspace/myapp/app/src/main/kotlin/co/app/common/AppInfo.kt led to an exception. 
  The original exception message was: java.util.NoSuchElementException: Sequence contains no element matching the predicate.
  Running detekt '1.20.0-RC1' on Java '17.0.2+8-LTS' on OS 'Linux'

Here is AppInfo.kt:

package co.app.common

import co.app.coroutines.flow.conflatedSharedFlow
import kotlinx.coroutines.flow.first

interface AppInfo {
  val versionName: String
  val versionCode: Int

  val playStorePackage: String

  val osVersion: Int

  val appVersion: String

  var suggestedVersion: String?
  suspend fun awaitSuggestedVersionChanged(): String

  fun isAppBelowSuggestedVersion(suggestedVersion: String?): Boolean
}

internal class AppInfoImpl(
  appVersionName: String,
  appVersionCode: Int,
  appPackageName: String,
  currentOsVersion: Int
) : AppInfo {
  override val versionName = appVersionName

  override val versionCode = appVersionCode

  override val playStorePackage = appPackageName

  override val osVersion = currentOsVersion

  override val appVersion = "a${versionName.removeSuffix("-DEBUG")}.0"

  private val suggestedVersionFlow = conflatedSharedFlow<String>()

  override var suggestedVersion: String? = null
    set(value) {
      field = value
      if(value != null) {
        suggestedVersionFlow.tryEmit(value)
      }
    }

  override suspend fun awaitSuggestedVersionChanged(): String = suggestedVersionFlow.first()

  override fun isAppBelowSuggestedVersion(suggestedVersion: String?): Boolean {
    tailrec fun isAppBelowSuggested(current: List<Int>, suggested: List<Int>, index: Int): Boolean =
      when {
        index >= current.size -> false

        current[index] != suggested[index] -> current[index] < suggested[index]

        else -> isAppBelowSuggested(current, suggested, index + 1)
      }

    return suggestedVersion?.let {
      val currentVersion = versionName.removeSuffix("-DEBUG")

      when(suggestedVersion) {
        currentVersion -> false

        else -> {
          val currentVersionSplit = currentVersion.split(".").mapNotNull { it.toIntOrNull() }
          val suggestedVersionSplit = suggestedVersion.split(".").mapNotNull { it.toIntOrNull() }

          when {
            currentVersionSplit.size != 3 || suggestedVersionSplit.size != 3 -> false

            else -> isAppBelowSuggested(currentVersionSplit, suggestedVersionSplit, index = 0)
          }
        }
      }
    } ?: false
  }
}

@eygraber eygraber added the bug label Mar 1, 2022
@BraisGabin
Copy link
Member

Do you have the stacktrace?

@eygraber
Copy link
Contributor Author

eygraber commented Mar 2, 2022

Caused by: java.util.NoSuchElementException: Sequence contains no element matching the predicate.
        at com.pinterest.ktlint.ruleset.experimental.trailingcomma.TrailingCommaRule.visitValueList(TrailingCommaRule.kt:357)
        at com.pinterest.ktlint.ruleset.experimental.trailingcomma.TrailingCommaRule.visit(TrailingCommaRule.kt:61)
        at io.gitlab.arturbosch.detekt.formatting.FormattingRule.apply(FormattingRule.kt:80)
        at io.gitlab.arturbosch.detekt.formatting.KtLintMultiRule$visit$2.invoke(KtLintMultiRule.kt:114)
        at io.gitlab.arturbosch.detekt.formatting.KtLintMultiRule$visit$2.invoke(KtLintMultiRule.kt:113)
        at io.gitlab.arturbosch.detekt.formatting.KtLintMultiRule.visitTokens(KtLintMultiRule.kt:142)
        at io.gitlab.arturbosch.detekt.formatting.KtLintMultiRule.visitTokens(KtLintMultiRule.kt:144)
        at io.gitlab.arturbosch.detekt.formatting.KtLintMultiRule.visitTokens(KtLintMultiRule.kt:144)
        at io.gitlab.arturbosch.detekt.formatting.KtLintMultiRule.visitTokens(KtLintMultiRule.kt:144)
        at io.gitlab.arturbosch.detekt.formatting.KtLintMultiRule.visit(KtLintMultiRule.kt:113)
        at io.gitlab.arturbosch.detekt.api.BaseRule.visitFile(BaseRule.kt:46)
        at io.gitlab.arturbosch.detekt.core.Analyzer.analyze$executeRules(Analyzer.kt:122)
        at io.gitlab.arturbosch.detekt.core.Analyzer.analyze(Analyzer.kt:133)
        at io.gitlab.arturbosch.detekt.core.Analyzer.access$analyze(Analyzer.kt:31)
        at io.gitlab.arturbosch.detekt.core.Analyzer$runAsync$tasks$1$1.invoke(Analyzer.kt:85)
        at io.gitlab.arturbosch.detekt.core.Analyzer$runAsync$tasks$1$1.invoke(Analyzer.kt:83)
        at io.gitlab.arturbosch.detekt.core.TaskPoolKt.task$lambda-0(TaskPool.kt:12)
        at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)

@eygraber
Copy link
Contributor Author

eygraber commented Mar 10, 2022

FYI, you may want to wait for the next ktlint release with pinterest/ktlint#1280

#2398 (comment)

@cortinico
Copy link
Member

Yup we'll have to do #4584 this manually and make sure it lands inside 1.20.0

@BraisGabin
Copy link
Member

I think that we can close this now that #4630 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants