Skip to content

Commit

Permalink
FindOverridableMethodCall is not thread safe
Browse files Browse the repository at this point in the history
Don't use static maps for analysis specific data, it can't work with
multiple analysis running in same JVM, like it might happen in Eclipse.

Fixes spotbugs#2701
  • Loading branch information
iloveeclipse committed Nov 15, 2023
1 parent f839cac commit 4c7dd15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Currently the versioning policy of this project follows [Semantic Versioning v2.
- Fixed false positive UPM_UNCALLED_PRIVATE_METHOD for method used in JUnit's MethodSource ([[#2379](https://github.com/spotbugs/spotbugs/issues/2379)])
- Use java.nio to load filter files ([[#2684](https://github.com/spotbugs/spotbugs/pull/2684)])
- Eclipse: Do not export javax.annotation packages ([[#2699](https://github.com/spotbugs/spotbugs/pull/2699)])
- Fixed not thread safe FindOverridableMethodCall detector ([[#2701](https://github.com/spotbugs/spotbugs/issues/2701)])

- tbd

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ private static class CallerInfo {
}

// For methods called using the standard way
private static final Map<XMethod, CallerInfo> callerConstructors = new HashMap<>();
private static final Map<XMethod, CallerInfo> callerClones = new HashMap<>();
private static final Map<XMethod, XMethod> callsToOverridable = new HashMap<>();
private static final MultiMap<XMethod, XMethod> callerToCalleeMap = new MultiMap<>(ArrayList.class);
private static final MultiMap<XMethod, XMethod> calleeToCallerMap = new MultiMap<>(ArrayList.class);
private final Map<XMethod, CallerInfo> callerConstructors = new HashMap<>();
private final Map<XMethod, CallerInfo> callerClones = new HashMap<>();
private final Map<XMethod, XMethod> callsToOverridable = new HashMap<>();
private final MultiMap<XMethod, XMethod> callerToCalleeMap = new MultiMap<>(ArrayList.class);
private final MultiMap<XMethod, XMethod> calleeToCallerMap = new MultiMap<>(ArrayList.class);

// For methods called using method references
private static final Map<Integer, CallerInfo> refCallerConstructors = new HashMap<>();
private static final Map<Integer, CallerInfo> refCallerClones = new HashMap<>();
private static final MultiMap<Integer, XMethod> refCalleeToCallerMap = new MultiMap<>(ArrayList.class);
private final Map<Integer, CallerInfo> refCallerConstructors = new HashMap<>();
private final Map<Integer, CallerInfo> refCallerClones = new HashMap<>();
private final MultiMap<Integer, XMethod> refCalleeToCallerMap = new MultiMap<>(ArrayList.class);


private final BugAccumulator bugAccumulator;
Expand Down Expand Up @@ -303,7 +303,7 @@ private boolean checkAndRecordCallBetweenNonOverridableMethods(XMethod caller, X
}

private XMethod getIndirectlyCalledOverridable(XMethod caller) {
return getIndirectlyCalledOverridable(caller, new HashSet<XMethod>());
return getIndirectlyCalledOverridable(caller, new HashSet<>());
}

private XMethod getIndirectlyCalledOverridable(XMethod caller, Set<XMethod> visited) {
Expand Down Expand Up @@ -334,7 +334,7 @@ private CallerInfo getIndirectCallerClone(XMethod callee) {
}

private CallerInfo getIndirectCallerSpecial(XMethod callee, Map<XMethod, CallerInfo> map) {
return getIndirectCallerSpecial(callee, map, new HashSet<XMethod>());
return getIndirectCallerSpecial(callee, map, new HashSet<>());
}

private CallerInfo getIndirectCallerSpecial(XMethod callee, Map<XMethod, CallerInfo> map, Set<XMethod> visited) {
Expand Down

0 comments on commit 4c7dd15

Please sign in to comment.