public static TaskID forName(String str) 
    throws IllegalArgumentException {
    if(str == null)
      return null;
    Matcher m = taskIdPattern.matcher(str);
    if (m.matches()) {
      return new org.apache.hadoop.mapred.TaskID(m.group(1),
          Integer.parseInt(m.group(2)),
          CharTaskTypeMaps.getTaskType(m.group(3).charAt(0)),
          Integer.parseInt(m.group(4)));
    }
    String exceptionMsg = "TaskId string : " + str + " is not properly formed" +
        "\nReason: " + m.toString();
    throw new IllegalArgumentException(exceptionMsg);
  }
@Test
  public void testForName() {
    assertEquals("The forName() method did not parse the task ID string "
        + "correctly", "task_1_0001_m_000000",
        TaskID.forName("task_1_0001_m_000").toString());
    assertEquals("The forName() method did not parse the task ID string "
        + "correctly", "task_23_0002_r_000001",
        TaskID.forName("task_23_0002_r_0001").toString());
    assertEquals("The forName() method did not parse the task ID string "
        + "correctly", "task_345_0003_s_000002",
        TaskID.forName("task_345_0003_s_00002").toString());
    assertEquals("The forName() method did not parse the task ID string "
        + "correctly", "task_6789_0004_c_000003",
        TaskID.forName("task_6789_0004_c_000003").toString());
    assertEquals("The forName() method did not parse the task ID string "
        + "correctly", "task_12345_0005_t_4000000",
        TaskID.forName("task_12345_0005_t_4000000").toString());

    try {
      TaskID.forName("tisk_12345_0005_t_4000000");
      fail("The forName() method parsed an invalid job ID: "
          + "tisk_12345_0005_t_4000000");
    } catch (IllegalArgumentException ex) {
      // Expected
    }

    try {
      TaskID.forName("tisk_12345_0005_t_4000000");
      fail("The forName() method parsed an invalid job ID: "
          + "tisk_12345_0005_t_4000000");
    } catch (IllegalArgumentException ex) {
      // Expected
    }

    try {
      TaskID.forName("task_abc_0005_t_4000000");
      fail("The forName() method parsed an invalid job ID: "
          + "task_abc_0005_t_4000000");
    } catch (IllegalArgumentException ex) {
      // Expected
    }

    try {
      TaskID.forName("task_12345_xyz_t_4000000");
      fail("The forName() method parsed an invalid job ID: "
          + "task_12345_xyz_t_4000000");
    } catch (IllegalArgumentException ex) {
      // Expected
    }

    try {
      TaskID.forName("task_12345_0005_x_4000000");
      fail("The forName() method parsed an invalid job ID: "
          + "task_12345_0005_x_4000000");
    } catch (IllegalArgumentException ex) {
      // Expected
    }

    try {
      TaskID.forName("task_12345_0005_t_jkl");
      fail("The forName() method parsed an invalid job ID: "
          + "task_12345_0005_t_jkl");
    } catch (IllegalArgumentException ex) {
      // Expected
    }

    try {
      TaskID.forName("task_12345_0005_t");
      fail("The forName() method parsed an invalid job ID: "
          + "task_12345_0005_t");
    } catch (IllegalArgumentException ex) {
      // Expected
    }

    try {
      TaskID.forName("task_12345_0005_4000000");
      fail("The forName() method parsed an invalid job ID: "
          + "task_12345_0005_4000000");
    } catch (IllegalArgumentException ex) {
      // Expected
    }

    try {
      TaskID.forName("task_12345_t_4000000");
      fail("The forName() method parsed an invalid job ID: "
          + "task_12345_t_4000000");
    } catch (IllegalArgumentException ex) {
      // Expected
    }

    try {
      TaskID.forName("12345_0005_t_4000000");
      fail("The forName() method parsed an invalid job ID: "
          + "12345_0005_t_4000000");
    } catch (IllegalArgumentException ex) {
      // Expected
    }
  }