backport fix for ROOT-6927 from master