Program: 43467
Project: 43467
Buggy source:
private Link evalLink(DatabaseMeta db,Connection conn,Mirror<?> mirror,Field field){
  try {
    One one=field.getAnnotation(One.class);
    if (null != one) {
      Mirror<?> ta=Mirror.me(one.target());
      Field referFld=mirror.getField(one.field());
      Field targetPkFld=lookupPkByReferField(ta,referFld);
      return Link.getLinkForOne(mirror,field,ta.getType(),referFld,targetPkFld);
    }
    Many many=field.getAnnotation(Many.class);
    if (null != many) {
      Mirror<?> ta=Mirror.me(many.target());
      Field pkFld;
      Field targetReferFld;
      if (Strings.isBlank(many.field())) {
        pkFld=null;
        targetReferFld=null;
      }
 else {
        targetReferFld=ta.getField(many.field());
        pkFld=lookupPkByReferField(mirror,targetReferFld);
      }
      return Link.getLinkForMany(mirror,field,ta.getType(),targetReferFld,pkFld,many.key());
    }
    ManyMany mm=field.getAnnotation(ManyMany.class);
    if (null != mm) {
      Statement stat=null;
      ResultSet rs=null;
      ResultSetMetaData rsmd=null;
      boolean fromName=false;
      boolean toName=false;
      try {
        stat=conn.createStatement();
        Segment tableName=new CharSegment(mm.relation());
        rs=stat.executeQuery(db.getResultSetMetaSql(TableName.render(tableName)));
        rsmd=rs.getMetaData();
        fromName=!Daos.isIntLikeColumn(rsmd,mm.from());
        toName=!Daos.isIntLikeColumn(rsmd,mm.to());
      }
 catch (      Exception e) {
        if (log.isWarnEnabled())         log.warnf("String_Node_Str" + "String_Node_Str",mm.relation(),mm.from(),mm.to());
      }
 finally {
        Daos.safeClose(stat,rs);
      }
      Mirror<?> ta=Mirror.me(mm.target());
      Field selfPk=mirror.getField(fromName ? Name.class : Id.class);
      Field targetPk=ta.getField(toName ? Name.class : Id.class);
      return Link.getLinkForManyMany(mirror,field,ta.getType(),selfPk,targetPk,mm.key(),mm.relation(),mm.from(),mm.to());
    }
  }
 catch (  NoSuchFieldException e) {
    throw Lang.makeThrow("String_Node_Str",field.getName(),mirror.getType().getName(),e.getMessage());
  }
  return null;
}

Fixed version (ground truth):
protected Link evalLink(DatabaseMeta db,Connection conn,Mirror<?> mirror,Field field){
  try {
    One one=field.getAnnotation(One.class);
    if (null != one) {
      Mirror<?> ta=Mirror.me(one.target());
      Field referFld=mirror.getField(one.field());
      Field targetPkFld=lookupPkByReferField(ta,referFld);
      return Link.getLinkForOne(mirror,field,ta.getType(),referFld,targetPkFld);
    }
    Many many=field.getAnnotation(Many.class);
    if (null != many) {
      Mirror<?> ta=Mirror.me(many.target());
      Field pkFld;
      Field targetReferFld;
      if (Strings.isBlank(many.field())) {
        pkFld=null;
        targetReferFld=null;
      }
 else {
        targetReferFld=ta.getField(many.field());
        pkFld=lookupPkByReferField(mirror,targetReferFld);
      }
      return Link.getLinkForMany(mirror,field,ta.getType(),targetReferFld,pkFld,many.key());
    }
    ManyMany mm=field.getAnnotation(ManyMany.class);
    if (null != mm) {
      Statement stat=null;
      ResultSet rs=null;
      ResultSetMetaData rsmd=null;
      boolean fromName=false;
      boolean toName=false;
      try {
        stat=conn.createStatement();
        Segment tableName=new CharSegment(mm.relation());
        rs=stat.executeQuery(db.getResultSetMetaSql(TableName.render(tableName)));
        rsmd=rs.getMetaData();
        fromName=!Daos.isIntLikeColumn(rsmd,mm.from());
        toName=!Daos.isIntLikeColumn(rsmd,mm.to());
      }
 catch (      Exception e) {
        if (log.isWarnEnabled())         log.warnf("String_Node_Str" + "String_Node_Str",mm.relation(),mm.from(),mm.to());
      }
 finally {
        Daos.safeClose(stat,rs);
      }
      Mirror<?> ta=Mirror.me(mm.target());
      Field selfPk=mirror.getField(fromName ? Name.class : Id.class);
      Field targetPk=ta.getField(toName ? Name.class : Id.class);
      return Link.getLinkForManyMany(mirror,field,ta.getType(),selfPk,targetPk,mm.key(),mm.relation(),mm.from(),mm.to());
    }
  }
 catch (  NoSuchFieldException e) {
    throw Lang.makeThrow("String_Node_Str",field.getName(),mirror.getType().getName(),e.getMessage());
  }
  return null;
}