Program: 40825
Project: 40825
Buggy source:
/** 
 * This function decodes a half-decoded Mode S reply to its deepest possible specialization. Use getType() to check its actual type afterwards.
 * @param modes the incompletely decoded Mode S message
 * @return an instance of the most specialized ModeSReply possible
 * @throws UnspecifiedFormatError if format is not specified
 * @throws BadFormatException if format contains error
 */
public static ModeSReply genericDecoder(ModeSReply modes) throws BadFormatException, UnspecifiedFormatError {
switch (modes.getDownlinkFormat()) {
case 0:
    return new ShortACAS(modes);
case 4:
  return new AltitudeReply(modes);
case 5:
return new IdentifyReply(modes);
case 11:
return new AllCallReply(modes);
case 16:
return new LongACAS(modes);
case 17:
case 18:
case 19:
if (modes.getDownlinkFormat() == 17 | modes.getDownlinkFormat() == 18 && modes.getFirstField() < 2 | modes.getDownlinkFormat() == 19 && modes.getFirstField() == 0) {
ExtendedSquitter es1090=new ExtendedSquitter(modes);
byte ftc=es1090.getFormatTypeCode();
if (ftc >= 1 && ftc <= 4) return new IdentificationMsg(es1090);
if (ftc >= 5 && ftc <= 8) return new SurfacePositionMsg(es1090);
if ((ftc >= 9 && ftc <= 18) || (ftc >= 20 && ftc <= 22)) return new AirbornePositionMsg(es1090);
if (ftc == 19) {
int subtype=es1090.getMessage()[0] & 0x7;
if (subtype == 1 || subtype == 2) return new VelocityOverGroundMsg(es1090);
 else if (subtype == 3 || subtype == 4) return new AirspeedHeadingMsg(es1090);
}
if (ftc == 28) {
int subtype=es1090.getMessage()[0] & 0x7;
if (subtype == 1) return new EmergencyOrPriorityStatusMsg(es1090);
if (subtype == 2) return new TCASResolutionAdvisoryMsg(es1090);
}
if (ftc == 31) {
int subtype=es1090.getMessage()[0] & 0x7;
if (subtype == 0 || subtype == 1) return new OperationalStatusMsg(es1090);
}
return es1090;
}
 else if (modes.getDownlinkFormat() == 18 && modes.getFirstField() == 6) {
return modes;
}
 else if (modes.getDownlinkFormat() == 18 && modes.getFirstField() < 4 | modes.getDownlinkFormat() == 18 && modes.getFirstField() == 5) {
return modes;
}
 else if (modes.getDownlinkFormat() == 18 && modes.getFirstField() == 4) {
return modes;
}
 else if (modes.getDownlinkFormat() == 19) {
return new MilitaryExtendedSquitter(modes);
}
case 20:
return new CommBAltitudeReply(modes);
case 21:
return new CommBIdentifyReply(modes);
default :
if (modes.getDownlinkFormat() >= 24) return new CommDExtendedLengthMsg(modes);
 else return modes;
}
}

Fixed version (ground truth):
/** 
 * This function decodes a half-decoded Mode S reply to its deepest possible specialization. Use getType() to check its actual type afterwards.
 * @param modes the incompletely decoded Mode S message
 * @return an instance of the most specialized ModeSReply possible
 * @throws UnspecifiedFormatError if format is not specified
 * @throws BadFormatException if format contains error
 */
public static ModeSReply genericDecoder(ModeSReply modes) throws BadFormatException, UnspecifiedFormatError {
switch (modes.getDownlinkFormat()) {
case 0:
    return new ShortACAS(modes);
case 4:
  return new AltitudeReply(modes);
case 5:
return new IdentifyReply(modes);
case 11:
return new AllCallReply(modes);
case 16:
return new LongACAS(modes);
case 17:
case 18:
case 19:
if (modes.getDownlinkFormat() == 17 || modes.getDownlinkFormat() == 18 && modes.getFirstField() < 2 || modes.getDownlinkFormat() == 19 && modes.getFirstField() == 0) {
ExtendedSquitter es1090=new ExtendedSquitter(modes);
byte ftc=es1090.getFormatTypeCode();
if (ftc >= 1 && ftc <= 4) return new IdentificationMsg(es1090);
if (ftc >= 5 && ftc <= 8) return new SurfacePositionMsg(es1090);
if ((ftc >= 9 && ftc <= 18) || (ftc >= 20 && ftc <= 22)) return new AirbornePositionMsg(es1090);
if (ftc == 19) {
int subtype=es1090.getMessage()[0] & 0x7;
if (subtype == 1 || subtype == 2) return new VelocityOverGroundMsg(es1090);
 else if (subtype == 3 || subtype == 4) return new AirspeedHeadingMsg(es1090);
}
if (ftc == 28) {
int subtype=es1090.getMessage()[0] & 0x7;
if (subtype == 1) return new EmergencyOrPriorityStatusMsg(es1090);
if (subtype == 2) return new TCASResolutionAdvisoryMsg(es1090);
}
if (ftc == 31) {
int subtype=es1090.getMessage()[0] & 0x7;
if (subtype == 0 || subtype == 1) return new OperationalStatusMsg(es1090);
}
return es1090;
}
 else if (modes.getDownlinkFormat() == 18 && modes.getFirstField() == 6) {
return modes;
}
 else if (modes.getDownlinkFormat() == 18 && modes.getFirstField() < 4 | modes.getDownlinkFormat() == 18 && modes.getFirstField() == 5) {
return modes;
}
 else if (modes.getDownlinkFormat() == 18 && modes.getFirstField() == 4) {
return modes;
}
 else if (modes.getDownlinkFormat() == 19) {
return new MilitaryExtendedSquitter(modes);
}
return modes;
case 20:
return new CommBAltitudeReply(modes);
case 21:
return new CommBIdentifyReply(modes);
default :
if (modes.getDownlinkFormat() >= 24) return new CommDExtendedLengthMsg(modes);
 else return modes;
}
}