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

Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8
    • tools
    • b02
    • Verified

        Consider code like this:
        -----
        import java.lang.annotation.ElementType;
        import java.lang.annotation.Retention;
        import java.lang.annotation.RetentionPolicy;
        import java.lang.annotation.Target;

        public class TestTA {
            public void test() {
                try {
                    System.err.println("adf");
                } catch (@TA1 Exception e) {
                } catch (@TA2 Throwable t) {
                }
            }
        }

        @Target(ElementType.TYPE_USE)
        @Retention(RetentionPolicy.RUNTIME)
        @interface TA1 { }

        @Target(ElementType.TYPE_USE)
        @Retention(RetentionPolicy.RUNTIME)
        @interface TA2 { }
        -----

        When compiled like this:
        $ javac -g:vars TestTA.java
        The result is:
        -----
          public void test();
            descriptor: ()V
            flags: ACC_PUBLIC
            Code:
              stack=2, locals=2, args_size=1
                 0: getstatic #2 // Field java/lang/System.err:Ljava/io/PrintStream;
                 3: ldc #3 // String adf
                 5: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
                 8: goto 16
                11: astore_1
                12: goto 16
                15: astore_1
                16: return
              Exception table:
                 from to target type
                     0 8 11 Class java/lang/Exception
                     0 8 15 Class java/lang/Throwable
              LocalVariableTable:
                Start Length Slot Name Signature
                   12 0 1 e Ljava/lang/Exception;
                   16 0 1 t Ljava/lang/Throwable;
                    0 17 0 this LTestTA;
              StackMapTable: number_of_entries = 3
                   frame_type = 75 /* same_locals_1_stack_item */
                  stack = [ class java/lang/Exception ]
                   frame_type = 67 /* same_locals_1_stack_item */
                  stack = [ class java/lang/Throwable ]
                   frame_type = 0 /* same */

              RuntimeVisibleTypeAnnotations:
                0: #22(): EXCEPTION_PARAMETER, exception_index=0
                1: #23(): EXCEPTION_PARAMETER, exception_index=1
        -----

        Which appears to be correct, but when compiled like this:
        $ javac -g:none TestTA.java
        The result is (just the relevant attribute):
        -----
              RuntimeVisibleTypeAnnotations:
                0: #15(): EXCEPTION_PARAMETER, exception_index=0
                1: #16(): EXCEPTION_PARAMETER, exception_index=0
        -----

        Note the "exception_index", which is incorrect for the second attribute.

        The problem appears to be in Code.putVar:~2195, the:
        var.sym.hasTypeAnnotations()
        should read:
        !var.sym.hasTypeAnnotations()

        This was using:
        $ javac -fullversion
        javac full version "1.8.0-ea-b116"

              jlahoda Jan Lahoda
              jlahoda Jan Lahoda
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: