18
18
19
19
package edu .umd .cs .findbugs .detect ;
20
20
21
- import java .util .Arrays ;
22
21
import java .util .HashMap ;
23
22
import java .util .HashSet ;
24
23
import java .util .Iterator ;
63
62
import edu .umd .cs .findbugs .ba .ca .CallListDataflow ;
64
63
import edu .umd .cs .findbugs .bcel .BCELUtil ;
65
64
import edu .umd .cs .findbugs .classfile .CheckedAnalysisException ;
66
- import edu .umd .cs .findbugs .classfile .Global ;
67
65
import edu .umd .cs .findbugs .classfile .MethodDescriptor ;
68
- import edu .umd .cs .findbugs .classfile .engine .bcel .FinallyDuplicatesInfoFactory ;
66
+ import edu .umd .cs .findbugs .util .CollectionAnalysis ;
67
+ import edu .umd .cs .findbugs .util .MethodAnalysis ;
69
68
70
69
public class AtomicOperationsCombinedDetector implements Detector {
71
70
@@ -157,11 +156,7 @@ private static boolean isInterestingField(ClassMember classMember) {
157
156
if (classMember == null ) {
158
157
return false ;
159
158
}
160
- Set <String > interestingCollectionMethodNames = new HashSet <>(Arrays .asList (
161
- "synchronizedCollection" , "synchronizedSet" , "synchronizedSortedSet" ,
162
- "synchronizedNavigableSet" , "synchronizedList" , "synchronizedMap" ,
163
- "synchronizedSortedMap" , "synchronizedNavigableMap" ));
164
- return ("java.util.Collections" .equals (classMember .getClassName ()) && interestingCollectionMethodNames .contains (classMember .getName ()))
159
+ return CollectionAnalysis .isSynchronizedCollection (classMember )
165
160
|| (classMember .getClassName ().startsWith ("java.util.concurrent.atomic" ) && classMember .getSignature ().endsWith (")V" ));
166
161
}
167
162
@@ -175,8 +170,6 @@ private void analyzeInterestingFields(ClassContext classContext, Method method)
175
170
CallListDataflow callListDataflow = classContext .getCallListDataflow (method );
176
171
JavaClass javaClass = classContext .getJavaClass ();
177
172
MethodDescriptor methodDescriptor = BCELUtil .getMethodDescriptor (javaClass , method );
178
- FinallyDuplicatesInfoFactory .FinallyDuplicatesInfo methodAnalysis =
179
- Global .getAnalysisCache ().getMethodAnalysis (FinallyDuplicatesInfoFactory .FinallyDuplicatesInfo .class , methodDescriptor );
180
173
boolean synchronizedBlock = false ;
181
174
182
175
for (Location location : cfg .orderedLocations ()) {
@@ -189,7 +182,7 @@ private void analyzeInterestingFields(ClassContext classContext, Method method)
189
182
synchronizedBlock = true ;
190
183
} else if (instruction instanceof MONITOREXIT ) {
191
184
synchronizedBlock = false ;
192
- } else if (instruction instanceof PUTFIELD && !synchronizedBlock && !isDuplicatedLocation (methodAnalysis , pc )) {
185
+ } else if (instruction instanceof PUTFIELD && !synchronizedBlock && !MethodAnalysis . isDuplicatedLocation (methodDescriptor , pc )) {
193
186
XField xField = XFactory .createXField ((FieldInstruction ) instruction , cpg );
194
187
if (interestingFields .contains (xField )) {
195
188
bugPrototype .invokedField = xField ;
@@ -198,7 +191,7 @@ private void analyzeInterestingFields(ClassContext classContext, Method method)
198
191
.add (bugPrototype );
199
192
}
200
193
} else if (instruction instanceof InvokeInstruction && !(instruction instanceof INVOKEDYNAMIC )
201
- && !synchronizedBlock && !isDuplicatedLocation (methodAnalysis , pc )) {
194
+ && !synchronizedBlock && !MethodAnalysis . isDuplicatedLocation (methodDescriptor , pc )) {
202
195
OpcodeStack stack = OpcodeStackScanner .getStackAt (javaClass , method , pc );
203
196
Optional <XField > interestingField = getInterestingField (stack );
204
197
XMethod xMethod = XFactory .createXMethod ((InvokeInstruction ) instruction , cpg );
@@ -230,10 +223,6 @@ private void analyzeInterestingFields(ClassContext classContext, Method method)
230
223
}
231
224
}
232
225
233
- private boolean isDuplicatedLocation (FinallyDuplicatesInfoFactory .FinallyDuplicatesInfo methodAnalysis , int pc ) {
234
- return methodAnalysis .getDuplicates (pc ).stream ().anyMatch (duplicatePc -> duplicatePc < pc );
235
- }
236
-
237
226
private Optional <XField > getInterestingField (OpcodeStack stack ) {
238
227
if (stack .getStackDepth () > 1 && stack .getStackItem (0 ).getReturnValueOf () != null ) {
239
228
return Optional .empty ();
0 commit comments