Program: 39292
Project: 39292
Buggy source:
/** 
 * Parse string into date, with autocomplete missing month and day. Examples with up-complete: <ul> <li>2010: 2010-12-31</li> <li>2010-03: 2010-03-31</li> <li>2010-03-06: 2010-03-06</li> </ul> Examples with down-complete: <ul> <li>2010: 2010-01-01</li> <li>2010-03: 2010-03-01</li> <li>2010-03-06: 2010-03-06</li> </ul>
 * @param dateExpression string with date expression
 * @param upComplete true if up-complete, otherwise down-complete
 * @return date or null if year is lower than 1500
 * @throws ParseException if year, month or day is invalid
 */
public static Date parseAndComplete(final String dateExpression,final boolean upComplete) throws ParseException {
  String[] dateExpressionParts=dateExpression.split("String_Node_Str");
  Calendar cal=Calendar.getInstance();
  cal.set(Calendar.YEAR,2000);
  cal.set(Calendar.MONTH,1);
  cal.set(Calendar.DAY_OF_MONTH,1);
  boolean dayDefined=false;
  try {
    int year=Integer.parseInt(dateExpressionParts[0]);
    if (year > 2500) {
      throw new ParseException(WRONG_DATE,1);
    }
    if (year < 1500) {
      throw new ParseException(WRONG_DATE,1);
    }
    cal.set(Calendar.YEAR,year);
    if (dateExpressionParts.length > 1) {
      int month=Integer.parseInt(dateExpressionParts[1]);
      if (month > 12 || month < 1) {
        throw new ParseException(WRONG_DATE,1);
      }
      cal.set(Calendar.MONTH,month - 1);
    }
 else {
      if (upComplete) {
        cal.set(Calendar.MONTH,cal.getActualMaximum(Calendar.MONTH));
      }
 else {
        cal.set(Calendar.MONTH,cal.getActualMinimum(Calendar.MONTH));
      }
    }
    if (dateExpressionParts.length > 2) {
      int day=Integer.parseInt(dateExpressionParts[2]);
      if (day > 0) {
        cal.set(Calendar.DAY_OF_MONTH,day);
        dayDefined=true;
      }
    }
    if (!dayDefined) {
      if (upComplete) {
        cal.set(Calendar.DAY_OF_MONTH,cal.getActualMaximum(Calendar.DAY_OF_MONTH));
      }
 else {
        cal.set(Calendar.DAY_OF_MONTH,cal.getActualMinimum(Calendar.DAY_OF_MONTH));
      }
    }
    return cal.getTime();
  }
 catch (  NumberFormatException e) {
    throw (ParseException)new ParseException(WRONG_DATE,1).initCause(e);
  }
}

Fixed version (ground truth):
/** 
 * Parse string into date, with autocomplete missing month and day. Examples with up-complete: <ul> <li>2010: 2010-12-31</li> <li>2010-03: 2010-03-31</li> <li>2010-03-06: 2010-03-06</li> </ul> Examples with down-complete: <ul> <li>2010: 2010-01-01</li> <li>2010-03: 2010-03-01</li> <li>2010-03-06: 2010-03-06</li> </ul>
 * @param dateExpression string with date expression
 * @param upComplete true if up-complete, otherwise down-complete
 * @return date or null if year is lower than 1500
 * @throws ParseException if year, month or day is invalid
 */
public static Date parseAndComplete(final String dateExpression,final boolean upComplete) throws ParseException {
  String[] dateExpressionParts=dateExpression.split("String_Node_Str");
  Calendar cal=Calendar.getInstance();
  cal.set(Calendar.YEAR,2000);
  cal.set(Calendar.MONTH,1);
  cal.set(Calendar.DAY_OF_MONTH,1);
  boolean dayDefined=false;
  try {
    int year=Integer.parseInt(dateExpressionParts[0]);
    if (year > 2500) {
      throw new ParseException(L_WRONG_DATE,1);
    }
    if (year < 1500) {
      throw new ParseException(L_WRONG_DATE,1);
    }
    cal.set(Calendar.YEAR,year);
    if (dateExpressionParts.length > 1) {
      int month=Integer.parseInt(dateExpressionParts[1]);
      if (month > 12 || month < 1) {
        throw new ParseException(L_WRONG_DATE,1);
      }
      cal.set(Calendar.MONTH,month - 1);
    }
 else {
      if (upComplete) {
        cal.set(Calendar.MONTH,cal.getActualMaximum(Calendar.MONTH));
      }
 else {
        cal.set(Calendar.MONTH,cal.getActualMinimum(Calendar.MONTH));
      }
    }
    if (dateExpressionParts.length > 2) {
      int day=Integer.parseInt(dateExpressionParts[2]);
      if (day > 0) {
        cal.set(Calendar.DAY_OF_MONTH,day);
        dayDefined=true;
      }
    }
    if (!dayDefined) {
      if (upComplete) {
        cal.set(Calendar.DAY_OF_MONTH,cal.getActualMaximum(Calendar.DAY_OF_MONTH));
      }
 else {
        cal.set(Calendar.DAY_OF_MONTH,cal.getActualMinimum(Calendar.DAY_OF_MONTH));
      }
    }
    return cal.getTime();
  }
 catch (  NumberFormatException e) {
    throw (ParseException)new ParseException(L_WRONG_DATE,1).initCause(e);
  }
}