JetBrains / Exposed

Kotlin SQL Framework
http://jetbrains.github.io/Exposed/
Apache License 2.0
8.28k stars 690 forks source link

fix: EXPOSED-270 Crash when `Duration.INFINITE` is used for duration column type #1975

Closed winkey728 closed 8 months ago

winkey728 commented 8 months ago

Fix EXPOSED-270.

Exposed converts Duration to its nanoseconds value when writing to database, and uses the kotlin Long.nanoseconds function to convert Long to Duration when reading from database. If inserting the Duration.INFINITE value, the saving value in database is 9223372036854775807(Long.MAX_VALUE). However, the kotlin Long.nanoseconds function checks Long.MAX_VALUE exceeding the nanosecond range and then converts it to millisecond unit, causing the ignoring of last few digits of the value. Therefore, the reading value does not equal to Duration.INFINITE anymore.

This bug can be fixed by first checking the equality of the value and Duration.INFINITE.inWholeNanoseconds, then return Duration.INFINITE directly if equals.