Buggy code:
public static Date addWeeks ( final Date date , final int amount ) { } public static Date addDays ( final Date date , final int amount ) { } public static Date addHours ( final Date date , final int amount ) { } public static Date addMinutes ( final Date date , final int amount ) { } public static Date addSeconds ( final Date date , final int amount ) { } public static Date addMilliseconds ( final Date date , final int amount ) { } private static Date add ( final Date date , final int calendarField , final int amount ) { } public static Date setYears ( final Date date , final int amount ) { } public static Date setMonths ( final Date date , final int amount ) { } public static Date setDays ( final Date date , final int amount ) { } public static Date setHours ( final Date date , final int amount ) { } public static Date setMinutes ( final Date date , final int amount ) { } public static Date setSeconds ( final Date date , final int amount ) { } public static Date setMilliseconds ( final Date date , final int amount ) { } private static Date set ( final Date date , final int calendarField , final int amount ) { } public static Calendar toCalendar ( final Date date ) { } public static Date round ( final Date date , final int field ) { } public static Calendar round ( final Calendar date , final int field ) { } public static Date round ( final Object date , final int field ) { } public static Date truncate ( final Date date , final int field ) { } public static Calendar truncate ( final Calendar date , final int field ) { } public static Date truncate ( final Object date , final int field ) { } public static Date ceiling ( final Date date , final int field ) { } public static Calendar ceiling ( final Calendar date , final int field ) { } public static Date ceiling ( final Object date , final int field ) { } private static void modify ( final Calendar val , final int field , final int modType ) { } public static Iterator < Calendar > iterator ( final Date focus , final int rangeStyle ) { } public static Iterator < Calendar > iterator ( final Calendar focus , final int rangeStyle ) { } public static Iterator < ? > iterator ( final Object focus , final int rangeStyle ) { } public static long getFragmentInMilliseconds ( final Date date , final int fragment ) { } public static long getFragmentInSeconds ( final Date date , final int fragment ) { } public static long getFragmentInMinutes ( final Date date , final int fragment ) { } public static long getFragmentInHours ( final Date date , final int fragment ) { } public static long getFragmentInDays ( final Date date , final int fragment ) { } public static long getFragmentInMilliseconds ( final Calendar calendar , final int fragment ) { } public static long getFragmentInSeconds ( final Calendar calendar , final int fragment ) { } public static long getFragmentInMinutes ( final Calendar calendar , final int fragment ) { } public static long getFragmentInHours ( final Calendar calendar , final int fragment ) { } public static long getFragmentInDays ( final Calendar calendar , final int fragment ) { } private static long getFragment ( final Date date , final int fragment , final TimeUnit unit ) { } private static long getFragment ( final Calendar calendar , final int fragment , final TimeUnit unit ) { if ( calendar == null ) { throw new IllegalArgumentException ( "The<seq2seq4repair_space>date<seq2seq4repair_space>must<seq2seq4repair_space>not<seq2seq4repair_space>be<seq2seq4repair_space>null" ) ; } long result = 0 ; <START_BUG> int offset = ( unit == ( TimeUnit . DAYS ) ) ? 0 : 1 ; <END_BUG> switch ( fragment ) { case Calendar . YEAR : result += unit . convert ( ( ( calendar . get ( Calendar . DAY_OF_YEAR ) ) - offset ) , TimeUnit . DAYS ) ; break ; case Calendar . MONTH : result += unit . convert ( ( ( calendar . get ( Calendar . DAY_OF_MONTH ) ) - offset ) , TimeUnit . DAYS ) ; break ; default : break ; } switch ( fragment ) { case Calendar . YEAR : case Calendar . MONTH : case Calendar . DAY_OF_YEAR : case Calendar . DATE : result += unit . convert ( calendar . get ( Calendar . HOUR_OF_DAY ) , TimeUnit . HOURS ) ; case Calendar . HOUR_OF_DAY : result += unit . convert ( calendar . get ( Calendar . MINUTE ) , TimeUnit . MINUTES ) ; case Calendar . MINUTE : result += unit . convert ( calendar . get ( Calendar . SECOND ) , TimeUnit . SECONDS ) ; case Calendar . SECOND : result += unit . convert ( calendar . get ( Calendar . MILLISECOND ) , TimeUnit . MILLISECONDS ) ; break ; case Calendar . MILLISECOND : break ; default : throw new IllegalArgumentException ( ( ( "The<seq2seq4repair_space>fragment<seq2seq4repair_space>" + fragment ) + "<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>supported" ) ) ; } return result ; } public static boolean truncatedEquals ( final Calendar cal1 , final Calendar cal2 , final int field ) { } public static boolean truncatedEquals ( final Date date1 , final Date date2 , final int field ) { } public static int truncatedCompareTo ( final Calendar cal1 , final Calendar cal2 , final int field ) { } public static int truncatedCompareTo ( final Date date1 , final Date date2 , final int field ) { } static class DateIterator implements Iterator < Calendar > { private final Calendar endFinal ; private final Calendar spot ;

Fix:
final int offset = ( unit == ( TimeUnit . DAYS ) ) ? 0 : 1 ;