Buggy code:
@ Service public class ApiServerAppService { private static final Logger LOG = LoggerFactory . getLogger ( ApiServerAppService . class ) ; private final GaiaAppRepository gaiaAppRepository ; @ Autowired private ApiServerUserService userService ; @ Autowired private ApiServerClusterService clusterService ; @ Autowired private ApiServerQueueService queueService ; @ Autowired private ApiServerGroupService groupService ; @ Autowired private GaiaClient gaiaClient ; private GaiaGroupEntity gaiaAdminGroup ; @ Autowired public ApiServerAppService ( GaiaAppRepository gaiaAppRepository ) { } @ Transactional ( readOnly = true ) public void validateUserPermission ( GaiaAppEntity app , String operator , String operation ) throws PortalException { if ( ( gaiaAdminGroup ) == null ) { gaiaAdminGroup = groupService . findGroupByName ( "gaia_admin" ) ; } GaiaUserEntity user = userService . findEntityByRtxId ( operator ) ; Set < GaiaGroupEntity > principalGroups = new HashSet < GaiaGroupEntity > ( app . getPrincipals ( ) ) ; if ( ( gaiaAdminGroup ) != null ) { principalGroups . add ( gaiaAdminGroup ) ; } boolean isInPrincipals = false ; <START_BUG> for ( GaiaGroupEntity group : app . getPrincipals ( ) ) { <END_BUG> if ( group . getUsers ( ) . contains ( user ) ) { isInPrincipals = true ; break ; } } if ( ! isInPrincipals ) { ApiServerAppService . LOG . warn ( String . format ( "User=%s<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>allowed<seq2seq4repair_space>to<seq2seq4repair_space>perform<seq2seq4repair_space>action=%s<seq2seq4repair_space>on<seq2seq4repair_space>the<seq2seq4repair_space>application<seq2seq4repair_space>appId=%s" , operator , operation , app . getAppId ( ) ) ) ; throw new PermissionDeniedException ( app , user . getRtxId ( ) , operation ) ; } } @ Transactional ( readOnly = true ) public boolean validateAppName ( String appName , String clusterId , String clusterName , String queueId , String queueName ) throws PortalException { } private boolean validateAppName ( String appName , GaiaClusterEntity cluster , GaiaQueueEntity queue ) throws PortalException { } @ Transactional ( readOnly = false ) public GaiaApp submitGaiaApp ( GaiaApp gaiaApp ) throws PortalException { } private GaiaClusterEntity getCluster ( String clusterId , String clusterName ) throws PortalException { } private GaiaQueueEntity getQueue ( GaiaClusterEntity cluster , String queueId , String queueName ) throws PortalException { } @ Transactional ( readOnly = true ) public Page < GaiaApp > findAll ( Pageable pageable ) throws PortalException { } @ Transactional ( readOnly = true ) public GaiaApp findByAppId ( String appId ) throws PortalException { } @ Transactional ( readOnly = true ) public GaiaAppEntity findEntityByAppId ( String appId ) throws PortalException { } @ Transactional ( readOnly = true ) public List < GaiaApp > findByGaiaUser ( String rtxId ) throws PortalException { } @ Transactional ( readOnly = false ) public GaiaApp killGaiaApp ( GaiaAppEntity entity ) throws PortalException { } @ Transactional ( readOnly = true ) public List < GaiaAppEntity > findUnfinishedApp ( ) { } @ Transactional ( readOnly = false ) public boolean updateGaiaAppByGaia ( ApplicationReport application ) { } @ Transactional ( readOnly = true ) public GaiaAppBlackListInfo getGaiaAppBlackList ( String appId ) throws PortalException { } public boolean addGaiaAppBlacklist ( GaiaAppEntity entity , String host ) throws PortalException { } public boolean deleteGaiaAppBlacklist ( GaiaAppEntity entity , String host ) throws PortalException { } @ Transactional ( readOnly = false ) public GaiaApp rampupInstance ( String appId , int num ) throws PortalException { } @ Transactional ( readOnly = false ) public GaiaApp rampupInstance ( GaiaAppEntity entity , int num , GaiaInstanceSubmitParameters launchInfo ) throws PortalException { } @ Transactional ( readOnly = true ) public boolean reloadInstance ( GaiaAppEntity entity , int instanceId , GaiaInstanceSubmitParameters launchInfo ) throws PortalException { } @ Transactional ( readOnly = true ) public GaiaInstances findAppInstances ( String appId ) throws PortalException { } @ Transactional ( readOnly = true ) public GaiaInstance findAppInstance ( String appId , int instanceId ) throws PortalException { } @ Transactional ( readOnly = true ) public boolean killAppInstance ( GaiaAppEntity gaiaAppEntity , int instanceId ) throws PortalException { } @ Transactional ( readOnly = true ) public GaiaInstanceInfo getInstanceWeb ( String appId , int instanceId ) throws PortalException { } @ Transactional ( readOnly = true ) public GaiaInstanceInfo getInstanceSshd ( String appId , int instanceId ) throws PortalException { } @ Transactional ( readOnly = true ) public InspectContainerResponse inspectInstance ( String appId , int instanceId ) throws PortalException { } @ Transactional ( readOnly = true ) public TopContainerResponse topInstance ( String appId , int instanceId ) throws PortalException { } @ Transactional ( readOnly = true ) public String logInstance ( String appId , int instanceId ) throws PortalException { } }

Fix:
for ( GaiaGroupEntity group : principalGroups ) {