@Override
    public boolean isValid(final String dir, final ConstraintValidatorContext context) {
        final boolean isValid;
        if (dir != null && !dir.isBlank()) {
            // Use the PathCreator, so we can interpret relative paths and paths with '~' in.
            final Path modifiedDir = pathCreator.toAppPath(dir);

            LOGGER.debug("Validating dir {} (modified to {})", dir, modifiedDir);
            boolean exists = Files.exists(modifiedDir);
            if (!exists && ensureExistence) {
                try {
                    LOGGER.info("Creating dir {} (modified to {})", dir, modifiedDir);
                    Files.createDirectories(modifiedDir);
                } catch (IOException e) {
                    final String msg = "error creating directory: " + e.getMessage();
                    addValidationMessage(context, dir, modifiedDir, msg);
                }
            }
            exists = Files.exists(modifiedDir);

            if (!exists) {
                final String msg = "path does not exist";
                addValidationMessage(context, dir, modifiedDir, msg);
                isValid = false;
            } else if (!Files.isDirectory(modifiedDir)) {
                final String msg = "path is not a directory";
                addValidationMessage(context, dir, modifiedDir, msg);
                isValid = false;
            } else if (!Files.isWritable(modifiedDir)) {
                final String msg = "directory is not writable";
                addValidationMessage(context, dir, modifiedDir, msg);
                isValid = false;
            } else {
                isValid = true;
            }
        } else {
            isValid = true;
        }
        return isValid;
    }
Implements the validation logic.
The state of {@code value} must not be altered.
<p>
This method can be accessed concurrently, thread-safety must be ensured
by the implementation.

@param dir     object to validate
@param context context in which the constraint is evaluated
@return {@code false} if {@code value} does not pass the constraint
stroom-util/src/main/java/stroom/util/validation/ValidDirectoryPathValidatorImpl.java