code: public static String tryGetCanonicalPathElseGetAbsolutePath(File file) {
      try {
        return file.getCanonicalPath();
      }
      catch (IOException ignore) {
        return file.getAbsolutePath();
      }
    }
docs: Attempts to the get the canonical path of the given file, otherwise returns the absolute path of the file.
  
  @param file the {@link File} from which the canonical or absolute path will be returned.
  @return the canonical path of the file unless an IOException occurs then return the absolute path of the file.
  @see java.io.File#getAbsolutePath()
  @see java.io.File#getCanonicalPath()