Fixing Problems with ClassCast Exception - TRUNK-4053(cherry picked from commit 1850c17f0d1cb437ee26ff9d0dde9cc1b1c1d706)