Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8278592

Documented annotations with target TYPE_USE and PARAMETER are duplicated

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      OS: Windows 10 20H2 (build 19042.1348)

      Java runtime:
      openjdk version "18-beta" 2022-03-22
      OpenJDK Runtime Environment Temurin-18+26-202112030041 (build 18-beta+26-202112030041)
      OpenJDK 64-Bit Server VM Temurin-18+26-202112030041 (build 18-beta+26-202112030041, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      Documented annotations that combine target TYPE_USE and other valid targets such as PARAMETER, are duplicated in the class data, and so on documentation too

      The duplication also happens if any other target type which is valid to the context is present, this causes annotations such as JetBrains's @NotNull and @Nullable to be duplicated in the class data, as well as on the javadocs, on return types or on parameters for example

      The bug is reproducible on :
      JDK 8u265
      JDK 11.0.6+10
      JDK 16.0.2+7
      JDK 18-EA+26

      Related issues:
      https://bugs.openjdk.java.net/browse/JDK-8175533

      Seems to be related:
      https://bugs.openjdk.java.net/browse/JDK-8006775

      Other issues caused by the bug:
      https://github.com/JetBrains/java-annotations/issues/37 : "I.e. overlapping scopes lead to tools such as Javadoc recognizing both targets as matched thus leading to issues such as duplication of the annotation in documentation"

      REGRESSION : Last worked in version 8

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Make any class with an annotated element that is allowed by two targets (TYPE_USE and PARAMETER here)

      API.java:

      @Documented
      @Retention(RetentionPolicy.RUNTIME)
      @Target({ElementType.PARAMETER, ElementType.TYPE_USE})
      @interface TypeUseAnnot {}

      public class API {
      public static void doSomething(@TypeUseAnnot Object obj) { }
      }


      Generating the docs:
      javadoc -d docs API.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The @TypeUseAnnot annotation should only appear once in the class data and also in the method detail section javadoc
      ACTUAL -
      The @TypeUseAnnot annotation is duplicated on the "obj" parameter

      ---------- BEGIN SOURCE ----------
      @Documented
      @Retention(RetentionPolicy.RUNTIME)
      @Target({ElementType.PARAMETER, ElementType.TYPE_USE})
      @interface TypeUseAnnot {}

      public class API {
      public static void doSomething(@TypeUseAnnot Object obj) { }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        1. API.java
          0.4 kB
        2. image.png
          image.png
          21 kB

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: