why do we need all this complex logic, why is this simply not targetUri.getPath().endsWith("/") ?