2017-03-03 46 views
1

當我嘗試建立我的科特林項目中,我得到了以下的理念errorUnsupportedOperationException異常同時建立了科特林項目理念

Error:Kotlin: [Internal Error] org.jetbrains.kotlin.util.KotlinFrontEndException: Exception while analyzing expression at (60,19) in E:/altruix-is/src/main/kotlin/com/mycompany/myproduct/capsulecrm/CapsuleCrmSubsystem.kt: 
client.execute(req) 

[...] 

Caused by: java.lang.UnsupportedOperationException: doSubstitute with no original should not be called for synthetic extension 
    at org.jetbrains.kotlin.synthetic.SamAdapterFunctionsScope$MyFunctionDescriptor.doSubstitute(SamAdapterFunctionsScope.kt:165) 
    at org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl$CopyConfiguration.build(FunctionDescriptorImpl.java:553) 
    at org.jetbrains.kotlin.load.java.ErasedOverridabilityCondition.isOverridable(ErasedOverridabilityCondition.kt:47) 

的錯誤似乎在通話

res = client.execute(req) 

其中client發生是Apache HttpClient。

Screenshot

源文件中,其中發生這種情況,可以發現here

我向JetBrains提交了錯誤報告,但我需要進一步研究該項目,因此需要解決。請注意,直到昨天一切正常。昨天我將Kotlin插件升級到最新版本,可能就是這個問題。

如何避免上述錯誤?

更新1(2017年3月3日14:46 MSK):

這不起作用:

open fun addNote(note: String, compId: Long): ValidationResult { 
    val client = httpClient 
    if (client == null) { 
     return ValidationResult(false, "Internal error") 
    } 

    var res: CloseableHttpResponse? = null 
    var req: HttpUriRequest? 
    try { 
     req = composeAddNoteRequest(note, compId) 
     res = client.execute(req) 
     if (res.statusLine.statusCode != 201) { 
      logger.error("addNote(note='$note', compId=$compId): Wrong status code ${res.statusLine.statusCode}") 
      return ValidationResult(false, "Wrong status code (CRM interaction)") 
     } 
     return ValidationResult(true, "") 
    } 
    catch (throwable: Throwable) { 
     logger.error("addNote(note='$note', compId=$compId)", throwable) 
     return ValidationResult(false, "Database error") 
    } finally { 
     close(res) 
    } 
    return ValidationResult(false, "Internal logic error") 
} 

此作品(區別是從頂部第二線):

open fun addNote(note: String, compId: Long): ValidationResult { 
    val client = httpClient as CloseableHttpClient // Change 
    if (client == null) { 
     return ValidationResult(false, "Internal error") 
    } 

    var res: CloseableHttpResponse? = null 
    var req: HttpUriRequest? 
    try { 
     req = composeAddNoteRequest(note, compId) 
     res = client.execute(req) 
     if (res.statusLine.statusCode != 201) { 
      logger.error("addNote(note='$note', compId=$compId): Wrong status code ${res.statusLine.statusCode}") 
      return ValidationResult(false, "Wrong status code (CRM interaction)") 
     } 
     return ValidationResult(true, "") 
    } 
    catch (throwable: Throwable) { 
     logger.error("addNote(note='$note', compId=$compId)", throwable) 
     return ValidationResult(false, "Database error") 
    } finally { 
     close(res) 
    } 
    return ValidationResult(false, "Internal logic error") 
} 
+0

這就是爲什麼它是評論 –

回答

1

在上面的例子中,返回client.execute(req)HttpResponse,這不是一個子類型的CloseableHttpResponse。所以,類型不匹配錯誤是正確的。您可以在此處使用CloseableHttpClient,或將client.execute(req)轉換爲CloseableHttpResponse

我無法從您的示例中重現KotlinFrontEndException。從提供的堆棧跟蹤中,我可以推斷出「SAM適配器」發生了什麼問題 - 也就是說,當您在接受單一抽象方法(SAM)接口的Java方法調用中使用Kotlin lambda時。 請問,如果問題仍然存在,請提交錯誤:http://kotl.in/issue