Program: 135821
Project: 135821
Buggy source:
/** 
 * Decode a RawPacket into an EthernetPacket
 * @param packetReceived -- data from wire to deserialize
 * @return
 * @throws org.opendaylight.controller.sal.packet.BufferException
 */
@Override public EthernetPacketReceived decode(PacketReceived packetReceived){
  byte[] data=packetReceived.getPayload();
  EthernetPacketReceivedBuilder builder=new EthernetPacketReceivedBuilder();
  RawPacketBuilder rpb=new RawPacketBuilder().setIngress(packetReceived.getIngress()).setConnectionCookie(packetReceived.getConnectionCookie()).setFlowCookie(packetReceived.getFlowCookie()).setTableId(packetReceived.getTableId()).setPacketInReason(packetReceived.getPacketInReason()).setPayloadOffset(0).setPayloadLength(data.length);
  if (packetReceived.getMatch() != null) {
    rpb.setMatch(new MatchBuilder(packetReceived.getMatch()).build());
  }
  RawPacket rp=rpb.build();
  ArrayList<PacketChain> packetChain=new ArrayList<PacketChain>();
  packetChain.add(new PacketChainBuilder().setPacket(rp).build());
  try {
    EthernetPacketBuilder epBuilder=new EthernetPacketBuilder();
    epBuilder.setDestinationMac(new MacAddress(HexEncode.bytesToHexStringFormat(BitBufferHelper.getBits(data,0,48))));
    epBuilder.setSourceMac(new MacAddress(HexEncode.bytesToHexStringFormat(BitBufferHelper.getBits(data,48,48))));
    Integer nextField=BitBufferHelper.getInt(BitBufferHelper.getBits(data,96,16));
    int extraHeaderBits=0;
    ArrayList<Header8021q> headerList=new ArrayList<Header8021q>();
    while (nextField.equals(ETHERTYPE_8021Q) || nextField.equals(ETHERTYPE_QINQ)) {
      Header8021qBuilder hBuilder=new Header8021qBuilder();
      hBuilder.setTPID(Header8021qType.forValue(nextField));
      byte[] vlanBytes=BitBufferHelper.getBits(data,112 + extraHeaderBits,16);
      hBuilder.setPriorityCode((short)((vlanBytes[0] & 0xff) >> 5));
      hBuilder.setDropEligible(1 == (((vlanBytes[0] & 0xff) & 0x10) >> 4));
      vlanBytes[0]=(byte)(vlanBytes[0] & 0x0F);
      hBuilder.setVlan(new VlanId(BitBufferHelper.getInt(vlanBytes)));
      headerList.add(hBuilder.build());
      nextField=BitBufferHelper.getInt(BitBufferHelper.getBits(data,128 + extraHeaderBits,16));
      extraHeaderBits+=32;
    }
    if (!headerList.isEmpty()) {
      epBuilder.setHeader8021q(headerList);
    }
    if (nextField >= ETHERTYPE_MIN) {
      epBuilder.setEthertype(KnownEtherType.forValue(nextField));
    }
 else     if (nextField <= LENGTH_MAX) {
      epBuilder.setEthernetLength(nextField);
    }
 else {
      _logger.debug("String_Node_Str" + nextField);
    }
    int payloadStart=(112 + extraHeaderBits) / NetUtils.NumBitsInAByte;
    int payloadEnd=data.length - 4;
    epBuilder.setPayloadOffset(payloadStart);
    epBuilder.setPayloadLength(payloadEnd - payloadStart);
    epBuilder.setCrc(BitBufferHelper.getLong(BitBufferHelper.getBits(data,(data.length - 4) * NetUtils.NumBitsInAByte,32)));
    packetChain.add(new PacketChainBuilder().setPacket(epBuilder.build()).build());
    builder.setPayload(data);
  }
 catch (  BufferException be) {
    _logger.info("String_Node_Str");
  }
  builder.setPacketChain(packetChain);
  return builder.build();
}

Fixed version (ground truth):
/** 
 * Decode a RawPacket into an EthernetPacket
 * @param packetReceived -- data from wire to deserialize
 * @return
 */
@Override public EthernetPacketReceived decode(PacketReceived packetReceived){
  byte[] data=packetReceived.getPayload();
  EthernetPacketReceivedBuilder builder=new EthernetPacketReceivedBuilder();
  RawPacketBuilder rpb=new RawPacketBuilder().setIngress(packetReceived.getIngress()).setConnectionCookie(packetReceived.getConnectionCookie()).setFlowCookie(packetReceived.getFlowCookie()).setTableId(packetReceived.getTableId()).setPacketInReason(packetReceived.getPacketInReason()).setPayloadOffset(0).setPayloadLength(data.length);
  if (packetReceived.getMatch() != null) {
    rpb.setMatch(new MatchBuilder(packetReceived.getMatch()).build());
  }
  RawPacket rp=rpb.build();
  ArrayList<PacketChain> packetChain=new ArrayList<PacketChain>();
  packetChain.add(new PacketChainBuilder().setPacket(rp).build());
  try {
    EthernetPacketBuilder epBuilder=new EthernetPacketBuilder();
    epBuilder.setDestinationMac(new MacAddress(HexEncode.bytesToHexStringFormat(BitBufferHelper.getBits(data,0,48))));
    epBuilder.setSourceMac(new MacAddress(HexEncode.bytesToHexStringFormat(BitBufferHelper.getBits(data,48,48))));
    Integer nextField=BitBufferHelper.getInt(BitBufferHelper.getBits(data,96,16));
    int extraHeaderBits=0;
    ArrayList<Header8021q> headerList=new ArrayList<Header8021q>();
    while (nextField.equals(ETHERTYPE_8021Q) || nextField.equals(ETHERTYPE_QINQ)) {
      Header8021qBuilder hBuilder=new Header8021qBuilder();
      hBuilder.setTPID(Header8021qType.forValue(nextField));
      byte[] vlanBytes=BitBufferHelper.getBits(data,112 + extraHeaderBits,16);
      hBuilder.setPriorityCode((short)((vlanBytes[0] & 0xff) >> 5));
      hBuilder.setDropEligible(1 == (((vlanBytes[0] & 0xff) & 0x10) >> 4));
      vlanBytes[0]=(byte)(vlanBytes[0] & 0x0F);
      hBuilder.setVlan(new VlanId(BitBufferHelper.getInt(vlanBytes)));
      headerList.add(hBuilder.build());
      nextField=BitBufferHelper.getInt(BitBufferHelper.getBits(data,128 + extraHeaderBits,16));
      extraHeaderBits+=32;
    }
    if (!headerList.isEmpty()) {
      epBuilder.setHeader8021q(headerList);
    }
    if (nextField >= ETHERTYPE_MIN) {
      epBuilder.setEthertype(KnownEtherType.forValue(nextField));
    }
 else     if (nextField <= LENGTH_MAX) {
      epBuilder.setEthernetLength(nextField);
    }
 else {
      _logger.debug("String_Node_Str" + nextField);
    }
    int payloadStart=(112 + extraHeaderBits) / NetUtils.NumBitsInAByte;
    int payloadEnd=data.length - 4;
    epBuilder.setPayloadOffset(payloadStart);
    epBuilder.setPayloadLength(payloadEnd - payloadStart);
    epBuilder.setCrc(BitBufferHelper.getLong(BitBufferHelper.getBits(data,(data.length - 4) * NetUtils.NumBitsInAByte,32)));
    packetChain.add(new PacketChainBuilder().setPacket(epBuilder.build()).build());
    builder.setPayload(data);
  }
 catch (  BufferException be) {
    _logger.info("String_Node_Str");
  }
  builder.setPacketChain(packetChain);
  return builder.build();
}