Program: 4757
Project: 4757
Buggy source:
@Test public void testProgramList() throws Exception {
  SecurityRequestContext.setUserId(ALICE.getName());
  ApplicationId applicationId=NamespaceId.DEFAULT.app(AllProgramsApp.NAME);
  Map<EntityId,Set<Action>> neededPrivileges=ImmutableMap.<EntityId,Set<Action>>builder().put(applicationId,EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.artifact(AllProgramsApp.class.getSimpleName(),"String_Node_Str"),EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME),EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME2),EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME3),EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DS_WITH_SCHEMA_NAME),EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.stream(AllProgramsApp.STREAM_NAME),EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.datasetType(KeyValueTable.class.getName()),EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.datasetType(ObjectMappedTable.class.getName()),EnumSet.of(Action.ADMIN)).build();
  setUpPrivilegesAndExpectFailedDeploy(neededPrivileges);
  AppFabricTestHelper.deployApplication(Id.Namespace.DEFAULT,AllProgramsApp.class,null,cConf);
  for (  ProgramType type : ProgramType.values()) {
    if (!type.equals(ProgramType.CUSTOM_ACTION) && !type.equals(ProgramType.WEBAPP)) {
      Assert.assertTrue(programLifecycleService.list(NamespaceId.DEFAULT,type).isEmpty());
    }
  }
  authorizer.grant(applicationId.program(ProgramType.FLOW,AllProgramsApp.NoOpFlow.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  authorizer.grant(applicationId.program(ProgramType.SERVICE,AllProgramsApp.NoOpService.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  authorizer.grant(applicationId.program(ProgramType.WORKER,AllProgramsApp.NoOpWorker.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  authorizer.grant(applicationId.program(ProgramType.SPARK,AllProgramsApp.NoOpSpark.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  authorizer.grant(applicationId.program(ProgramType.MAPREDUCE,AllProgramsApp.NoOpMR.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  authorizer.grant(applicationId.program(ProgramType.MAPREDUCE,AllProgramsApp.NoOpMR2.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  authorizer.grant(applicationId.program(ProgramType.WORKFLOW,AllProgramsApp.NoOpWorkflow.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  for (  ProgramType type : ProgramType.values()) {
    if (!type.equals(ProgramType.CUSTOM_ACTION) && !type.equals(ProgramType.WEBAPP)) {
      Assert.assertFalse(programLifecycleService.list(NamespaceId.DEFAULT,type).isEmpty());
      SecurityRequestContext.setUserId("String_Node_Str");
      Assert.assertTrue(programLifecycleService.list(NamespaceId.DEFAULT,type).isEmpty());
      SecurityRequestContext.setUserId("String_Node_Str");
    }
  }
}

Fixed version (ground truth):
@Test public void testProgramList() throws Exception {
  SecurityRequestContext.setUserId(ALICE.getName());
  ApplicationId applicationId=NamespaceId.DEFAULT.app(AllProgramsApp.NAME);
  Map<EntityId,Set<Action>> neededPrivileges=ImmutableMap.<EntityId,Set<Action>>builder().put(applicationId,EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.artifact(AllProgramsApp.class.getSimpleName(),"String_Node_Str"),EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME),EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME2),EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME3),EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.dataset(AllProgramsApp.DS_WITH_SCHEMA_NAME),EnumSet.of(Action.ADMIN)).put(NamespaceId.DEFAULT.stream(AllProgramsApp.STREAM_NAME),EnumSet.of(Action.ADMIN)).build();
  setUpPrivilegesAndExpectFailedDeploy(neededPrivileges);
  AppFabricTestHelper.deployApplication(Id.Namespace.DEFAULT,AllProgramsApp.class,null,cConf);
  for (  ProgramType type : ProgramType.values()) {
    if (!type.equals(ProgramType.CUSTOM_ACTION) && !type.equals(ProgramType.WEBAPP)) {
      Assert.assertTrue(programLifecycleService.list(NamespaceId.DEFAULT,type).isEmpty());
    }
  }
  authorizer.grant(applicationId.program(ProgramType.FLOW,AllProgramsApp.NoOpFlow.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  authorizer.grant(applicationId.program(ProgramType.SERVICE,AllProgramsApp.NoOpService.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  authorizer.grant(applicationId.program(ProgramType.WORKER,AllProgramsApp.NoOpWorker.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  authorizer.grant(applicationId.program(ProgramType.SPARK,AllProgramsApp.NoOpSpark.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  authorizer.grant(applicationId.program(ProgramType.MAPREDUCE,AllProgramsApp.NoOpMR.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  authorizer.grant(applicationId.program(ProgramType.MAPREDUCE,AllProgramsApp.NoOpMR2.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  authorizer.grant(applicationId.program(ProgramType.WORKFLOW,AllProgramsApp.NoOpWorkflow.NAME),ALICE,Collections.singleton(Action.EXECUTE));
  for (  ProgramType type : ProgramType.values()) {
    if (!type.equals(ProgramType.CUSTOM_ACTION) && !type.equals(ProgramType.WEBAPP)) {
      Assert.assertFalse(programLifecycleService.list(NamespaceId.DEFAULT,type).isEmpty());
      SecurityRequestContext.setUserId("String_Node_Str");
      Assert.assertTrue(programLifecycleService.list(NamespaceId.DEFAULT,type).isEmpty());
      SecurityRequestContext.setUserId("String_Node_Str");
    }
  }
}