Buggy code:
public class SubscriptionData implements Subscription { private static final Logger log = LoggerFactory . getLogger ( SubscriptionData . class ) ; private final Clock clock ; private final SubscriptionApiService apiService ; private final UUID id ; private final UUID bundleId ; private final DateTime startDate ; private final DateTime bundleStartDate ; private final ProductCategory category ; private final long activeVersion ; private final DateTime chargedThroughDate ; private final DateTime paidThroughDate ; private List < SubscriptionTransitionData > transitions ; public SubscriptionData ( SubscriptionBuilder builder ) { } public SubscriptionData ( SubscriptionBuilder builder , SubscriptionApiService apiService , Clock clock ) { } @ Override public UUID getId ( ) { } @ Override public UUID getBundleId ( ) { } @ Override public DateTime getStartDate ( ) { } @ Override public SubscriptionState getState ( ) { } @ Override public IPlanPhase getCurrentPhase ( ) { } @ Override public IPlan getCurrentPlan ( ) { } @ Override public String getCurrentPriceList ( ) { } @ Override public DateTime getEndDate ( ) { } @ Override public void cancel ( DateTime requestedDate , boolean eot ) throws EntitlementUserApiException { } @ Override public void uncancel ( ) throws EntitlementUserApiException { } @ Override public void changePlan ( String productName , BillingPeriod term , String priceList , DateTime requestedDate ) throws EntitlementUserApiException { } @ Override public void pause ( ) throws EntitlementUserApiException { } @ Override public void resume ( ) throws EntitlementUserApiException { } public SubscriptionTransition getLatestTranstion ( ) { } public SubscriptionTransition getTransitionFromEvent ( EntitlementEvent event ) { } public long getActiveVersion ( ) { } public ProductCategory getCategory ( ) { } public DateTime getBundleStartDate ( ) { } public DateTime getChargedThroughDate ( ) { } public DateTime getPaidThroughDate ( ) { } public DateTime getCurrentPlanStart ( ) { } public List < SubscriptionTransition > getActiveTransitions ( ) { } public boolean isSubscriptionFutureCancelled ( ) { } public DateTime getPlanChangeEffectiveDate ( ActionPolicy policy , DateTime now ) { } public DateTime getCurrentPhaseStart ( ) { } public void rebuildTransitions ( final List < EntitlementEvent > events , final ICatalog catalog ) { if ( events == null ) { return ; } SubscriptionState nextState = null ; String nextPlanName = null ; String nextPhaseName = null ; String nextPriceList = null ; SubscriptionState previousState = null ; String previousPlanName = null ; String previousPhaseName = null ; String previousPriceList = null ; transitions = new LinkedList < SubscriptionTransitionData > ( ) ; for ( final EntitlementEvent cur : events ) { if ( ( ! ( cur . isActive ( ) ) ) || ( ( cur . getActiveVersion ( ) ) < ( activeVersion ) ) ) { continue ; } ApiEventType apiEventType = null ; switch ( cur . getType ( ) ) { case PHASE : PhaseEvent phaseEV = ( ( PhaseEvent ) ( cur ) ) ; nextPhaseName = phaseEV . getPhase ( ) ; break ; case API_USER : ApiEvent userEV = ( ( ApiEvent ) ( cur ) ) ; apiEventType = userEV . getEventType ( ) ; switch ( apiEventType ) { case CREATE : nextState = SubscriptionState . ACTIVE ; nextPlanName = userEV . getEventPlan ( ) ; nextPhaseName = userEV . getEventPlanPhase ( ) ; nextPriceList = userEV . getPriceList ( ) ; break ; case CHANGE : nextPlanName = userEV . getEventPlan ( ) ; nextPhaseName = userEV . getEventPlanPhase ( ) ; nextPriceList = userEV . getPriceList ( ) ; break ; case PAUSE : nextState = SubscriptionState . PAUSED ; break ; case RESUME : nextState = SubscriptionState . ACTIVE ; break ; case CANCEL : nextState = SubscriptionState . CANCELLED ; nextPlanName = null ; nextPhaseName = null ; break ; case UNCANCEL : break ; default : throw new com . ning . billing . entitlement . exceptions . EntitlementError ( String . format ( "Unexpected<seq2seq4repair_space>UserEvent<seq2seq4repair_space>type<seq2seq4repair_space>=<seq2seq4repair_space>%s" , userEV . getEventType ( ) . toString ( ) ) ) ; } break ; default : throw new com . ning . billing . entitlement . exceptions . EntitlementError ( String . format ( "Unexpected<seq2seq4repair_space>Event<seq2seq4repair_space>type<seq2seq4repair_space>=<seq2seq4repair_space>%s" , cur . getType ( ) ) ) ; } IPlan previousPlan = null ; IPlanPhase previousPhase = null ; IPlan nextPlan = null ; IPlanPhase nextPhase = null ; try { previousPlan = ( previousPlanName != null ) ? catalog . findPlan ( previousPlanName ) : null ; <START_BUG> previousPhase = ( previousPhase != null ) ? catalog . findPhase ( previousPhaseName ) : null ; <END_BUG> nextPlan = ( nextPlanName != null ) ? catalog . findPlan ( nextPlanName ) : null ; nextPhase = ( nextPhaseName != null ) ? catalog . findPhase ( nextPhaseName ) : null ; } catch ( CatalogApiException e ) { SubscriptionData . log . error ( String . format ( "Failed<seq2seq4repair_space>to<seq2seq4repair_space>build<seq2seq4repair_space>transition<seq2seq4repair_space>for<seq2seq4repair_space>subscription<seq2seq4repair_space>%s" , id ) , e ) ; } SubscriptionTransitionData transition = new SubscriptionTransitionData ( cur . getId ( ) , id , bundleId , cur . getType ( ) , apiEventType , cur . getRequestedDate ( ) , cur . getEffectiveDate ( ) , previousState , previousPlan , previousPhase , previousPriceList , nextState , nextPlan , nextPhase , nextPriceList ) ; transitions . add ( transition ) ; previousState = nextState ; previousPlanName = nextPlanName ; previousPhaseName = nextPhaseName ; previousPriceList = nextPriceList ; } } }

Fix:
previousPhase = ( previousPhaseName != null ) ? catalog . findPhase ( previousPhaseName ) : null ;