Reputation: 18760
When I try to build my Kotlin project I get the following error in 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)
The error seems to occur in calls
res = client.execute(req)
where client
is Apache HttpClient.
The source file, where this occurs can be found here.
I submitted the bug report to JetBrains, but I need to work further on the project and therefore a work around. Note that until yesterday everything worked fine. Yesterday I upgraded the Kotlin plugin to the most recent version, maybe that's the problem.
How can I avoid the error above?
Update 1 (03.03.2017 14:46 MSK):
This doesn't work:
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")
}
This works (difference is in the second line from the top):
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")
}
Upvotes: 1
Views: 1550
Reputation: 46
In your example above, client.execute(req)
returns HttpResponse
, which is not a sub-type of CloseableHttpResponse
. So, type mismatch error is correct. Either you should use CloseableHttpClient
here, or cast client.execute(req)
to CloseableHttpResponse
.
I couldn't reproduce KotlinFrontEndException
from your example. From the stack trace provided I can deduce that something wrong happened with "SAM adapters" - that is, when you use a Kotlin lambda in a Java method call that accepts single abstract method (SAM) interface.
Please, file a bug here if the problem still occurs: http://kotl.in/issue
Upvotes: 2