code: private File getValidDir(final String varName, final String dirName) {
          if (dirName == null) {
              throw new RuntimeException("The system variable '" + varName + "' is not set!");
          }
          final File dir = new File(dirName);
          if (!dir.exists()) {
              throw new IllegalArgumentException("The directory '" + dir + "' does not exist! [system variable '" + varName + "']");
          }
          if (!dir.isDirectory()) {
              throw new IllegalArgumentException("The name '" + dir + "' is not a directory! [system variable '" + varName + "']");
          }
          return dir;
      }
docs: Checks if the system variable is set and is a valid directory. If this is not the case a {@link RuntimeException} will be thrown.
  
  @param varName
  Name of the system variable.
  @param dirName
  Name of the directory (from the system variable).
  
  @return Directory reference.