UnsupportedOperationException异常同时建立了科特林项目理念

问题描述:

当我尝试建立我的科特林项目中,我得到了以下的理念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

这就是为什么它是评论 –

在上面的例子中,返回client.execute(req)HttpResponse,这不是一个子类型的CloseableHttpResponse。所以,类型不匹配错误是正确的。您可以在此处使用CloseableHttpClient,或将client.execute(req)转换为CloseableHttpResponse

我无法从您的示例中重现KotlinFrontEndException。从提供的堆栈跟踪中,我可以推断出“SAM适配器”发生了什么问题 - 也就是说,当您在接受单一抽象方法(SAM)接口的Java方法调用中使用Kotlin lambda时。 请问,如果问题仍然存在,请提交错误:http://kotl.in/issue