Merge pull request #10093 from smowton/smowton/feature/java-singular-locations

Java: pick an arbitrary representative location when an entity has many candidate locations.
This commit is contained in:
Chris Smowton
2022-08-22 09:32:43 +01:00
committed by GitHub
11 changed files with 131 additions and 18 deletions

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Classes and methods that are seen with several different paths during the extraction process (for example, packaged into different JAR files) now report an arbitrarily selected location via their `getLocation` and `hasLocationInfo` predicates, rather than reporting all of them. This may lead to reduced alert duplication.

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, _, _, _, _)
}