Java: pick an arbitrary representative location when an entity has many candidate locations.

This commit is contained in:
Chris Smowton
2022-08-18 12:01:09 +01:00
parent 61a2c0dab5
commit 17dd1f64ec

View File

@@ -205,5 +205,19 @@ cached
private predicate fixedHasLocation(Top l, Location loc, File f) {
hasSourceLocation(l, loc, f)
or
hasLocation(l, loc) and not hasSourceLocation(l, _, _) and locations_default(loc, f, _, _, _, _)
// When an entity has more than one location, as it might due to
// e.g. a parameterized generic being seen and extracted in several
// different directories or JAR files, select an arbitrary representative
// location to avoid needlessly duplicating alerts.
//
// Don't do this when the relevant location is in a source file, because
// that is much more unusual and we would rather notice the bug than mask it here.
loc =
min(Location candidateLoc |
hasLocation(l, candidateLoc)
|
candidateLoc order by candidateLoc.getFile().toString()
) and
not hasSourceLocation(l, _, _) and
locations_default(loc, f, _, _, _, _)
}