Fix ClassCastException in ThunkSource

* and add test