I think the issue here is that, somehow, the path you're getting passed is sometimes a URL and sometimes an OS path.  Each of these APIs works correctly across all platforms when given the type of string it's designed to be used for, but since the type of string varies by platform we need to call both.  Might want to tweak the comment a bit -- as is it sort of suggests one or both of these APIs is unreliable.