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

Wrong type annotation offset on casts on expressions

XMLWordPrintable

    • x86_64
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      javac 11.0.1

      A DESCRIPTION OF THE PROBLEM :
      The offset for annotation on cast is wrongly on the instruction which follows checkcast if the cast is on an expression

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      javap the compiled source code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
         stack=1, locals=3, args_size=3
               0: iload_0
               1: ifeq 8
               4: aload_1
               5: goto 9
               8: aload_2
               9: checkcast #2 // class java/lang/String
              12: areturn
      .....
            RuntimeVisibleTypeAnnotations:
              0: #21(): CAST, offset=9, type_index=0
                TypeUse
      }
      ACTUAL -
         stack=1, locals=3, args_size=3
               0: iload_0
               1: ifeq 8
               4: aload_1
               5: goto 9
               8: aload_2
               9: checkcast #2 // class java/lang/String
              12: areturn
      ....
            RuntimeVisibleTypeAnnotations:
              0: #21(): CAST, offset=12, type_index=0
                TypeUse
      }

      ---------- BEGIN SOURCE ----------
      @Target(ElementType.TYPE_USE)
      @Retention(RetentionPolicy.RUNTIME)
      public @interface TypeUse {}

      public class AnnotateCast {
          private static String checkcast(boolean test,Object obj,Object obj2) {
                  return (@TypeUse String)(test?obj:obj2);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Object obj1 = test?obj:obj2;
       return (@TypeUse String)obj1;
      /* placing brackets round obj1 reproduces the problem */

      FREQUENCY : occasionally


            vromero Vicente Arturo Romero Zaldivar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: