Plugin Error: Kotlin threw an uncaught ClassCastException

Android Studio 3.0 Canary 3
I receive this error:
Plugin Error: Kotlin threw an uncaught ClassCastException

buildscript {
ext.kotlin_version = ‘1.1.2-5’
repositories {
maven { url ‘https://maven.google.com’ }
jcenter()
}
dependencies {
classpath ‘com.android.tools.build:gradle:3.0.0-alpha3’
classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version”
}
}

org.jetbrains.uast.UastContext cannot be cast to org.jetbrains.uast.UastContext
java.lang.ClassCastException: org.jetbrains.uast.UastContext cannot be cast to org.jetbrains.uast.UastContext
at org.jetbrains.uast.UastContextKt.toUElement(UastContext.kt:77)
at org.jetbrains.kotlin.android.folding.ResourceFoldingBuilder.buildFoldRegions(ResourceFoldingBuilder.kt:78)
at com.intellij.lang.folding.LanguageFolding.buildFoldingDescriptors(LanguageFolding.java:83)
at com.intellij.lang.folding.CompositeFoldingBuilder.buildFoldRegions(CompositeFoldingBuilder.java:63)
at com.intellij.lang.folding.LanguageFolding.buildFoldingDescriptors(LanguageFolding.java:83)
at com.intellij.codeInsight.folding.impl.FoldingUpdate.getFoldingsFor(FoldingUpdate.java:236)
at com.intellij.codeInsight.folding.impl.FoldingUpdate.getFoldingsFor(FoldingUpdate.java:222)
at com.intellij.codeInsight.folding.impl.FoldingUpdate.getUpdateResult(FoldingUpdate.java:112)
at com.intellij.codeInsight.folding.impl.FoldingUpdate.lambda$updateFoldRegions$1(FoldingUpdate.java:101)
at com.intellij.psi.impl.PsiParameterizedCachedValue.doCompute(PsiParameterizedCachedValue.java:53)
at com.intellij.util.CachedValueBase.getValueWithLock(CachedValueBase.java:222)
at com.intellij.psi.impl.PsiCachedValue.getValueWithLock(PsiCachedValue.java:60)
at com.intellij.psi.impl.PsiParameterizedCachedValue.getValue(PsiParameterizedCachedValue.java:43)
at com.intellij.psi.util.CachedValuesManager.getParameterizedCachedValue(CachedValuesManager.java:97)
at com.intellij.codeInsight.folding.impl.FoldingUpdate.updateFoldRegions(FoldingUpdate.java:97)
at com.intellij.codeInsight.folding.impl.CodeFoldingManagerImpl.updateFoldRegions(CodeFoldingManagerImpl.java:326)
at com.intellij.codeInsight.folding.impl.CodeFoldingManagerImpl.updateFoldRegionsAsync(CodeFoldingManagerImpl.java:312)
at com.intellij.codeInsight.daemon.impl.CodeFoldingPass.doCollectInformation(CodeFoldingPass.java:42)
at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:70)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$null$1(PassExecutorService.java:438)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1156)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:431)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:556)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:501)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:66)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:430)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:406)
at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:142)
at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:242)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:404)
at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:165)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Please make sure that you have the correct version of the Kotlin plugin installed in Android Studio. For 3.0 Canary, the correct version is 1.1.2-5.

I’m seeing this same issue after updating Android Studio 3.0 Canary 5 to Kotlin Plugin 1.1.3-release-Studio3.0-2 and updating my Gradle build to use 1.1.3-2

The frustrating problem with this issue is that I can no longer see errors in my code

1 Like

I have the same issue
Android Studio 3.0 Canary 6 to Kotlin Plugin 1.1.3-release-Studio3.0-2 and updating my Gradle build to use 1.1.3-2

1 Like

Same here.

Can you double-check if your locally-installed Kotlin plugin has its own copy of uast?

I can easily reproduce this in Android Studio by installing Kotlin 1.2-M1, then manually copying uast-common-1.0.jar into ~/.AndroidStudioPreview3.0/config/plugins/Kotlin/lib. I don’t know how the plugin update works for deleting files that are no longer part of the install, but perhaps there’s another uast jar there, from an older plugin version?