mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[java-dfa] IDEA-329980 "Constant values" false positive for Thread.currentThread
GitOrigin-RevId: ae59b89b689fbb2a756869fe5f4c916b1934ab06
This commit is contained in:
committed by
intellij-monorepo-bot
parent
16230b3454
commit
0f07763950
@@ -23,6 +23,7 @@ import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PropertyUtilBase;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.ig.callMatcher.CallMatcher;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
@@ -39,7 +40,10 @@ import static com.intellij.util.ObjectUtils.tryCast;
|
||||
* Utility class to help producing values for Java DFA
|
||||
*/
|
||||
public final class JavaDfaValueFactory {
|
||||
|
||||
// Methods that while considered as pure may return different results, as depend on the world state
|
||||
private static final CallMatcher UNSTABLE_METHODS = CallMatcher.staticCall(
|
||||
"java.lang.Thread", "currentThread").parameterCount(0);
|
||||
|
||||
private JavaDfaValueFactory() {
|
||||
}
|
||||
|
||||
@@ -205,7 +209,8 @@ public final class JavaDfaValueFactory {
|
||||
if (InheritanceUtil.isInheritor(method.getReturnType(), JAVA_UTIL_STREAM_BASE_STREAM)) return null;
|
||||
if (method.getParameterList().isEmpty() &&
|
||||
(PropertyUtilBase.isSimplePropertyGetter(method) || JavaMethodContractUtil.isPure(method) || isClassAnnotatedImmutable(method)) &&
|
||||
isContractAllowedForGetter(method)) {
|
||||
isContractAllowedForGetter(method) &&
|
||||
!UNSTABLE_METHODS.methodMatches(method)) {
|
||||
return new GetterDescriptor(method);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.util.stream.Stream;
|
||||
|
||||
class Test {
|
||||
public static void main(String[] args) {
|
||||
long thread = Thread.currentThread().getId();
|
||||
|
||||
Stream.of(1, 2, 3, 4)
|
||||
.parallel()
|
||||
.forEach(e -> {
|
||||
if (Thread.currentThread().getId() == thread) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -400,4 +400,5 @@ public class DataFlowInspection8Test extends DataFlowInspectionTestCase {
|
||||
public void testConsumedStreamDifferentMethods() { doTest(); }
|
||||
public void testConsumedStreamWithoutInline() { doTest(); }
|
||||
public void testLocalityAndConditionalExpression() { doTest(); }
|
||||
public void testParallelStreamThreadId() { doTest(); }
|
||||
}
|
||||
Reference in New Issue
Block a user