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

Query Results in ClassCastException #369

Closed
commonsguy opened this issue Aug 12, 2018 · 1 comment
Closed

Query Results in ClassCastException #369

commonsguy opened this issue Aug 12, 2018 · 1 comment

Comments

@commonsguy
Copy link

commonsguy commented Aug 12, 2018

Environment:

  • org.jetbrains.exposed:exposed:0.10.4
  • kotlin_version = '1.2.51'

Steps to Reproduce the Problem: Run the unit test in this sample project:

KotlinTextBug.zip

which contains this one test class:

package com.commonsware.bug

import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.transactions.transaction
import org.junit.Before
import org.junit.Test
import java.sql.Connection

object Users : Table("users") {
  val username = text("username")
  val passwordHash = text("password_hash")
}

class ExposedTest {
  @Before
  fun setUp() {
    Database.connect("jdbc:sqlite:../bug.sqlite", "org.sqlite.JDBC")
    TransactionManager.manager.defaultIsolationLevel =
        Connection.TRANSACTION_SERIALIZABLE
  }

  @Test
  fun bcrypt() {
    transaction {
      val user = Users.select { Users.username eq "testuser" }.single()

      assert(user[Users.username].isNotEmpty())
      assert(user[Users.passwordHash].isNotEmpty())
    }
  }
}

Expected Results: for the test to pass

Actual Results: crash when accessing the passwordHash property:

java.lang.ClassCastException: [B cannot be cast to java.lang.CharSequence
	at com.commonsware.bug.ExposedTest$bcrypt$1.invoke(ExposedTest.kt:31)
	at com.commonsware.bug.ExposedTest$bcrypt$1.invoke(ExposedTest.kt:17)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:103)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:74)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:57)
	at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction$default(ThreadLocalTransactionManager.kt:57)
	at com.commonsware.bug.ExposedTest.bcrypt(ExposedTest.kt:27)
       ...

The SQLite database (bug.sqlite in the project root) is not created by Exposed, but instead was created by Ruby and its sqlite3 gem. The table (users) contains a username and a password_hash column. The latter contains a BCrypt hash of a password. Both columns are TEXT, and Exposed can access the username column just fine, but it blows up when trying to access password_hash.

Let me know if you need additional information!

@Tapac
Copy link
Contributor

Tapac commented Aug 15, 2018

Thank you for a report, fixed in master.

@Tapac Tapac closed this as completed Aug 15, 2018
Tapac added a commit that referenced this issue Aug 15, 2018
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

No branches or pull requests

2 participants