ENT-1903: Isolate the WeakHashMap reference. (#3221)

This commit is contained in:
Chris Rankin 2018-05-23 20:09:57 +01:00 committed by GitHub
parent 356b22fa44
commit 76918de656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -114,14 +114,33 @@ class MapSerializer(private val declaredType: ParameterizedType, factory: Serial
}
internal fun Class<*>.checkSupportedMapType() {
checkHashMap()
checkWeakHashMap()
checkDictionary()
}
private fun Class<*>.checkHashMap() {
if (HashMap::class.java.isAssignableFrom(this) && !LinkedHashMap::class.java.isAssignableFrom(this)) {
throw IllegalArgumentException(
"Map type $this is unstable under iteration. Suggested fix: use java.util.LinkedHashMap instead.")
} else if (WeakHashMap::class.java.isAssignableFrom(this)) {
}
}
/**
* The [WeakHashMap] class does not exist within the DJVM, and so we need
* to isolate this reference.
*/
private fun Class<*>.checkWeakHashMap() {
if (WeakHashMap::class.java.isAssignableFrom(this)) {
throw IllegalArgumentException("Weak references with map types not supported. Suggested fix: "
+ "use java.util.LinkedHashMap instead.")
} else if (Dictionary::class.java.isAssignableFrom(this)) {
}
}
private fun Class<*>.checkDictionary() {
if (Dictionary::class.java.isAssignableFrom(this)) {
throw IllegalArgumentException(
"Unable to serialise deprecated type $this. Suggested fix: prefer java.util.map implementations")
}
}
}