File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
kotlinx-coroutines-core/jvm Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,6 @@ internal actual class JobCancellationException public actual constructor(
61
61
override fun equals (other : Any? ): Boolean =
62
62
other == = this ||
63
63
other is JobCancellationException && other.message == message && other.job == job && other.cause == cause
64
- override fun hashCode (): Int =
65
- (message!! .hashCode() * 31 + job.hashCode()) * 31 + (cause?.hashCode() ? : 0 )
64
+ override fun hashCode (): Int = /* since job is transient it is indeed nullable after deserialization */
65
+ (message!! .hashCode() * 31 + ( job? .hashCode() ? : 0 )) * 31 + (cause?.hashCode() ? : 0 )
66
66
}
Original file line number Diff line number Diff line change @@ -36,4 +36,31 @@ class JobCancellationExceptionSerializerTest : TestBase() {
36
36
finish(4 )
37
37
}
38
38
}
39
+
40
+ @Test
41
+ fun testHashCodeAfterDeserialization () = runTest {
42
+ try {
43
+ coroutineScope {
44
+ val job = launch {
45
+ hang {}
46
+ }
47
+ throw JobCancellationException (
48
+ message = " Job Cancelled" ,
49
+ job = job,
50
+ cause = null ,
51
+ )
52
+ }
53
+ } catch (e: Throwable ) {
54
+ val outputStream = ByteArrayOutputStream ()
55
+ ObjectOutputStream (outputStream).use {
56
+ it.writeObject(e)
57
+ }
58
+ val deserializedException =
59
+ ObjectInputStream (outputStream.toByteArray().inputStream()).use {
60
+ it.readObject() as JobCancellationException
61
+ }
62
+ // verify hashCode does not fail even though Job is transient
63
+ assert (deserializedException.hashCode() != 0 )
64
+ }
65
+ }
39
66
}
You can’t perform that action at this time.
0 commit comments