Program: 108933
Project: 108933
Buggy source:
private void analyze(){
  if (model == null) {
    return;
  }
  ModelConfiguration config=model.getOutputConfig();
  if (config == null) {
    config=model.getInputConfig();
  }
  DataHandle data;
  if (target == ModelPart.INPUT) {
    data=config.getInput().getHandle();
  }
 else {
    data=model.getOutput();
  }
  if ((config == null) || (data == null)) {
    reset();
    return;
  }
  if (data != null && model.getViewConfig().isSubset()) {
    data=data.getView();
  }
  final int index=data.getColumnIndexOf(attribute);
  if (index == -1) {
    clearCache();
    reset();
    return;
  }
  if (cache.containsKey(attribute)) {
    return;
  }
  final AttributeType type=config.getInput().getDefinition().getAttributeType(attribute);
  Hierarchy hierarchy=null;
  if (type instanceof Hierarchy) {
    hierarchy=(Hierarchy)type;
  }
 else   if (type == AttributeType.SENSITIVE_ATTRIBUTE) {
    hierarchy=config.getHierarchy(attribute);
  }
  final Map<String,Double> map=new HashMap<String,Double>();
  for (int i=0; i < data.getNumRows(); i++) {
    final String val=data.getValue(i,index);
    if (!map.containsKey(val)) {
      map.put(val,1d);
    }
 else {
      map.put(val,map.get(val) + 1);
    }
  }
  final String[] dvals;
  if (hierarchy != null && hierarchy.getHierarchy() != null && hierarchy.getHierarchy().length != 0) {
    final int level=data.getGeneralization(attribute);
    final List<String> list=new ArrayList<String>();
    final Set<String> done=new HashSet<String>();
    final String[][] h=hierarchy.getHierarchy();
    for (int i=0; i < h.length; i++) {
      final String val=h[i][level];
      if (map.containsKey(val)) {
        if (!done.contains(val)) {
          list.add(val);
          done.add(val);
        }
      }
    }
    if (model.getAnonymizer() != null && map.containsKey(model.getAnonymizer().getSuppressionString()) && !done.contains(model.getAnonymizer().getSuppressionString())) {
      list.add(model.getAnonymizer().getSuppressionString());
    }
    dvals=list.toArray(new String[]{});
  }
 else {
    final DataType<?> dtype=data.getDataType(attribute);
    final String[] v=new String[map.size()];
    int i=0;
    for (    final String s : map.keySet()) {
      v[i++]=s;
    }
    Arrays.sort(v,new Comparator<String>(){
      @Override public int compare(      final String arg0,      final String arg1){
        try {
          return dtype.compare(arg0,arg1);
        }
 catch (        final Exception e) {
          throw new RuntimeException(e);
        }
      }
    }
);
    dvals=v;
  }
  double sum=0;
  for (  final double i : map.values()) {
    sum+=i;
  }
  final double[] distribution=new double[map.size()];
  for (int i=0; i < dvals.length; i++) {
    distribution[i]=map.get(dvals[i]) / sum;
  }
  cache.put(attribute,distribution);
}

Fixed version (ground truth):
private void analyze(){
  if (model == null) {
    return;
  }
  ModelConfiguration config=model.getOutputConfig();
  if (config == null) {
    config=model.getInputConfig();
  }
  DataHandle data=getHandle();
  if ((config == null) || (data == null)) {
    reset();
    return;
  }
  if (data != null && model.getViewConfig().isSubset()) {
    data=data.getView();
  }
  final int index=data.getColumnIndexOf(attribute);
  if (index == -1) {
    clearCache();
    reset();
    return;
  }
  if (cache.containsKey(attribute)) {
    return;
  }
  final AttributeType type=config.getInput().getDefinition().getAttributeType(attribute);
  Hierarchy hierarchy=null;
  if (type instanceof Hierarchy) {
    hierarchy=(Hierarchy)type;
  }
 else   if (type == AttributeType.SENSITIVE_ATTRIBUTE) {
    hierarchy=config.getHierarchy(attribute);
  }
  final Map<String,Double> map=new HashMap<String,Double>();
  for (int i=0; i < data.getNumRows(); i++) {
    final String val=data.getValue(i,index);
    if (!map.containsKey(val)) {
      map.put(val,1d);
    }
 else {
      map.put(val,map.get(val) + 1);
    }
  }
  final String[] dvals;
  if (hierarchy != null && hierarchy.getHierarchy() != null && hierarchy.getHierarchy().length != 0) {
    final int level=data.getGeneralization(attribute);
    final List<String> list=new ArrayList<String>();
    final Set<String> done=new HashSet<String>();
    final String[][] h=hierarchy.getHierarchy();
    for (int i=0; i < h.length; i++) {
      final String val=h[i][level];
      if (map.containsKey(val)) {
        if (!done.contains(val)) {
          list.add(val);
          done.add(val);
        }
      }
    }
    if (model.getAnonymizer() != null && map.containsKey(model.getAnonymizer().getSuppressionString()) && !done.contains(model.getAnonymizer().getSuppressionString())) {
      list.add(model.getAnonymizer().getSuppressionString());
    }
    dvals=list.toArray(new String[]{});
  }
 else {
    final DataType<?> dtype=data.getDataType(attribute);
    final String[] v=new String[map.size()];
    int i=0;
    for (    final String s : map.keySet()) {
      v[i++]=s;
    }
    Arrays.sort(v,new Comparator<String>(){
      @Override public int compare(      final String arg0,      final String arg1){
        try {
          return dtype.compare(arg0,arg1);
        }
 catch (        final Exception e) {
          throw new RuntimeException(e);
        }
      }
    }
);
    dvals=v;
  }
  double sum=0;
  for (  final double i : map.values()) {
    sum+=i;
  }
  final double[] distribution=new double[map.size()];
  for (int i=0; i < dvals.length; i++) {
    distribution[i]=map.get(dvals[i]) / sum;
  }
  cache.put(attribute,distribution);
}