Buggy code:
@ Service public class GroupBrokerImpl implements GroupBroker { private final Logger logger = LoggerFactory . getLogger ( GroupBrokerImpl . class ) ; @ Autowired private GroupRepository groupRepository ; @ Autowired private UserRepository userRepository ; @ Autowired private EventRepository eventRepository ; @ Autowired private MeetingRepository meetingRepository ; @ Autowired private VoteRepository voteRepository ; @ Autowired private GroupLogRepository groupLogRepository ; @ Autowired private PermissionBroker permissionBroker ; @ Autowired private ApplicationEventPublisher applicationEventPublisher ; @ Autowired private AsyncGroupEventLogger asyncGroupEventLogger ; @ Autowired private TokenGeneratorService tokenGeneratorService ; @ Override @ Transactional ( readOnly = true ) public Group load ( String groupUid ) { } @ Override @ Transactional public Group create ( String userUid , String name , String parentGroupUid , Set < MembershipInfo > membershipInfos , GroupPermissionTemplate groupPermissionTemplate , String description ) { } private void logGroupEventsAfterCommit ( Set < GroupLog > groupLogs ) { } @ Override @ Transactional public void deactivate ( String userUid , String groupUid , boolean checkIfWithinTimeWindow ) { } @ Override @ Transactional ( readOnly = true ) public boolean isDeactivationAvailable ( User user , Group group , boolean checkIfWithinTimeWindow ) { } @ Override @ Transactional public void updateName ( String userUid , String groupUid , String name ) { } @ Override public void updateDescription ( String userUid , String groupUid , String description ) { } @ Override @ Transactional public void addMembers ( String userUid , String groupUid , Set < MembershipInfo > membershipInfos ) { } @ Override @ Transactional public void addMemberViaJoinCode ( String userUidToAdd , String groupUid , String tokenPassed ) { } private Set < Membership > addMembers ( User initiator , Group group , Set < MembershipInfo > membershipInfos ) { } @ Override @ Transactional public void removeMembers ( String userUid , String groupUid , Set < String > memberUids ) { } @ Override @ Transactional public void unsubscribeMember ( String userUid , String groupUid ) { } @ Override @ Transactional public void updateMembershipRole ( String userUid , String groupUid , String memberUid , String roleName ) { } @ Override @ Transactional public void updateMembers ( String userUid , String groupUid , Set < MembershipInfo > modifiedMembers ) { } public Group merge ( String userUid , String firstGroupUid , String secondGroupUid , boolean leaveActive , boolean orderSpecified , boolean createNew , String newGroupName ) { } @ Override @ Transactional public void updateGroupPermissions ( String userUid , String groupUid , Map < String , Set < Permission > > newPermissions ) { } @ Override @ Transactional public void updateGroupDefaultReminderSetting ( String userUid , String groupUid , int reminderMinutes ) { } @ Override @ Transactional public void updateGroupDefaultLanguage ( String userUid , String groupUid , String newLocale , boolean includeSubGroups ) { } @ Override @ Transactional public String openJoinToken ( String userUid , String groupUid , boolean temporary , LocalDateTime expiryDateTime ) { } @ Override @ Transactional public void closeJoinToken ( String userUid , String groupUid ) { } @ Override @ Transactional public void updateDiscoverable ( String userUid , String groupUid , boolean discoverable , String authUserPhoneNumber ) { } @ Override @ Transactional ( readOnly = true ) public List < Group > findPublicGroups ( String searchTerm ) { } @ Override public Group findGroupFromJoinCode ( String joinCode ) { } @ Override public Set < Group > subGroups ( String groupUid ) { } @ Override public List < Group > parentChain ( String groupUid ) { } @ Override @ Transactional ( readOnly = true ) public List < GroupTreeDTO > groupTree ( String userUid ) { } @ Override @ Transactional ( readOnly = true ) public Set < Group > possibleParents ( String userUid , String groupUid ) { } @ Override @ Transactional public void link ( String userUid , String childGroupUid , String parentGroupUid ) { } @ Override public Set < Group > mergeCandidates ( String userUid , String groupUid ) { } private boolean isGroupAlsoParent ( Group possibleChildGroup , Group possibleParentGroup ) { } private void recursiveParentGroups ( Group childGroup , List < Group > parentGroups ) { } @ Override @ Transactional ( readOnly = true ) public LocalDateTime getLastTimeGroupActiveOrModified ( String groupUid ) { } private LocalDateTime getLastTimeGroupActive ( String groupUid ) { Group group = groupRepository . findOneByUid ( groupUid ) ; <START_BUG> Event latestEvent = eventRepository . findTopByAppliesToGroupOrderByEventStartDateTimeDesc ( group ) ; <END_BUG> return latestEvent != null ? latestEvent . getEventStartDateTime ( ) . toLocalDateTime ( ) : group . getCreatedDateTime ( ) . toLocalDateTime ( ) ; } private LocalDateTime getLastTimeGroupModified ( String groupUid ) { } @ Override public List < LocalDate > getMonthsGroupActive ( String groupUid ) { } @ Override public List < GroupLog > getLogsForGroup ( Group group , LocalDateTime periodStart , LocalDateTime periodEnd ) { } @ Override @ Transactional ( readOnly = true ) public List < Event > retrieveGroupEvents ( Group group , EventType eventType , LocalDateTime periodStart , LocalDateTime periodEnd ) { } }

Fix:
Event latestEvent = eventRepository . findTopByAppliesToGroupAndEventStartDateTimeNotNullOrderByEventStartDateTimeDesc ( group ) ;