Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating documentation fails with exception "class com.intellij.psi.impl.source.PsiImmediateClassType cannot be cast to class com.intellij.psi.impl.source.PsiClassReferenceType" #2551

Closed
jankoh opened this issue Jun 22, 2022 · 1 comment · Fixed by #2562
Assignees
Labels

Comments

@jankoh
Copy link

jankoh commented Jun 22, 2022

Describe the bug
This is the other error mentioned #2545 that is thrown in 1.6.X, and 1.7.0; 1.5.30 works. I compiled a minimal example triggering the error. It turns out, Dokka tries tor read and process java files, even when the package is excluded for documentation generation and the file does not even contain documentation:

jkohnert@kohnert-n4:~/Develop/testdokka$ ./gradlew --stacktrace dokkaHtml

> Task :dokkaHtml
Initializing plugins
Dokka is performing: documentation for testdokka
Validity check
Creating documentation models


> Task :dokkaHtml FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':dokkaHtml'.
> class com.intellij.psi.impl.source.PsiImmediateClassType cannot be cast to class com.intellij.psi.impl.source.PsiClassReferenceType (com.intellij.psi.impl.source.PsiImmediateClassType and com.intellij.psi.impl.source.PsiClassReferenceType are in unnamed module of loader java.net.URLClassLoader @e09e1f8)

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':dokkaHtml'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:147)
        at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:145)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:133)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
        at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:74)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:333)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:320)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:313)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:299)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:143)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:227)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:218)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:140)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
Caused by: java.lang.ClassCastException: class com.intellij.psi.impl.source.PsiImmediateClassType cannot be cast to class com.intellij.psi.impl.source.PsiClassReferenceType (com.intellij.psi.impl.source.PsiImmediateClassType and com.intellij.psi.impl.source.PsiClassReferenceType are in unnamed module of loader java.net.URLClassLoader @e09e1f8)
        at org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator$DokkaPsiParser.toValue(DefaultPsiToDocumentableTranslator.kt:690)
        at org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator$DokkaPsiParser.toValue(DefaultPsiToDocumentableTranslator.kt:669)
        at org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator$DokkaPsiParser.toAnnotation(DefaultPsiToDocumentableTranslator.kt:726)
        at org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator$DokkaPsiParser.toValue(DefaultPsiToDocumentableTranslator.kt:686)
        at org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator$DokkaPsiParser.toValue(DefaultPsiToDocumentableTranslator.kt:687)
        at org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator$DokkaPsiParser.toValue(DefaultPsiToDocumentableTranslator.kt:669)
        at org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator$DokkaPsiParser.toAnnotation(DefaultPsiToDocumentableTranslator.kt:726)
        at org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator$DokkaPsiParser.toListOfAnnotations(DefaultPsiToDocumentableTranslator.kt:666)
        at org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator$DokkaPsiParser.parseField(DefaultPsiToDocumentableTranslator.kt:646)
        at org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator$DokkaPsiParser.parseField(DefaultPsiToDocumentableTranslator.kt:613)
        at org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator$DokkaPsiParser.parseField$default(DefaultPsiToDocumentableTranslator.kt:610)
        at org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator$DokkaPsiParser$parseClasslike$2$invokeSuspend$$inlined$with$lambda$5$1$1.invokeSuspend(parallelCollectionOperations.kt:19)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)


* Get more help at https://help.gradle.org

BUILD FAILED in 7s
1 actionable task: 1 executed
jkohnert@kohnert-n4:~/Develop/testdokka$ 

Expected behaviour
Documentation should be generated

To Reproduce
I compiled a minimal example in https://github.com/jankoh/testdokka

Removing the annotation in TestModelClass.java fixes the error. unfortunately in the real project this is generated code, nd the problem is spread over many files, so moving those things to kotlin is not an option at the moment. Still I wonder why dokka is trying to read those java files at all; and I'm not quite sure how things were handled in 1.5.X

Dokka configuration
Configuration of dokka used to reproduce the bug

tasks {
	dokkaHtml.configure {
		outputDirectory.set(buildDir.resolve("doc"))

		dokkaSourceSets {
			configureEach {
				// Set jdk version to the version used outside
				jdkVersion.set(javaVersion)

				// Use to include or exclude non public members.
				includeNonPublic.set(false)

				// Do not output deprecated members. Applies globally, can be overridden by packageOptions
				skipDeprecated.set(true)

				// Emit warnings about not documented members. Applies globally, also can be overridden by packageOptions
				reportUndocumented.set(true)

				// Do not create index pages for empty packages
				skipEmptyPackages.set(true)

				// Create or omit external links, java main docs are defined below
				noStdlibLink.set(false)
				noJdkLink.set(false)

				externalDocumentationLink {
					url.set(URL("https://docs.oracle.com/en/java/javase/17/docs/api/"))
					packageListUrl.set(URL("https://docs.oracle.com/en/java/javase/17/docs/api/allpackages-index.html"))
				}

				// Suppress a package
				perPackageOption {
					matchingRegex.set(".*\\.model.*") // will match all .internal packages and sub-packages
					suppress.set(true)
				}
			}
		}
	}
}

Installation

  • Operating system: Linux
  • Build tool: Gradle v7.4.2
  • Dokka version: 1.7.0/1.6.X
@IgnatBeresnev
Copy link
Member

Hi! Thanks for the report and huge thanks for the reproducer, it was of great help! I've added a unit test to cover your exact case

IgnatBeresnev added a commit that referenced this issue Jul 7, 2022
IgnatBeresnev added a commit that referenced this issue Jul 11, 2022
Fixes #2509
Fixes #2551
Fixes #2350

(cherry picked from commit 3332f9f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants