Program: 4760
Project: 4760
Buggy source:
@Test public void testDatasetInstances() throws Exception {
  final DatasetId dsId=NamespaceId.DEFAULT.dataset("String_Node_Str");
  final DatasetId dsId1=NamespaceId.DEFAULT.dataset("String_Node_Str");
  DatasetTypeId tableTypeId=NamespaceId.DEFAULT.datasetType(Table.class.getName());
  DatasetId dsId2=NamespaceId.DEFAULT.dataset("String_Node_Str");
  SecurityRequestContext.setUserId(ALICE.getName());
  assertAuthorizationFailure(new DatasetOperationExecutor(){
    @Override public void execute() throws Exception {
      dsFramework.addInstance(Table.class.getName(),dsId,DatasetProperties.EMPTY);
    }
  }
,"String_Node_Str");
  grantAndAssertSuccess(dsId,ALICE,ImmutableSet.of(Action.ADMIN));
  grantAndAssertSuccess(tableTypeId,ALICE,EnumSet.of(Action.ADMIN));
  dsFramework.addInstance(Table.class.getName(),dsId,DatasetProperties.EMPTY);
  Assert.assertTrue(dsFramework.hasInstance(dsId));
  Assert.assertNotNull(dsFramework.getDataset(dsId,ImmutableMap.<String,String>of(),null));
  dsFramework.updateInstance(dsId,DatasetProperties.builder().add("String_Node_Str","String_Node_Str").build());
  SecurityRequestContext.setUserId(BOB.getName());
  assertAuthorizationFailure(new DatasetOperationExecutor(){
    @Override public void execute() throws Exception {
      dsFramework.getDataset(dsId,ImmutableMap.<String,String>of(),null);
    }
  }
,String.format("String_Node_Str",BOB,dsId));
  assertAuthorizationFailure(new DatasetOperationExecutor(){
    @Override public void execute() throws Exception {
      dsFramework.updateInstance(dsId,DatasetProperties.builder().add("String_Node_Str","String_Node_Str").build());
    }
  }
,String.format("String_Node_Str",BOB,Action.ADMIN,dsId));
  assertAuthorizationFailure(new DatasetOperationExecutor(){
    @Override public void execute() throws Exception {
      dsFramework.truncateInstance(dsId);
    }
  }
,String.format("String_Node_Str",BOB,Action.ADMIN,dsId));
  grantAndAssertSuccess(dsId,BOB,ImmutableSet.of(Action.ADMIN));
  dsFramework.updateInstance(dsId,DatasetProperties.builder().add("String_Node_Str","String_Node_Str").build());
  dsFramework.truncateInstance(dsId);
  DatasetSpecification datasetSpec=dsFramework.getDatasetSpec(dsId);
  Assert.assertNotNull(datasetSpec);
  Assert.assertEquals("String_Node_Str",datasetSpec.getProperty("String_Node_Str"));
  grantAndAssertSuccess(dsId1,BOB,ImmutableSet.of(Action.ADMIN));
  grantAndAssertSuccess(dsId2,BOB,ImmutableSet.of(Action.ADMIN));
  grantAndAssertSuccess(tableTypeId,BOB,EnumSet.of(Action.ADMIN));
  dsFramework.addInstance(Table.class.getName(),dsId1,DatasetProperties.EMPTY);
  dsFramework.addInstance(Table.class.getName(),dsId2,DatasetProperties.EMPTY);
  Assert.assertEquals(ImmutableSet.of(dsId,dsId1,dsId2),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  SecurityRequestContext.setUserId(ALICE.getName());
  Assert.assertEquals(ImmutableSet.of(dsId),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  grantAndAssertSuccess(dsId1,ALICE,ImmutableSet.of(Action.EXECUTE));
  grantAndAssertSuccess(dsId2,ALICE,ImmutableSet.of(Action.EXECUTE));
  try {
    dsFramework.deleteAllInstances(NamespaceId.DEFAULT);
    Assert.fail();
  }
 catch (  Exception e) {
    Assert.assertTrue(e.getMessage().contains("String_Node_Str"));
  }
  Assert.assertEquals(ImmutableSet.of(dsId1,dsId2,dsId),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  assertAuthorizationFailure(new DatasetOperationExecutor(){
    @Override public void execute() throws Exception {
      dsFramework.deleteInstance(dsId1);
    }
  }
,String.format("String_Node_Str",dsId1));
  grantAndAssertSuccess(dsId1,ALICE,ImmutableSet.of(Action.ADMIN));
  Assert.assertEquals(ImmutableSet.of(dsId1,dsId2,dsId),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  dsFramework.deleteInstance(dsId1);
  Assert.assertEquals(ImmutableSet.of(dsId2,dsId),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  SecurityRequestContext.setUserId(BOB.getName());
  Assert.assertEquals(ImmutableSet.of(dsId2,dsId),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  dsFramework.deleteInstance(dsId2);
  SecurityRequestContext.setUserId(ALICE.getName());
  dsFramework.deleteInstance(dsId);
  grantAndAssertSuccess(dsId2,ALICE,EnumSet.of(Action.ADMIN));
  dsFramework.addInstance(Table.class.getName(),dsId,DatasetProperties.EMPTY);
  dsFramework.addInstance(Table.class.getName(),dsId1,DatasetProperties.EMPTY);
  dsFramework.addInstance(Table.class.getName(),dsId2,DatasetProperties.EMPTY);
  Assert.assertEquals(ImmutableSet.of(dsId,dsId1,dsId2),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  dsFramework.deleteAllInstances(NamespaceId.DEFAULT);
  Assert.assertTrue(dsFramework.getInstances(NamespaceId.DEFAULT).isEmpty());
}

Fixed version (ground truth):
@Test public void testDatasetInstances() throws Exception {
  final DatasetId dsId=NamespaceId.DEFAULT.dataset("String_Node_Str");
  final DatasetId dsId1=NamespaceId.DEFAULT.dataset("String_Node_Str");
  DatasetId dsId2=NamespaceId.DEFAULT.dataset("String_Node_Str");
  SecurityRequestContext.setUserId(ALICE.getName());
  assertAuthorizationFailure(new DatasetOperationExecutor(){
    @Override public void execute() throws Exception {
      dsFramework.addInstance(Table.class.getName(),dsId,DatasetProperties.EMPTY);
    }
  }
,"String_Node_Str");
  grantAndAssertSuccess(dsId,ALICE,ImmutableSet.of(Action.ADMIN));
  dsFramework.addInstance(Table.class.getName(),dsId,DatasetProperties.EMPTY);
  Assert.assertTrue(dsFramework.hasInstance(dsId));
  Assert.assertNotNull(dsFramework.getDataset(dsId,ImmutableMap.<String,String>of(),null));
  dsFramework.updateInstance(dsId,DatasetProperties.builder().add("String_Node_Str","String_Node_Str").build());
  SecurityRequestContext.setUserId(BOB.getName());
  assertAuthorizationFailure(new DatasetOperationExecutor(){
    @Override public void execute() throws Exception {
      dsFramework.getDataset(dsId,ImmutableMap.<String,String>of(),null);
    }
  }
,String.format("String_Node_Str",BOB,dsId));
  assertAuthorizationFailure(new DatasetOperationExecutor(){
    @Override public void execute() throws Exception {
      dsFramework.updateInstance(dsId,DatasetProperties.builder().add("String_Node_Str","String_Node_Str").build());
    }
  }
,String.format("String_Node_Str",BOB,Action.ADMIN,dsId));
  assertAuthorizationFailure(new DatasetOperationExecutor(){
    @Override public void execute() throws Exception {
      dsFramework.truncateInstance(dsId);
    }
  }
,String.format("String_Node_Str",BOB,Action.ADMIN,dsId));
  grantAndAssertSuccess(dsId,BOB,ImmutableSet.of(Action.ADMIN));
  dsFramework.updateInstance(dsId,DatasetProperties.builder().add("String_Node_Str","String_Node_Str").build());
  dsFramework.truncateInstance(dsId);
  DatasetSpecification datasetSpec=dsFramework.getDatasetSpec(dsId);
  Assert.assertNotNull(datasetSpec);
  Assert.assertEquals("String_Node_Str",datasetSpec.getProperty("String_Node_Str"));
  grantAndAssertSuccess(dsId1,BOB,ImmutableSet.of(Action.ADMIN));
  grantAndAssertSuccess(dsId2,BOB,ImmutableSet.of(Action.ADMIN));
  dsFramework.addInstance(Table.class.getName(),dsId1,DatasetProperties.EMPTY);
  dsFramework.addInstance(Table.class.getName(),dsId2,DatasetProperties.EMPTY);
  Assert.assertEquals(ImmutableSet.of(dsId,dsId1,dsId2),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  SecurityRequestContext.setUserId(ALICE.getName());
  Assert.assertEquals(ImmutableSet.of(dsId),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  grantAndAssertSuccess(dsId1,ALICE,ImmutableSet.of(Action.EXECUTE));
  grantAndAssertSuccess(dsId2,ALICE,ImmutableSet.of(Action.EXECUTE));
  try {
    dsFramework.deleteAllInstances(NamespaceId.DEFAULT);
    Assert.fail();
  }
 catch (  Exception e) {
    Assert.assertTrue(e.getMessage().contains("String_Node_Str"));
  }
  Assert.assertEquals(ImmutableSet.of(dsId1,dsId2,dsId),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  assertAuthorizationFailure(new DatasetOperationExecutor(){
    @Override public void execute() throws Exception {
      dsFramework.deleteInstance(dsId1);
    }
  }
,String.format("String_Node_Str",dsId1));
  grantAndAssertSuccess(dsId1,ALICE,ImmutableSet.of(Action.ADMIN));
  Assert.assertEquals(ImmutableSet.of(dsId1,dsId2,dsId),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  dsFramework.deleteInstance(dsId1);
  Assert.assertEquals(ImmutableSet.of(dsId2,dsId),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  SecurityRequestContext.setUserId(BOB.getName());
  Assert.assertEquals(ImmutableSet.of(dsId2,dsId),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  dsFramework.deleteInstance(dsId2);
  SecurityRequestContext.setUserId(ALICE.getName());
  dsFramework.deleteInstance(dsId);
  grantAndAssertSuccess(dsId2,ALICE,EnumSet.of(Action.ADMIN));
  dsFramework.addInstance(Table.class.getName(),dsId,DatasetProperties.EMPTY);
  dsFramework.addInstance(Table.class.getName(),dsId1,DatasetProperties.EMPTY);
  dsFramework.addInstance(Table.class.getName(),dsId2,DatasetProperties.EMPTY);
  Assert.assertEquals(ImmutableSet.of(dsId,dsId1,dsId2),summaryToDatasetIdSet(dsFramework.getInstances(NamespaceId.DEFAULT)));
  dsFramework.deleteAllInstances(NamespaceId.DEFAULT);
  Assert.assertTrue(dsFramework.getInstances(NamespaceId.DEFAULT).isEmpty());
}