Buggy code:
public class ChangeData { public static void ensureChangeLoaded ( Iterable < ChangeData > changes ) throws OrmException { } public static void ensureAllPatchSetsLoaded ( Iterable < ChangeData > changes ) throws OrmException { } public static void ensureCurrentPatchSetLoaded ( Iterable < ChangeData > changes ) throws OrmException { } public static void ensureCurrentApprovalsLoaded ( Iterable < ChangeData > changes ) throws OrmException { } public interface Factory { ChangeData create ( ReviewDb db , Change . Id id ) { } ChangeData create ( ReviewDb db , Change c ) { } ChangeData create ( ReviewDb db , ChangeControl c ) { } } static ChangeData createForTest ( Change . Id id , int currentPatchSetId ) { } private final ReviewDb db ; private final GitRepositoryManager repoManager ; private final GenericFactory changeControlFactory ; private final IdentifiedUser . GenericFactory userFactory ; private final ChangeNotes . Factory notesFactory ; private final ApprovalsUtil approvalsUtil ; private final ChangeMessagesUtil cmUtil ; private final PatchListCache patchListCache ; private final NotesMigration notesMigration ; private final Id legacyId ; private ChangeDataSource returnedBySource ; private Change change ; private ChangeNotes notes ; private String commitMessage ; private List < FooterLine > commitFooters ; private PatchSet currentPatchSet ; private Collection < PatchSet > patches ; private ListMultimap < PatchSet . Id , PatchSetApproval > allApprovals ; private List < PatchSetApproval > currentApprovals ; private Map < Integer , List < String > > files = new HashMap < > ( ) ; private Collection < PatchLineComment > comments ; private CurrentUser visibleTo ; private ChangeControl changeControl ; private List < ChangeMessage > messages ; private List < SubmitRecord > submitRecords ; private ChangeData . ChangedLines changedLines ; @ AssistedInject private ChangeData ( GitRepositoryManager repoManager , ChangeControl . GenericFactory changeControlFactory , IdentifiedUser . GenericFactory userFactory , ChangeNotes . Factory notesFactory , ApprovalsUtil approvalsUtil , ChangeMessagesUtil cmUtil , PatchListCache patchListCache , NotesMigration notesMigration , @ Assisted ReviewDb db , @ Assisted Change . Id id ) { } @ AssistedInject private ChangeData ( GitRepositoryManager repoManager , ChangeControl . GenericFactory changeControlFactory , IdentifiedUser . GenericFactory userFactory , ChangeNotes . Factory notesFactory , ApprovalsUtil approvalsUtil , ChangeMessagesUtil cmUtil , PatchListCache patchListCache , NotesMigration notesMigration , @ Assisted ReviewDb db , @ Assisted Change c ) { } @ AssistedInject private ChangeData ( GitRepositoryManager repoManager , ChangeControl . GenericFactory changeControlFactory , IdentifiedUser . GenericFactory userFactory , ChangeNotes . Factory notesFactory , ApprovalsUtil approvalsUtil , ChangeMessagesUtil cmUtil , PatchListCache patchListCache , NotesMigration notesMigration , @ Assisted ReviewDb db , @ Assisted ChangeControl c ) { } public boolean isFromSource ( ChangeDataSource s ) { } public void cacheFromSource ( ChangeDataSource s ) { } public void setCurrentFilePaths ( List < String > filePaths ) throws OrmException { } public List < String > currentFilePaths ( ) throws OrmException { } public List < String > filePaths ( PatchSet ps ) throws OrmException { } public ChangeData . ChangedLines changedLines ( ) throws OrmException { } public void setChangedLines ( int insertions , int deletions ) { } public Id getId ( ) { } boolean fastIsVisibleTo ( CurrentUser user ) { } public boolean hasChangeControl ( ) { } public ChangeControl changeControl ( ) throws OrmException { } void cacheVisibleTo ( ChangeControl ctl ) { } public Change change ( ) throws OrmException { } public ChangeNotes notes ( ) throws OrmException { } public PatchSet currentPatchSet ( ) throws OrmException { } public List < PatchSetApproval > currentApprovals ( ) throws OrmException { } public void setCurrentApprovals ( List < PatchSetApproval > approvals ) { } public String commitMessage ( ) throws NoSuchChangeException , OrmException , IOException { } public List < FooterLine > commitFooters ( ) throws NoSuchChangeException , OrmException , IOException { } private void loadCommitData ( ) throws NoSuchChangeException , OrmException , IOException , IncorrectObjectTypeException , MissingObjectException , RepositoryNotFoundException { } public Collection < PatchSet > patches ( ) throws OrmException { } public PatchSet patch ( PatchSet . Id psId ) throws OrmException { } public ListMultimap < PatchSet . Id , PatchSetApproval > approvals ( ) throws OrmException { } public SetMultimap < ReviewerState , Account . Id > reviewers ( ) throws OrmException { } public Collection < PatchLineComment > comments ( ) throws OrmException { } public List < ChangeMessage > messages ( ) throws OrmException { if ( ( messages ) == null ) { <START_BUG> messages = cmUtil . byChange ( db , notes ) ; <END_BUG> } return messages ; } public void setSubmitRecords ( List < SubmitRecord > records ) { } public List < SubmitRecord > getSubmitRecords ( ) { } @ Override public String toString ( ) { } public static class ChangedLines { public final int insertions ; public final int deletions ; ChangedLines ( int insertions , int deletions ) { } } }

Fix:
messages = cmUtil . byChange ( db , notes ( ) ) ;