Allow setting seed only once, as it is set from superclass constructor

Add tests for Java<->Kotlin Random wrappers.

#KT-29520 Fixed
This commit is contained in:
Ilya Gorbunov
2019-02-10 20:23:18 +03:00
parent 4d0261fc45
commit f50820045a
2 changed files with 61 additions and 1 deletions
@@ -75,7 +75,13 @@ private class KotlinRandom(val impl: Random) : java.util.Random() {
impl.nextBytes(bytes)
}
private var seedInitialized: Boolean = false
override fun setSeed(seed: Long) {
throw UnsupportedOperationException("Setting seed is not supported.")
if (!seedInitialized) {
// ignore seed value from constructor
seedInitialized = true
} else {
throw UnsupportedOperationException("Setting seed is not supported.")
}
}
}