BZ-991058: protecting code execution on custom accumulates. Adding test cases.
(cherry picked from commit ab04723de2eeefe43b822563e793ee42ca0fd500)