JDK-8028576 : Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-11-19
  • Updated: 2014-08-04
  • Resolved: 2014-01-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u20Fixed 9 b02Fixed
Description
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"