在Idea中构建Kotlin项目时,UnsupportedOperationException
当我尝试构建我的Kotlin项目时,我在Idea中得到以下错误 :
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。
源文件可以在这里找到。
我向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") }
在你上面的例子中, client.execute(req)
返回HttpResponse
,它不是CloseableHttpResponse
的子类型。 所以,类型不匹配错误是正确的。 要么在这里使用CloseableHttpClient
,要么将client.execute(req)
CloseableHttpResponse
为CloseableHttpResponse
。
我无法从您的示例中重现KotlinFrontEndException
。 从提供的堆栈跟踪中,我可以推断出“SAM适配器”发生了什么问题 – 也就是说,当您在接受单一抽象方法(SAM)接口的Java方法调用中使用Kotlin lambda时。 如果问题仍然存在,请在这里提交错误: http : //kotl.in/issue
- IDEA IllegalStateException:使用Kotlin运行JUnit测试时,服务正在死亡
- Dagger2错误:Kotlin:未解决的参考:DaggerSOMETHINGComponent
- 如何恢复Intellij中的模块依赖项排除(代码检查后误报)
- TransformException重复org / intellij / lang / annotations / Identifier.class的条目
- Kotlin REPL与Android类unStub!编辑
- 用pom自动复制文件
- IntelliJ中的两个JVM Kotlin“创建项目”选项有什么不同?
- NoSuchMethodError:java.lang.Long.hashCode
- 如何在IntelliJ插件中执行Kotlin代码?