changeset 22443:0922d94d0576

8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info Summary: The exception parameters with type annotations need to be added into the varBuffer even if not generating debug info Reviewed-by: jjg, emc
author jlahoda
date Wed, 15 Jan 2014 13:49:57 +0100
parents 8fd30fc4e3a3
children c79ee1e6742f a81ce6432372
files langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ExceptionParameters.java
diffstat 3 files changed, 34 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java	Wed Jan 15 10:57:25 2014 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java	Wed Jan 15 13:49:57 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -2189,9 +2189,9 @@
         // Keep local variables if
         // 1) we need them for debug information
         // 2) it is an exception type and it contains type annotations
-        if (!varDebugInfo &&
-                (!var.sym.isExceptionParameter() ||
-                var.sym.hasTypeAnnotations())) return;
+        boolean keepLocalVariables = varDebugInfo ||
+            (var.sym.isExceptionParameter() && var.sym.hasTypeAnnotations());
+        if (!keepLocalVariables) return;
         if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return;
         if (varBuffer == null)
             varBuffer = new LocalVar[20];
--- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java	Wed Jan 15 10:57:25 2014 +0100
+++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java	Wed Jan 15 13:49:57 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,7 @@
 import java.lang.annotation.*;
 import java.lang.reflect.*;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -51,6 +52,11 @@
         new Driver().runDriver(clazz.newInstance());
     }
 
+    String[][] extraParamsCombinations = new String[][] {
+        new String[] { },
+        new String[] { "-g" },
+    };
+
     protected void runDriver(Object object) throws Exception {
         int passed = 0, failed = 0;
         Class<?> clazz = object.getClass();
@@ -65,18 +71,20 @@
                 throw new IllegalArgumentException("Test method needs to return a string: " + method);
             String testClass = testClassOf(method);
 
-            try {
-                String compact = (String)method.invoke(object);
-                String fullFile = wrap(compact);
-                ClassFile cf = compileAndReturn(fullFile, testClass);
-                List<TypeAnnotation> actual = ReferenceInfoUtil.extendedAnnotationsOf(cf);
-                ReferenceInfoUtil.compare(expected, actual, cf);
-                out.println("PASSED:  " + method.getName());
-                ++passed;
-            } catch (Throwable e) {
-                out.println("FAILED:  " + method.getName());
-                out.println("    " + e.toString());
-                ++failed;
+            for (String[] extraParams : extraParamsCombinations) {
+                try {
+                    String compact = (String)method.invoke(object);
+                    String fullFile = wrap(compact);
+                    ClassFile cf = compileAndReturn(fullFile, testClass, extraParams);
+                    List<TypeAnnotation> actual = ReferenceInfoUtil.extendedAnnotationsOf(cf);
+                    ReferenceInfoUtil.compare(expected, actual, cf);
+                    out.println("PASSED:  " + method.getName());
+                    ++passed;
+                } catch (Throwable e) {
+                    out.println("FAILED:  " + method.getName());
+                    out.println("    " + e.toString());
+                    ++failed;
+                }
             }
         }
 
@@ -156,7 +164,7 @@
         }
     }
 
-    private ClassFile compileAndReturn(String fullFile, String testClass) throws Exception {
+    private ClassFile compileAndReturn(String fullFile, String testClass, String... extraParams) throws Exception {
         File source = writeTestFile(fullFile);
         File clazzFile = compileTestFile(source, testClass);
         return ClassFile.read(clazzFile);
@@ -170,8 +178,12 @@
         return f;
     }
 
-    protected File compileTestFile(File f, String testClass) {
-        int rc = com.sun.tools.javac.Main.compile(new String[] { "-source", "1.8", "-g", f.getPath() });
+    protected File compileTestFile(File f, String testClass, String... extraParams) {
+        List<String> options = new ArrayList<>();
+        options.addAll(Arrays.asList("-source", "1.8"));
+        options.addAll(Arrays.asList(extraParams));
+        options.add(f.getPath());
+        int rc = com.sun.tools.javac.Main.compile(options.toArray(new String[options.size()]));
         if (rc != 0)
             throw new Error("compilation failed. rc=" + rc);
         String path;
--- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ExceptionParameters.java	Wed Jan 15 10:57:25 2014 +0100
+++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ExceptionParameters.java	Wed Jan 15 13:49:57 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
 
 /*
  * @test
+ * @bug 8028576
  * @summary Test population of reference info for exception parameters
  * @author Werner Dietl
  * @compile -g Driver.java ReferenceInfoUtil.java ExceptionParameters.java