Program: 51577
Project: 51577
Buggy source:
private Connection getRestrictedConnection(){
  Connection connection=getConnection();
  Role role=new Role();
  Schema schema=connection.getSchema();
  final boolean fail=true;
  Cube salesCube=schema.lookupCube("String_Node_Str",fail);
  final SchemaReader schemaReader=salesCube.getSchemaReader(null);
  Hierarchy storeHierarchy=salesCube.lookupHierarchy("String_Node_Str",false);
  role.grant(schema,Access.ALL_DIMENSIONS);
  role.grant(salesCube,Access.ALL);
  Level nationLevel=Util.lookupHierarchyLevel(storeHierarchy,"String_Node_Str");
  role.grant(storeHierarchy,Access.CUSTOM,nationLevel,null);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.ALL);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.NONE);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.ALL);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.ALL);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.ALL);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.NONE);
  Hierarchy customersHierarchy=salesCube.lookupHierarchy("String_Node_Str",false);
  Level stateProvinceLevel=Util.lookupHierarchyLevel(customersHierarchy,"String_Node_Str");
  Level customersCityLevel=Util.lookupHierarchyLevel(customersHierarchy,"String_Node_Str");
  role.grant(customersHierarchy,Access.CUSTOM,stateProvinceLevel,customersCityLevel);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.ALL);
  role.makeImmutable();
  connection.setRole(role);
  return connection;
}

Fixed version (ground truth):
/** 
 * @param restrictCustomers true to restrict access to the customersdimension. This will change the defaultMember of the dimension, all cell values will be null because there are no sales data for Canada
 */
private Connection getRestrictedConnection(boolean restrictCustomers){
  Connection connection=getConnection();
  Role role=new Role();
  Schema schema=connection.getSchema();
  final boolean fail=true;
  Cube salesCube=schema.lookupCube("String_Node_Str",fail);
  final SchemaReader schemaReader=salesCube.getSchemaReader(null);
  Hierarchy storeHierarchy=salesCube.lookupHierarchy("String_Node_Str",false);
  role.grant(schema,Access.ALL_DIMENSIONS);
  role.grant(salesCube,Access.ALL);
  Level nationLevel=Util.lookupHierarchyLevel(storeHierarchy,"String_Node_Str");
  role.grant(storeHierarchy,Access.CUSTOM,nationLevel,null);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.ALL);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.NONE);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.ALL);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.ALL);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.ALL);
  role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.NONE);
  if (restrictCustomers) {
    Hierarchy customersHierarchy=salesCube.lookupHierarchy("String_Node_Str",false);
    Level stateProvinceLevel=Util.lookupHierarchyLevel(customersHierarchy,"String_Node_Str");
    Level customersCityLevel=Util.lookupHierarchyLevel(customersHierarchy,"String_Node_Str");
    role.grant(customersHierarchy,Access.CUSTOM,stateProvinceLevel,customersCityLevel);
    role.grant(schemaReader.getMemberByUniqueName(Util.explode("String_Node_Str"),fail),Access.ALL);
  }
  role.makeImmutable();
  connection.setRole(role);
  return connection;
}