Skip to content

Commit 90f388a

Browse files
committed
Count thread starts
1 parent e9e5c2f commit 90f388a

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

spotbugs/src/main/java/edu/umd/cs/findbugs/detect/ResourceInMultipleThreadsDetector.java

+16-11
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,30 @@ public void sawOpcode(int seen) {
9494

9595
if (firstPass) {
9696
collectMethodsUsedInThreads(seen);
97-
} else {
97+
} /*else {
9898
try {
9999
collectFieldsUsedInThreads(seen);
100100
} catch (CheckedAnalysisException e) {
101101
bugReporter.logError(String.format("Detector %s caught exception while analyzing class %s", getClass().getName(), getClassName()), e);
102102
}
103-
}
103+
}*/
104104
}
105105

106106
private void collectMethodsUsedInThreads(int seen) {
107107
if (seen == Const.INVOKEDYNAMIC && getStack().getStackDepth() > 1
108108
&& "Ljava/lang/Thread;".equals(getStack().getStackItem(1).getSignature())
109109
&& !isJavaRuntimeMethod()) {
110-
getMethodFromBootstrap(getThisClass(), (ConstantInvokeDynamic) getConstantRefOperand()).ifPresent(methodsUsedInThreads::add);
111-
} else if ((seen == Const.INVOKEVIRTUAL || seen == Const.INVOKEINTERFACE || seen == Const.INVOKESPECIAL || seen == Const.INVOKESTATIC)
110+
getMethodFromBootstrap(getThisClass(), (ConstantInvokeDynamic) getConstantRefOperand()).ifPresent(methodDescriptor -> {
111+
BugInstance bug = new BugInstance(this, "AT_UNSAFE_RESOURCE_ACCESS_IN_THREAD", LOW_PRIORITY)
112+
.addClass(this)
113+
.addMethod(methodDescriptor);
114+
bugReporter.reportBug(bug);
115+
});
116+
} /*else if ((seen == Const.INVOKEVIRTUAL || seen == Const.INVOKEINTERFACE || seen == Const.INVOKESPECIAL || seen == Const.INVOKESTATIC)
112117
&& getXMethodOperand() != null && methodsUsedInThreads.contains(getMethodDescriptor())
113118
&& getClassDescriptor().equals(getXMethodOperand().getClassDescriptor())) {
114119
methodsUsedInThreads.add(getMethodDescriptorOperand());
115-
}
120+
}*/
116121
}
117122

118123
/**
@@ -187,12 +192,12 @@ private void createOrUpdateFieldData(XField xField, boolean putfield, Method met
187192

188193
@Override
189194
public void visitAfter(JavaClass javaClass) {
190-
super.visit(javaClass);
191-
fieldsUsedInThreads.entrySet().stream()
192-
.filter(entry -> isBug(entry.getValue()))
193-
.flatMap(entry -> entry.getValue().methodBugs.values().stream().flatMap(Set::stream))
194-
.collect(Collectors.toSet())
195-
.forEach(bugReporter::reportBug);
195+
//super.visit(javaClass);
196+
//fieldsUsedInThreads.entrySet().stream()
197+
// .filter(entry -> isBug(entry.getValue()))
198+
// .flatMap(entry -> entry.getValue().methodBugs.values().stream().flatMap(Set::stream))
199+
// .collect(Collectors.toSet())
200+
// .forEach(bugReporter::reportBug);
196201
}
197202

198203
/**

0 commit comments

Comments
 (0)