code: public static int getAttemptId(Configuration conf)
        throws IllegalArgumentException {
      if (conf == null) {
        throw new NullPointerException("Conf is null");
      }
  
      String taskId = conf.get("mapred.task.id");
      if (taskId == null) {
        throw new IllegalArgumentException(
            "Configuration does not contain the property mapred.task.id");
      }
  
      String[] parts = taskId.split("_");
      if (parts.length != 6 ||
          !parts[0].equals("attempt") ||
          (!"m".equals(parts[3]) && !"r".equals(parts[3]))) {
        throw new IllegalArgumentException(
            "TaskAttemptId string : " + taskId + " is not properly formed");
      }
  
      return Integer.parseInt(parts[5]);
    }
docs: Get the attempt number
  @param conf Configuration
  @return Attempt number
  @throws IllegalArgumentException