Source:
<code>private void checkPathOwnerAndPermission(String clusterName, String location, FileSystem fs, FsPermission expectedPermission, Boolean exactPerms) throws IOException, ValidationException { Path locationPath = new Path(location); if (!fs.exists(locationPath)) { throw new ValidationException("Location " + location + " for cluster " + clusterName + " must exist."); } final String loginUser = UserGroupInformation.getLoginUser().getShortUserName(); FileStatus fileStatus = fs.getFileStatus(locationPath); final String locationOwner = fileStatus.getOwner(); if (!locationOwner.equals(loginUser)) { LOG.error("Location has owner {}, should be the process user {}", locationPath, locationOwner, loginUser); throw new ValidationException( "Path [" + locationPath + "] has owner [" + locationOwner + "], should be the process user " + loginUser); } if (exactPerms) { if (fileStatus.getPermission().toShort() != expectedPermission.toShort()) { LOG.error("Location has permissions {}, should be {}", locationPath, fileStatus.getPermission(), expectedPermission); throw new ValidationException( "Path " + locationPath + " has permissions: " + fileStatus.getPermission() + ", should be " + expectedPermission); } } else { if (fileStatus.getPermission().toShort() < expectedPermission.toShort()) { <START> LOG.error("Location has permissions {}, should be {}", locationPath, fileStatus.getPermission(), <END> expectedPermission); throw new ValidationException( "Path " + locationPath + " has permissions: " + fileStatus.getPermission() + ", should be " + expectedPermission); } } fs.listStatus(locationPath); }</code><technical_language>If logging throwing exception similar message. Create message re-use save a redundant lines of code</technical_language>

Target:
private void checkPathOwnerAndPermission(String clusterName, String location, FileSystem fs, FsPermission expectedPermission, Boolean exactPerms) throws ValidationException { Path locationPath = new Path(location); try { if (!fs.exists(locationPath)) { throw new ValidationException("Location " + location + " for cluster " + clusterName + " must exist."); } final String loginUser = UserGroupInformation.getLoginUser().getShortUserName(); FileStatus fileStatus = fs.getFileStatus(locationPath); final String locationOwner = fileStatus.getOwner(); if (!locationOwner.equals(loginUser)) { LOG.error("Location has owner {}, should be the process user {}", locationPath, locationOwner, loginUser); throw new ValidationException( "Path [" + locationPath + "] has owner [" + locationOwner + "], should be the process user " + loginUser); } String errorMessage = "Path " + locationPath + " has permissions: " + fileStatus.getPermission().toString() + ", should be " + expectedPermission; if (exactPerms) { if (fileStatus.getPermission().toShort() != expectedPermission.toShort()) { LOG.error(errorMessage); throw new ValidationException(errorMessage); } } else { if (expectedPermission.getUserAction().ordinal() > fileStatus.getPermission().getUserAction() .ordinal()) { LOG.error(errorMessage + " at least"); throw new ValidationException(errorMessage + " at least"); } if (expectedPermission.getGroupAction().ordinal() > fileStatus.getPermission().getGroupAction() .ordinal()) { LOG.error(errorMessage + " at least"); throw new ValidationException(errorMessage + " at least"); } if (expectedPermission.getOtherAction().ordinal() > fileStatus.getPermission().getOtherAction() .ordinal()) { LOG.error(errorMessage + " at least"); throw new ValidationException(errorMessage + " at least"); } } fs.listStatus(locationPath); } catch (IOException e) { throw new ValidationException( "Unable to validate the location with path: " + location + " for cluster:" + clusterName + " due to transient failures ", e); } }