Skip to content

[Bug] Package-level annotation dropped due to inconsistent Annotations merge #4558

Description

@juliamcclellan

What is happening? What should have happened instead?

If a package with both java and kotlin source files has package-level annotations in the package-info.java files, I expect the annotations to be present on the DPackage after the java and kotlin DModules have been merged. This was the previous dokka behavior, but between versions and 2.3.0-dev-423 and 2.3.0-dev-424 the behavior changed and the annotations are no longer present on the merged DPackage.

From debugging, this is because the behavior of Annotations.mergeStrategyFor is inconsistent depending on which Annotations is left and which is right:

override fun mergeStrategyFor(left: Annotations, right: Annotations): MergeStrategy<AnnotationTarget> =
            MergeStrategy.Replace(Annotations(left.myContent + right.myContent))

Because myContent is SourceSetDependent<List<Annotation>>, typealias for Map<DokkaSourceSet, List<Annotation>>. When adding two Maps together, if the same key is present in both Maps, the corresponding entries aren't merged in any way, the second entry is just used. So when merging, if the java package Annotations are left while they empty Annotations from the kotlin DPackage are right, the resultant DPackage has empty Annotations.

Reproducer

/src/com/sample/package-info.java

@Deprecated
package com.sample;

/src/com/sample/Foo.kt

package com.sample
class Foo

/src/com/sample/Bar.java

package com.sample;
public class Bar {}

Dokka version

2.3.0-dev-424

Kotlin Gradle Plugin (KGP) version

No response

Android Gradle Plugin (AGP) version (if applicable)

No response

Build tool

Gradle

Project type

  • Kotlin Multiplatform (KMP)
  • Android
  • JVM
  • Other

Anything else? (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions