JD.CAST.UPCAST is triggered when an object is checked with an instance of operator for type A and than cast to type B, where B is a subtype of type A.

Vulnerability and risk

This is usually an error, because the cast is not safe, the object can actually be another subtype of A. In some cases, this error can produce false positives when the path from the instanceof to the cast is incompatible.

Example 1

14     void setValue(Object a, Object value) {
15         if (a instanceof Map) {
16             HashMap b = (HashMap) a;
17             b.put(value, "");
18         } else if (a instanceof List) {
19             List b = (List) a;
20             b.add(value);
21         }
22     }

JD.CAST.UPCAST: Suspicious cast of 'a' to 'HashMap', where 'HashMap' is a subtype of 'Map'. This object can hold other subtypes of 'Map' which can cause a ClassCastException.-> 15: a instanceof Map-> 16: (HashMap)a