Program: 24798
Project: 24798
Buggy source:
/** 
 * This is the worker function that runs in a separate thread and keeps an eye out for runaways.
 */
private static void watch(){
  try {
    while (true) {
      Thread.sleep(1000);
synchronized (beingWatched) {
        long curTime=System.currentTimeMillis();
        int nRunaways=0;
        Iterator iter=beingWatched.values().iterator();
        while (iter.hasNext()) {
          Entry e=(Entry)iter.next();
          if (curTime < e.nextCheckTime) {
            if (e.runaway)             ++nRunaways;
            continue;
          }
          e.runaway=true;
          ++nRunaways;
          long nextTime=Math.min(5000,e.maxTime);
          e.nextCheckTime=curTime + nextTime;
          e.needPrint=true;
        }
        int count=0;
        iter=beingWatched.values().iterator();
        while (iter.hasNext()) {
          Entry e=(Entry)iter.next();
          if (e.runaway)           ++count;
          if (!e.needPrint)           continue;
          String id=Trace.getThreadId(e.thread);
          if (id == null)           id="String_Node_Str";
          double secs=(curTime - e.startTime) / 1000.0;
          String secStr=DecimalFormat.getInstance().format(secs);
          Trace.warning("String_Node_Str" + id + "String_Node_Str"+ "String_Node_Str"+ secStr+ "String_Node_Str"+ count+ "String_Node_Str"+ nRunaways+ "String_Node_Str"+ "String_Node_Str"+ e.descrip);
          try {
            Class c=e.thread.getClass();
            Method m=c.getMethod("String_Node_Str",new Class[0]);
            StackTraceElement[] stackTrace=(StackTraceElement[])m.invoke(e.thread,new Object[0]);
            StringBuffer buf=new StringBuffer();
            for (int i=0; i < stackTrace.length; i++) {
              buf.append("String_Node_Str");
              buf.append(stackTrace[i].toString());
              buf.append("String_Node_Str");
            }
            Trace.warning("String_Node_Str" + buf.toString());
          }
 catch (          Exception exc) {
          }
        }
      }
    }
  }
 catch (  InterruptedException e) {
  }
}

Fixed version (ground truth):
/** 
 * This is the worker function that runs in a separate thread and keeps an eye out for runaways.
 */
private static void watch(){
  try {
    while (true) {
      Thread.sleep(5100);
synchronized (beingWatched) {
        long curTime=System.currentTimeMillis();
        int nRunaways=0;
        Iterator iter=beingWatched.values().iterator();
        while (iter.hasNext()) {
          Entry e=(Entry)iter.next();
          if (curTime < e.nextCheckTime) {
            if (e.runaway)             ++nRunaways;
            continue;
          }
          e.runaway=true;
          ++nRunaways;
          e.needPrint=true;
        }
        int count=0;
        curTime=System.currentTimeMillis();
        iter=beingWatched.values().iterator();
        while (iter.hasNext()) {
          Entry e=(Entry)iter.next();
          if (e.runaway)           ++count;
          if (!e.needPrint)           continue;
          String id=Trace.getThreadId(e.thread);
          if (id == null)           id="String_Node_Str";
          double secs=(curTime - e.startTime) / 1000.0;
          String secStr=DecimalFormat.getInstance().format(secs);
          Trace.warning("String_Node_Str" + id + "String_Node_Str"+ "String_Node_Str"+ secStr+ "String_Node_Str"+ count+ "String_Node_Str"+ nRunaways+ "String_Node_Str"+ "String_Node_Str"+ e.descrip);
          try {
            Class c=e.thread.getClass();
            Method m=c.getMethod("String_Node_Str",new Class[0]);
            StackTraceElement[] stackTrace=(StackTraceElement[])m.invoke(e.thread,new Object[0]);
            StringBuffer buf=new StringBuffer();
            for (int i=0; i < stackTrace.length; i++) {
              buf.append("String_Node_Str");
              buf.append(stackTrace[i].toString());
              buf.append("String_Node_Str");
            }
            Trace.warning("String_Node_Str" + buf.toString());
          }
 catch (          Exception exc) {
          }
        }
        curTime=System.currentTimeMillis();
        iter=beingWatched.values().iterator();
        while (iter.hasNext()) {
          Entry e=(Entry)iter.next();
          if (!e.needPrint)           continue;
          e.needPrint=false;
          e.nextCheckTime=curTime + e.maxTime;
        }
      }
    }
  }
 catch (  InterruptedException e) {
  }
}