Buggy code:
carry = fQuotient . toBigInteger ( ) ; setSecond ( endSeconds . intValue ( ) ) ; BigDecimal tempFracSeconds = endSeconds . subtract ( new BigDecimal ( BigInteger . valueOf ( ( ( long ) ( getSecond ( ) ) ) ) ) ) ; if ( ( tempFracSeconds . compareTo ( XMLGregorianCalendarImpl . DECIMAL_ZERO ) ) < 0 ) { setFractionalSecond ( XMLGregorianCalendarImpl . DECIMAL_ONE . add ( tempFracSeconds ) ) ; if ( ( getSecond ( ) ) == 0 ) { setSecond ( 59 ) ; carry = carry . subtract ( BigInteger . ONE ) ; } else { setSecond ( ( ( getSecond ( ) ) - 1 ) ) ; } } else { setFractionalSecond ( tempFracSeconds ) ; } int startMinutes = getMinute ( ) ; if ( startMinutes == ( DatatypeConstants . FIELD_UNDEFINED ) ) { fieldUndefined [ XMLGregorianCalendarImpl . MINUTE ] = true ; startMinutes = XMLGregorianCalendarImpl . MIN_FIELD_VALUE [ XMLGregorianCalendarImpl . MINUTE ] ; } BigInteger dMinutes = XMLGregorianCalendarImpl . sanitize ( duration . getField ( DatatypeConstants . MINUTES ) , signum ) ; temp = BigInteger . valueOf ( startMinutes ) . add ( dMinutes ) . add ( carry ) ; setMinute ( temp . mod ( XMLGregorianCalendarImpl . SIXTY ) . intValue ( ) ) ; carry = new BigDecimal ( temp ) . divide ( XMLGregorianCalendarImpl . DECIMAL_SIXTY , BigDecimal . ROUND_FLOOR ) . toBigInteger ( ) ; int startHours = getHour ( ) ; if ( startHours == ( DatatypeConstants . FIELD_UNDEFINED ) ) { fieldUndefined [ XMLGregorianCalendarImpl . HOUR ] = true ; startHours = XMLGregorianCalendarImpl . MIN_FIELD_VALUE [ XMLGregorianCalendarImpl . HOUR ] ; } BigInteger dHours = XMLGregorianCalendarImpl . sanitize ( duration . getField ( DatatypeConstants . HOURS ) , signum ) ; temp = BigInteger . valueOf ( startHours ) . add ( dHours ) . add ( carry ) ; setHour ( temp . mod ( XMLGregorianCalendarImpl . TWENTY_FOUR ) . intValue ( ) ) ; carry = new BigDecimal ( temp ) . divide ( new BigDecimal ( XMLGregorianCalendarImpl . TWENTY_FOUR ) , BigDecimal . ROUND_FLOOR ) . toBigInteger ( ) ; BigInteger tempDays ; int startDay = getDay ( ) ; if ( startDay == ( DatatypeConstants . FIELD_UNDEFINED ) ) { fieldUndefined [ XMLGregorianCalendarImpl . DAY ] = true ; startDay = XMLGregorianCalendarImpl . MIN_FIELD_VALUE [ XMLGregorianCalendarImpl . DAY ] ; } BigInteger dDays = XMLGregorianCalendarImpl . sanitize ( duration . getField ( DatatypeConstants . DAYS ) , signum ) ; int maxDayInMonth = XMLGregorianCalendarImpl . maximumDayInMonthFor ( getEonAndYear ( ) , getMonth ( ) ) ; if ( startDay > maxDayInMonth ) { tempDays = BigInteger . valueOf ( maxDayInMonth ) ; } else if ( startDay < 1 ) { tempDays = BigInteger . ONE ; } else { tempDays = BigInteger . valueOf ( startDay ) ; } BigInteger endDays = tempDays . add ( dDays ) . add ( carry ) ; int monthCarry ; int intTemp ; while ( true ) { if ( ( endDays . compareTo ( BigInteger . ONE ) ) < 0 ) { BigInteger mdimf = null ; if ( ( month ) >= 2 ) { mdimf = BigInteger . valueOf ( XMLGregorianCalendarImpl . maximumDayInMonthFor ( getEonAndYear ( ) , ( ( getMonth ( ) ) - 1 ) ) ) ; } else { mdimf = BigInteger . valueOf ( XMLGregorianCalendarImpl . maximumDayInMonthFor ( getEonAndYear ( ) . subtract ( BigInteger . valueOf ( ( ( long ) ( 1 ) ) ) ) , 12 ) ) ; } endDays = endDays . add ( mdimf ) ; monthCarry = - 1 ; } else if ( ( endDays . compareTo ( BigInteger . valueOf ( XMLGregorianCalendarImpl . maximumDayInMonthFor ( getEonAndYear ( ) , getMonth ( ) ) ) ) ) > 0 ) { endDays = endDays . add ( BigInteger . valueOf ( ( - ( XMLGregorianCalendarImpl . maximumDayInMonthFor ( getEonAndYear ( ) , getMonth ( ) ) ) ) ) ) ; monthCarry = 1 ; } else { break ; } intTemp = ( getMonth ( ) ) + monthCarry ; int endMonth = ( intTemp - 1 ) % ( 13 - 1 ) ; int quotient ; if ( endMonth < 0 ) { endMonth = ( ( 13 - 1 ) + endMonth ) + 1 ; <START_BUG> quotient = new BigDecimal ( ( intTemp - 1 ) ) . divide ( new BigDecimal ( XMLGregorianCalendarImpl . TWELVE ) , BigDecimal . ROUND_UP ) . intValue ( ) ; <END_BUG> } else { quotient = ( intTemp - 1 ) // ( 13 - 1 ) ; endMonth += 1 ; } setMonth ( endMonth ) ; if ( quotient != 0 ) { setYear ( getEonAndYear ( ) . add ( BigInteger . valueOf ( quotient ) ) ) ; } } setDay ( endDays . intValue ( ) ) ; for ( int i = XMLGregorianCalendarImpl . YEAR ; i <= ( XMLGregorianCalendarImpl . SECOND ) ; i ++ ) { if ( fieldUndefined [ i ] ) { switch ( i ) { case XMLGregorianCalendarImpl . YEAR : setYear ( DatatypeConstants . FIELD_UNDEFINED ) ; break ; case XMLGregorianCalendarImpl . MONTH : setMonth ( DatatypeConstants . FIELD_UNDEFINED ) ; break ; case XMLGregorianCalendarImpl . DAY : setDay ( DatatypeConstants . FIELD_UNDEFINED ) ; break ; case XMLGregorianCalendarImpl . HOUR : setHour ( DatatypeConstants . FIELD_UNDEFINED ) ; break ; case XMLGregorianCalendarImpl . MINUTE : setMinute ( DatatypeConstants . FIELD_UNDEFINED ) ; break ; case XMLGregorianCalendarImpl . SECOND : setSecond ( DatatypeConstants . FIELD_UNDEFINED ) ; setFractionalSecond ( null ) ; break ; } } } } private static final BigInteger FOUR = BigInteger . valueOf ( 4 ) ; private static final BigInteger HUNDRED = BigInteger . valueOf ( 100 ) ; private static final BigInteger FOUR_HUNDRED = BigInteger . valueOf ( 400 ) ;

Fix:
quotient = BigDecimal . valueOf ( ( intTemp - 1 ) ) . divide ( new BigDecimal ( XMLGregorianCalendarImpl . TWELVE ) , BigDecimal . ROUND_UP ) . intValue ( ) ;