Fix Class Cast Exception on some generics types
(cherry picked from commit 6ead000)
Fix Class Cast Exception on some generics types
(cherry picked from commit 8540ab3)