Program: 4749
Project: 4749
Buggy source:
@Test @Category(SlowTests.class) public void testApps() throws Exception {
  try {
    deployApplication(NamespaceId.DEFAULT,DummyApp.class);
    Assert.fail("String_Node_Str");
  }
 catch (  RuntimeException e) {
    Assert.assertTrue(e.getCause() instanceof UnauthorizedException);
  }
  createAuthNamespace();
  Authorizer authorizer=getAuthorizer();
  ApplicationId dummyAppId=AUTH_NAMESPACE.app(DummyApp.class.getSimpleName());
  Map<EntityId,Set<Action>> neededPrivileges=ImmutableMap.<EntityId,Set<Action>>builder().put(dummyAppId,EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.artifact(DummyApp.class.getSimpleName(),"String_Node_Str"),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.dataset("String_Node_Str"),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.stream("String_Node_Str"),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.dataset("String_Node_Str"),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.datasetType(KeyValueTable.class.getName()),EnumSet.of(Action.ADMIN)).build();
  setUpPrivilegeAndRegisterForDeletion(ALICE,neededPrivileges);
  try {
    deployApplication(AUTH_NAMESPACE,DummyApp.class);
    Assert.fail();
  }
 catch (  Exception e) {
  }
  grantAndAssertSuccess(AUTH_NAMESPACE.datasetType(DummyApp.CustomDummyDataset.class.getName()),ALICE,EnumSet.of(Action.ADMIN));
  cleanUpEntities.add(AUTH_NAMESPACE.datasetType(DummyApp.CustomDummyDataset.class.getName()));
  grantAndAssertSuccess(AUTH_NAMESPACE.datasetModule(DummyApp.CustomDummyDataset.class.getName()),ALICE,EnumSet.of(Action.ADMIN));
  cleanUpEntities.add(AUTH_NAMESPACE.datasetModule(DummyApp.CustomDummyDataset.class.getName()));
  ApplicationManager appManager=deployApplication(AUTH_NAMESPACE,DummyApp.class);
  Assert.assertTrue("String_Node_Str",authorizer.listPrivileges(BOB).isEmpty());
  appManager.update(new AppRequest(new ArtifactSummary(DummyApp.class.getSimpleName(),"String_Node_Str")));
  SecurityRequestContext.setUserId(BOB.getName());
  try {
    appManager.update(new AppRequest(new ArtifactSummary(DummyApp.class.getSimpleName(),"String_Node_Str")));
    Assert.fail("String_Node_Str");
  }
 catch (  Exception expected) {
  }
  grantAndAssertSuccess(dummyAppId,BOB,ImmutableSet.of(Action.READ,Action.WRITE));
  try {
    appManager.delete();
  }
 catch (  Exception expected) {
  }
  grantAndAssertSuccess(dummyAppId,BOB,ImmutableSet.of(Action.ADMIN));
  appManager.delete();
  Assert.assertTrue(!getAuthorizer().isVisible(Collections.singleton(dummyAppId),BOB).isEmpty());
  Assert.assertEquals(3,authorizer.listPrivileges(BOB).size());
  SecurityRequestContext.setUserId(ALICE.getName());
  deployApplication(AUTH_NAMESPACE,DummyApp.class);
  Map<EntityId,Set<Action>> anotherAppNeededPrivilege=ImmutableMap.<EntityId,Set<Action>>builder().put(AUTH_NAMESPACE.app(AllProgramsApp.NAME),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.artifact(AllProgramsApp.class.getSimpleName(),"String_Node_Str"),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.dataset(AllProgramsApp.DATASET_NAME),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.dataset(AllProgramsApp.DATASET_NAME2),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.dataset(AllProgramsApp.DATASET_NAME3),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.dataset(AllProgramsApp.DS_WITH_SCHEMA_NAME),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.stream(AllProgramsApp.STREAM_NAME),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.datasetType(ObjectMappedTable.class.getName()),EnumSet.of(Action.ADMIN)).build();
  setUpPrivilegeAndRegisterForDeletion(ALICE,anotherAppNeededPrivilege);
  deployApplication(AUTH_NAMESPACE,AllProgramsApp.class);
  SecurityRequestContext.setUserId(BOB.getName());
  try {
    deleteAllApplications(AUTH_NAMESPACE);
    Assert.fail("String_Node_Str" + "String_Node_Str");
  }
 catch (  UnauthorizedException expected) {
  }
  SecurityRequestContext.setUserId(ALICE.getName());
  deleteAllApplications(AUTH_NAMESPACE);
}

Fixed version (ground truth):
@Test @Category(SlowTests.class) public void testApps() throws Exception {
  try {
    deployApplication(NamespaceId.DEFAULT,DummyApp.class);
    Assert.fail("String_Node_Str");
  }
 catch (  UnauthorizedException e) {
  }
  createAuthNamespace();
  Authorizer authorizer=getAuthorizer();
  ApplicationId dummyAppId=AUTH_NAMESPACE.app(DummyApp.class.getSimpleName());
  Map<EntityId,Set<Action>> neededPrivileges=ImmutableMap.<EntityId,Set<Action>>builder().put(dummyAppId,EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.artifact(DummyApp.class.getSimpleName(),"String_Node_Str"),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.dataset("String_Node_Str"),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.stream("String_Node_Str"),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.dataset("String_Node_Str"),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.datasetType(KeyValueTable.class.getName()),EnumSet.of(Action.ADMIN)).build();
  setUpPrivilegeAndRegisterForDeletion(ALICE,neededPrivileges);
  try {
    deployApplication(AUTH_NAMESPACE,DummyApp.class);
    Assert.fail();
  }
 catch (  UnauthorizedException e) {
  }
  grantAndAssertSuccess(AUTH_NAMESPACE.datasetType(DummyApp.CustomDummyDataset.class.getName()),ALICE,EnumSet.of(Action.ADMIN));
  cleanUpEntities.add(AUTH_NAMESPACE.datasetType(DummyApp.CustomDummyDataset.class.getName()));
  grantAndAssertSuccess(AUTH_NAMESPACE.datasetModule(DummyApp.CustomDummyDataset.class.getName()),ALICE,EnumSet.of(Action.ADMIN));
  cleanUpEntities.add(AUTH_NAMESPACE.datasetModule(DummyApp.CustomDummyDataset.class.getName()));
  ApplicationManager appManager=deployApplication(AUTH_NAMESPACE,DummyApp.class);
  Assert.assertTrue("String_Node_Str",authorizer.listPrivileges(BOB).isEmpty());
  appManager.update(new AppRequest(new ArtifactSummary(DummyApp.class.getSimpleName(),"String_Node_Str")));
  SecurityRequestContext.setUserId(BOB.getName());
  try {
    appManager.update(new AppRequest(new ArtifactSummary(DummyApp.class.getSimpleName(),"String_Node_Str")));
    Assert.fail("String_Node_Str");
  }
 catch (  UnauthorizedException expected) {
  }
  grantAndAssertSuccess(dummyAppId,BOB,ImmutableSet.of(Action.READ,Action.WRITE));
  try {
    appManager.delete();
  }
 catch (  UnauthorizedException expected) {
  }
  grantAndAssertSuccess(dummyAppId,BOB,ImmutableSet.of(Action.ADMIN));
  appManager.delete();
  Assert.assertTrue(!getAuthorizer().isVisible(Collections.singleton(dummyAppId),BOB).isEmpty());
  Assert.assertEquals(3,authorizer.listPrivileges(BOB).size());
  SecurityRequestContext.setUserId(ALICE.getName());
  deployApplication(AUTH_NAMESPACE,DummyApp.class);
  Map<EntityId,Set<Action>> anotherAppNeededPrivilege=ImmutableMap.<EntityId,Set<Action>>builder().put(AUTH_NAMESPACE.app(AllProgramsApp.NAME),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.artifact(AllProgramsApp.class.getSimpleName(),"String_Node_Str"),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.dataset(AllProgramsApp.DATASET_NAME),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.dataset(AllProgramsApp.DATASET_NAME2),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.dataset(AllProgramsApp.DATASET_NAME3),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.dataset(AllProgramsApp.DS_WITH_SCHEMA_NAME),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.stream(AllProgramsApp.STREAM_NAME),EnumSet.of(Action.ADMIN)).put(AUTH_NAMESPACE.datasetType(ObjectMappedTable.class.getName()),EnumSet.of(Action.ADMIN)).build();
  setUpPrivilegeAndRegisterForDeletion(ALICE,anotherAppNeededPrivilege);
  deployApplication(AUTH_NAMESPACE,AllProgramsApp.class);
  SecurityRequestContext.setUserId(BOB.getName());
  try {
    deleteAllApplications(AUTH_NAMESPACE);
    Assert.fail("String_Node_Str" + "String_Node_Str");
  }
 catch (  UnauthorizedException expected) {
  }
  SecurityRequestContext.setUserId(ALICE.getName());
  deleteAllApplications(AUTH_NAMESPACE);
}