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

EqualsAlwaysReturnsTrueOrFalse crashes on certain input #2103

Closed
lwasyl opened this issue Nov 19, 2019 · 0 comments · Fixed by #2124
Closed

EqualsAlwaysReturnsTrueOrFalse crashes on certain input #2103

lwasyl opened this issue Nov 19, 2019 · 0 comments · Fixed by #2124
Milestone

Comments

@lwasyl
Copy link

lwasyl commented Nov 19, 2019

As title says, for the following file:

data class Item(
    val text: String,
    val onClicked: () -> Unit
) : SuperClass() {

    override fun equals(other: Any?): Boolean = (other as? Item)?.text == this.text
    override fun hashCode(): Int = text.hashCode()
}

Detekt crashes with the following stacktrace:

Analyzing '.../Item.kt' led to an exception.
The original exception message was: java.util.NoSuchElementException: Array is empty.
Running detekt '1.1.1' on Java '1.8.0_222-20190711112007.graal.jdk8u-src-tar-gz-b08' on OS 'Mac OS X'.
If the exception message does not help, please feel free to create an issue on our github page.
java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1592)
java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582)
java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
kotlin.collections.ArraysKt___ArraysKt.first(_Arrays.kt:836)
io.gitlab.arturbosch.detekt.rules.bugs.EqualsAlwaysReturnsTrueOrFalse.isSingleReturnWithBooleanConstant(EqualsAlwaysReturnsTrueOrFalse.kt:67)
io.gitlab.arturbosch.detekt.rules.bugs.EqualsAlwaysReturnsTrueOrFalse.isReturningBooleanConstant(EqualsAlwaysReturnsTrueOrFalse.kt:61)
io.gitlab.arturbosch.detekt.rules.bugs.EqualsAlwaysReturnsTrueOrFalse.visitNamedFunction(EqualsAlwaysReturnsTrueOrFalse.kt:50)
org.jetbrains.kotlin.psi.KtVisitorVoid.visitNamedFunction(KtVisitorVoid.java:483)

3flex pushed a commit that referenced this issue Nov 26, 2019
Fixes an exception that occurs when the equals method contains no
dedicated return expression.
Closes #2103
@arturbosch arturbosch added this to the 1.2.1 milestone Nov 26, 2019
arturbosch pushed a commit that referenced this issue Dec 5, 2019
Fixes an exception that occurs when the equals method contains no
dedicated return expression.
Closes #2103
smyachenkov pushed a commit to smyachenkov/detekt that referenced this issue Dec 9, 2019
Fixes an exception that occurs when the equals method contains no
dedicated return expression.
Closes detekt#2103
smyachenkov pushed a commit to smyachenkov/detekt that referenced this issue Dec 9, 2019
Fixes an exception that occurs when the equals method contains no
dedicated return expression.
Closes detekt#2103
@lock lock bot locked as resolved and limited conversation to collaborators Mar 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants