Program: 40339
Project: 40339
Buggy source:
public BgpValidityResource validity(final Asn origin,final IpRange prefix){
  final List<Pair<RoaPrefix,Validity>> roaPrefixes=this.roaPrefixes.findExactAndAllLessSpecific(prefix).stream().flatMap(x -> x.stream()).map(r -> {
    final BgpPreviewEntry bgpPreviewEntry=BgpPreviewEntry.of(origin,prefix,Validity.UNKNOWN);
    final Validity validity=validateBgpRisEntry(Collections.singletonList(r),bgpPreviewEntry);
    return Pair.of(r,validity);
  }
).sorted(Comparator.comparingInt(p -> {
switch (p.getRight()) {
case VALID:
      return 0;
case INVALID_LENGTH:
    return 1;
case INVALID_ASN:
  return 2;
}
return 10;
}
)).collect(Collectors.toList());
final Validity validity=roaPrefixes.stream().findFirst().map(p -> p.getRight()).orElse(Validity.UNKNOWN);
final List<ValidatingRoa> validatingRoaStream=roaPrefixes.stream().flatMap(p -> {
final RoaPrefix r=p.getLeft();
if (r.getTrustAnchor() != null) {
return r.getLocations().stream().map(loc -> ValidatingRoa.of(r.getAsn().toString(),r.getPrefix().toString(),p.getRight().toString(),r.getMaximumLength(),r.getTrustAnchor() == null ? null : r.getTrustAnchor().getName(),loc,null,null));
}
 else if (r.getRoaPrefixAssertionId() != null) {
return Stream.of(ValidatingRoa.of(r.getAsn().toString(),r.getPrefix().toString(),p.getRight().toString(),r.getMaximumLength(),null,null,r.getRoaPrefixAssertionId(),r.getComment()));
}
 else {
return Stream.empty();
}
}
).distinct().collect(Collectors.toList());
return BgpValidityResource.of(origin.toString(),prefix.toString(),validity.toString(),validatingRoaStream);
}

Fixed version (ground truth):
public BgpValidityResource validity(final Asn origin,final IpRange prefix){
  final List<Pair<RoaPrefix,Validity>> roaPrefixes=this.roaPrefixes.findExactAndAllLessSpecific(prefix).stream().flatMap(x -> x.stream()).map(r -> {
    final BgpPreviewEntry bgpPreviewEntry=BgpPreviewEntry.of(origin,prefix,Validity.UNKNOWN);
    final Validity validity=validateBgpRisEntry(Collections.singletonList(r),bgpPreviewEntry);
    return Pair.of(r,validity);
  }
).sorted(Comparator.comparingInt(p -> {
switch (p.getRight()) {
case VALID:
      return 0;
case INVALID_LENGTH:
    return 1;
case INVALID_ASN:
  return 2;
}
return 10;
}
)).collect(Collectors.toList());
final Validity validity=roaPrefixes.stream().findFirst().map(p -> p.getRight()).orElse(Validity.UNKNOWN);
final List<ValidatingRoa> validatingRoaStream=roaPrefixes.stream().flatMap(p -> {
final RoaPrefix r=p.getLeft();
if (r.getTrustAnchor() != null) {
return r.getLocations().stream().map(loc -> ValidatingRoa.of(r.getAsn().toString(),r.getPrefix().toString(),p.getRight().toString(),r.getMaximumLength(),r.getTrustAnchor() == null ? null : r.getTrustAnchor().getName(),loc,null,null));
}
 else if (r.getRoaPrefixAssertionId() != null) {
return Stream.of(ValidatingRoa.of(r.getAsn().toString(),r.getPrefix().toString(),p.getRight().toString(),r.getMaximumLength(),"String_Node_Str",null,r.getRoaPrefixAssertionId(),r.getComment()));
}
 else {
return Stream.empty();
}
}
).distinct().collect(Collectors.toList());
return BgpValidityResource.of(origin.toString(),prefix.toString(),validity.toString(),validatingRoaStream);
}