JAL-2724 patch to fix ClassCastException - method should be refactored and tests...