Skip to content

Commit 17dd1f6

Browse files
committed
Java: pick an arbitrary representative location when an entity has many candidate locations.
1 parent 61a2c0d commit 17dd1f6

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

java/ql/lib/semmle/code/Location.qll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,19 @@ cached
205205
private predicate fixedHasLocation(Top l, Location loc, File f) {
206206
hasSourceLocation(l, loc, f)
207207
or
208-
hasLocation(l, loc) and not hasSourceLocation(l, _, _) and locations_default(loc, f, _, _, _, _)
208+
// When an entity has more than one location, as it might due to
209+
// e.g. a parameterized generic being seen and extracted in several
210+
// different directories or JAR files, select an arbitrary representative
211+
// location to avoid needlessly duplicating alerts.
212+
//
213+
// Don't do this when the relevant location is in a source file, because
214+
// that is much more unusual and we would rather notice the bug than mask it here.
215+
loc =
216+
min(Location candidateLoc |
217+
hasLocation(l, candidateLoc)
218+
|
219+
candidateLoc order by candidateLoc.getFile().toString()
220+
) and
221+
not hasSourceLocation(l, _, _) and
222+
locations_default(loc, f, _, _, _, _)
209223
}

0 commit comments

Comments
 (0)