JBCTS-1381 Fix potential stack overflow issue