Program: 4625
Project: 4625
Buggy source:
/** 
 * This method calculates the quality of service for a given host.  The calculation is some function of whether or not the host is busy, whether or not the host has ever received an incoming connection, etc. Moved this code from SearchView to here permanently, so we avoid duplication.  It makes sense from a data point of view, but this method isn't really essential an essential method.
 * @return a int from -1 to 3, with -1 for "never work" and 3 for "alwayswork".  Typically a return value of N means N+1 stars will be displayed in the GUI.
 * @param iFirewalled switch to indicate if the client is firewalled ornot.  See RouterService.acceptingIncomingConnection or Acceptor for details.  
 */
public int calculateQualityOfService(boolean iFirewalled){
  final int YES=1;
  final int MAYBE=0;
  final int NO=-1;
  int busy;
  try {
    busy=this.getIsBusy() ? YES : NO;
  }
 catch (  BadPacketException e) {
    busy=MAYBE;
  }
  boolean isMCastReply;
  try {
    isMCastReply=this.isReplyToMulticastQuery();
  }
 catch (  BadPacketException e) {
    isMCastReply=false;
  }
  int heFirewalled;
  if (isMCastReply) {
    iFirewalled=false;
    heFirewalled=NO;
  }
 else   if (NetworkUtils.isPrivateAddress(this.getIPBytes())) {
    heFirewalled=YES;
  }
 else {
    try {
      heFirewalled=this.getNeedsPush() ? YES : NO;
    }
 catch (    BadPacketException e) {
      heFirewalled=MAYBE;
    }
  }
  if (Arrays.equals(_address,RouterService.getAddress())) {
    return 3;
  }
 else   if (isMCastReply) {
    return 4;
  }
 else   if (iFirewalled && heFirewalled == YES) {
    return -1;
  }
 else   if (busy == MAYBE || heFirewalled == MAYBE) {
    return 0;
  }
 else   if (busy == YES) {
    Assert.that(heFirewalled == NO || !iFirewalled);
    if (heFirewalled == YES)     return 0;
 else     return 1;
  }
 else   if (busy == NO) {
    Assert.that(heFirewalled == NO || !iFirewalled);
    if (heFirewalled == YES)     return 2;
 else     return 3;
  }
 else {
    Assert.that(false,"String_Node_Str");
    return -1;
  }
}

Fixed version (ground truth):
/** 
 * This method calculates the quality of service for a given host.  The calculation is some function of whether or not the host is busy, whether or not the host has ever received an incoming connection, etc. Moved this code from SearchView to here permanently, so we avoid duplication.  It makes sense from a data point of view, but this method isn't really essential an essential method.
 * @return a int from -1 to 3, with -1 for "never work" and 3 for "alwayswork".  Typically a return value of N means N+1 stars will be displayed in the GUI.
 * @param iFirewalled switch to indicate if the client is firewalled ornot.  See RouterService.acceptingIncomingConnection or Acceptor for details.  
 */
public int calculateQualityOfService(boolean iFirewalled){
  final int YES=1;
  final int MAYBE=0;
  final int NO=-1;
  int busy;
  try {
    busy=this.getIsBusy() ? YES : NO;
  }
 catch (  BadPacketException e) {
    busy=MAYBE;
  }
  boolean isMCastReply;
  try {
    isMCastReply=this.isReplyToMulticastQuery();
  }
 catch (  BadPacketException e) {
    isMCastReply=false;
  }
  int heFirewalled;
  if (isMCastReply) {
    iFirewalled=false;
    heFirewalled=NO;
  }
 else   if (NetworkUtils.isPrivateAddress(this.getIPBytes())) {
    heFirewalled=YES;
  }
 else {
    try {
      heFirewalled=this.getNeedsPush() ? YES : NO;
    }
 catch (    BadPacketException e) {
      heFirewalled=MAYBE;
    }
  }
  boolean hasPushProxies=false;
  if ((this.getPushProxies() != null) && (this.getPushProxies().size() > 1))   hasPushProxies=true;
  if (Arrays.equals(_address,RouterService.getAddress())) {
    return 3;
  }
 else   if (isMCastReply) {
    return 4;
  }
 else   if (iFirewalled && heFirewalled == YES) {
    return -1;
  }
 else   if (busy == MAYBE || heFirewalled == MAYBE) {
    return 0;
  }
 else   if (busy == YES) {
    Assert.that(heFirewalled == NO || !iFirewalled);
    if (heFirewalled == YES)     return 0;
 else     return 1;
  }
 else   if (busy == NO) {
    Assert.that(heFirewalled == NO || !iFirewalled);
    if (heFirewalled == YES && !hasPushProxies)     return 2;
 else     return 3;
  }
 else {
    Assert.that(false,"String_Node_Str");
    return -1;
  }
}