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: EXPOSED-270 Crash when Duration.INFINITE is used for duration column type #1975

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ class KotlinDurationColumnType : ColumnType() {
}

override fun valueFromDB(value: Any): Duration = when (value) {
Duration.INFINITE.inWholeNanoseconds -> Duration.INFINITE
is Long -> value.nanoseconds
is Number -> value.toLong().nanoseconds
is String -> Duration.parse(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,69 @@ class MiscTableTest : DatabaseTestsBase() {
}
}

@Test
fun testInfiniteDuration() {
winkey728 marked this conversation as resolved.
Show resolved Hide resolved
val tbl = Misc
val date = today
val dateTime = now()
val time = dateTime.time
val timestamp = Clock.System.now()
val duration = Duration.INFINITE
val eOne = MiscTable.E.ONE
val dec = BigDecimal("123.45")
withTables(tbl) {
tbl.insert {
it[by] = 7
it[sm] = -2
it[n] = 14
it[c] = "1234"
it[s] = "123456789"
it[d] = date
it[t] = time
it[dt] = dateTime
it[ts] = timestamp
it[dr] = duration
it[e] = eOne
it[es] = eOne
it[dc] = dec
}

val row = tbl.selectAll().where { tbl.dr eq Duration.INFINITE }.single()

tbl.checkRowFull(
row,
by = 7,
byn = null,
sm = -2,
smn = null,
n = 14,
nn = null,
d = date,
dn = null,
t = time,
tn = null,
dt = dateTime,
dtn = null,
ts = timestamp,
tsn = null,
dr = duration,
drn = null,
e = eOne,
en = null,
es = eOne,
esn = null,
c = "1234",
cn = null,
s = "123456789",
sn = null,
dc = dec,
dcn = null,
fcn = null,
dblcn = null
)
}
}

private object ZeroDateTimeTable : Table("zerodatetimetable") {
val id = integer("id")

Expand Down