https://kotlinlang.org logo
#detekt
Title
# detekt
v

vineethraj49

04/05/2021, 3:56 AM
context: i am trying to replicate the behavior of https://github.com/JetBrains/intellij-community/blob/master/jvm/jvm-analysis-impl/[…]ion/blockingCallsDetection/ThrowsTypeBlockingMethodChecker.java problem: KtCallExpression.getResolvedCall(bindingContext) gives JavaMethodDescriptor; the referenced PsiMethod for the JavaMethodDescriptor would be in rt.jar; 1. how to resolve to the PsiMethod from JavaMethodDescriptor? 2. or get the PsiMethod/PsiReferenceList some other way at analysis time? one way I can think of doing 2, is specifically just loading
((descriptor.source as JavaSourceElement).javaElement as BinaryJavaMethod).containingClass
at runtime
g

gammax

04/07/2021, 9:38 AM
I’m unsure how to help you 🤔 What is
ThrowsTypeBlockingMethodChecker
even doing? Can you provide some example of compliant/non-compliant code?
v

vineethraj49

04/08/2021, 2:58 AM
@gammax, this is used to check if a method is a blocking method
this is used further with another inspection, which sees if this method call is being made in a non-blocking context
g

gammax

04/08/2021, 12:53 PM
Can you provide some example of compliant/non-compliant code? 🙂
v

vineethraj49

04/08/2021, 10:46 PM
Copy code
V java.util.concurrent.Future#get() throws InterruptedException, ExecutionException; // defined in rt.jar

suspend fun foo() {
    val aFuture = asyncHttpClient.executeRequest(r).get() // this `.get` is identified as a blocking call in non-blocking context
}
9 Views