当我尝试构建我的Kotlin项目时,我在Idea中获得了以下error:
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。
发生这种情况的源文件可以找到here。
我向JetBrains提交了错误报告,但我需要进一步研究该项目,因此需要解决。请注意,直到昨天一切正常。昨天我将Kotlin插件升级到了最新版本,也许这就是问题所在。
如何避免上述错误?
更新1(03.03.2017 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 :(得分:2)
在上面的示例中,client.execute(req)
返回HttpResponse
,这不是CloseableHttpResponse
的子类型。因此,类型不匹配错误是正确的。您应该在此使用CloseableHttpClient
,或将client.execute(req)
投射到CloseableHttpResponse
。
我无法从您的示例中重现KotlinFrontEndException
。从提供的堆栈跟踪中我可以推断出“SAM适配器”发生了错误 - 也就是说,当您在接受单个抽象方法(SAM)接口的Java方法调用中使用Kotlin lambda时。
如果问题仍然存在,请在此处提交错误:http://kotl.in/issue