Check if tree path exists before using it. Fixes REDMINE-8