JetBrains / java-annotations

Annotations for JVM-based languages.
Apache License 2.0
404 stars 47 forks source link

Annotations are shown multiple time in javadocs #35

Closed original-codematrix closed 4 years ago

original-codematrix commented 4 years ago

I'm using this dependency:

<dependency>
    <groupId>org.jetbrains</groupId>
    <artifactId>annotations</artifactId>
    <version>20.1.0</version>
</dependency>

With this maven plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>3.2.0</version>
    <executions>
        <execution>
            <id>attach-javadocs</id>
            <phase>deploy</phase>
            <configuration>
                <quiet>true</quiet>
                <notimestamp>true</notimestamp>
                <encoding>${utf.encoding}</encoding> <!-- utf.encoding = UTF-8 -->
                <docencoding>${utf.encoding}</docencoding>
                <charset>${utf.encoding}</charset>
                <additionalOptions>
                    <additionalOption>-XDignore.symbol.file</additionalOption>
                    <additionalOption>-Xdoclint:-html</additionalOption>
                </additionalOptions>
                <linksource>true</linksource>
                <source>${java.version}</source> <!-- java.version = 11 -->
            </configuration>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

When I now create a Javadoc of a class that contains e. g. NotNull or Nullable it results looks like this in the JavaDocs:

All methods overview: image image

Method detail: image image

I've also switched to another annotation library (jsr305) from that these annotations are only shown once.

amaembo commented 4 years ago

This is not the annotation package bug. This is how javadoc tool works when the annotation has multiple targets including TYPE_USE. E.g. for a class like this:

import java.lang.annotation.*;

@Documented
@Target({ElementType.TYPE_USE, ElementType.METHOD})
public @interface Test {
  @Test String value() default "";
}

Generating javadoc (simply by invoking javadoc Test.java) you will see duplicated annotation:

@Test
@Test java.lang.String value

You may consider reporting an issue to OpenJDK

JSR-305 works because it doesn't provide TYPE_USE target. You may use our annotations-java5 package as an alternativem it should work as well.