Scala

Scala

Made by DeepSource

Type T is a potential candidate for type erasure SC-A1004

Bug risk
Critical

Usage of isInstanceOf[] and asInstanceOf[] may or may not lead to bugs depending on whether or not the type T is erased as part of type erasure during the compilation. However, the analyzer has detected that in this case, type T is a potential candidate for type erasure and there is a good chance that the entity's type is actually going to be different during the runtime.

val list1 = List(1, 2, 3)
val list2 = List("a", "b", "c")

In this example, both list1 and list are actually of type List during the runtime and the underlying types of both the lists, Int and String are erased during the type erasure. Although we flag all the instances of isInstanceOf[] and asInstanceOf[], any calls to them with T being a potential candidate for type erasure are flagged as critical.

References