Program: 63508
Project: 63508
Buggy source:
/** 
 * INTERNAL: Create primary key values to be used for cache lookup.  The map of primary keys on the reference is keyed on the reference descriptors primary key field names.  Each of these primary keys contains all of the values for a particular key - in the order that they we read in from the document.  For example, if the key field names are A, B, and C, and there are three reference object instances, then the hashmap would have the following: (A=[1,2,3], B=[X,Y,Z], C=[Jim, Joe, Jane]).  If the primary key field names on the reference descriptor contained [B, C, A], then the result of this method call would be reference.primaryKeys=([X, Jim, 1], [Y, Joe, 2], [Z, Jane, 3]).
 * @param reference
 */
private void createPKVectorsFromMap(Reference reference,CollectionReferenceMapping mapping){
  CoreDescriptor referenceDescriptor=mapping.getReferenceDescriptor();
  Vector pks=new Vector();
  if (null == referenceDescriptor) {
    CacheId pkVals=(CacheId)reference.getPrimaryKeyMap().get(null);
    if (null == pkVals) {
      return;
    }
    for (int x=0; x < pkVals.getPrimaryKey().length; x++) {
      Object[] values=new Object[1];
      values[0]=pkVals.getPrimaryKey()[x];
      pks.add(new CacheId(values));
    }
  }
 else {
    List pkFields=referenceDescriptor.getPrimaryKeyFieldNames();
    if (pkFields.isEmpty()) {
      return;
    }
    boolean init=true;
    for (Iterator pkFieldNameIt=pkFields.iterator(); pkFieldNameIt.hasNext(); ) {
      CacheId pkVals=(CacheId)reference.getPrimaryKeyMap().get(pkFieldNameIt.next());
      if (pkVals == null) {
        return;
      }
      if (init) {
        for (int i=0; i < pkVals.getPrimaryKey().length; i++) {
          pks.add(new CacheId(new Object[0]));
        }
        init=false;
      }
      for (int i=0; i < pkVals.getPrimaryKey().length; i++) {
        Object val=pkVals.getPrimaryKey()[i];
        ((CacheId)pks.get(i)).add(val);
      }
    }
  }
  reference.setPrimaryKey(pks);
}

Fixed version (ground truth):
/** 
 * INTERNAL: Create primary key values to be used for cache lookup.  The map of primary keys on the reference is keyed on the reference descriptors primary key field names.  Each of these primary keys contains all of the values for a particular key - in the order that they we read in from the document.  For example, if the key field names are A, B, and C, and there are three reference object instances, then the hashmap would have the following: (A=[1,2,3], B=[X,Y,Z], C=[Jim, Joe, Jane]).  If the primary key field names on the reference descriptor contained [B, C, A], then the result of this method call would be reference.primaryKeys=([X, Jim, 1], [Y, Joe, 2], [Z, Jane, 3]).
 */
private void createPKVectorsFromMap(final Reference reference,final CollectionReferenceMapping mapping){
  final CoreDescriptor referenceDescriptor=mapping.getReferenceDescriptor();
  final Vector<CacheId> pks=new Vector<CacheId>();
  if (null == referenceDescriptor) {
    final CacheId pkVals=(CacheId)reference.getPrimaryKeyMap().get(null);
    if (null == pkVals) {
      return;
    }
    for (int x=0; x < pkVals.getPrimaryKey().length; x++) {
      final Object[] values=new Object[1];
      values[0]=pkVals.getPrimaryKey()[x];
      pks.add(new CacheId(values));
    }
  }
 else {
    final List pkFields=referenceDescriptor.getPrimaryKeyFieldNames();
    if (pkFields.isEmpty()) {
      return;
    }
    boolean init=true;
    for (    Object pkField : pkFields) {
      final CacheId pkVals=(CacheId)reference.getPrimaryKeyMap().get(pkField);
      if (pkVals == null) {
        return;
      }
      if (init) {
        for (int i=0; i < pkVals.getPrimaryKey().length; i++) {
          pks.add(new CacheId(new Object[0]));
        }
        init=false;
      }
      for (int i=0; i < pkVals.getPrimaryKey().length; i++) {
        final Object val=pkVals.getPrimaryKey()[i];
        (pks.get(i)).add(val);
      }
    }
  }
  reference.setPrimaryKey(pks);
}