code: static File validateDirectory(final File directory) {
  
          File newDirectory = null;
  
          try {
              newDirectory = AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<File>() {
                  @Override
                  public File run() throws Exception {
                      boolean ok = true;
  
                      if (!directory.exists())
                          ok = directory.mkdirs() || directory.exists(); //2nd exists check is necessary to close timing window
  
                      if (!ok) {
                          Tr.error(tc, "UNABLE_TO_DELETE_RESOURCE_NOEX", new Object[] { directory.getAbsolutePath() });
                          return null;
                      }
                      return directory;
                  }
              });
          } catch (PrivilegedActionException e) {
              Tr.error(tc, "UNABLE_TO_DELETE_RESOURCE", new Object[] { directory.getAbsolutePath(), e });
          }
  
          return newDirectory;
      }
docs: This method will create the directory if it does not exist,
  ensuring the specified location is writable.
  
  @param The new directory location
  @return A valid/accessible/created directory or null