src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java

Print this page
rev 2609 : 8065132: Parameter annotations not updated when synthetic parameters are prepended
Summary: Cause javac to add synthetic parameters to Runtime[In]VisibleParameterAnnotations attributes
Reviewed-by: jjg, jfranck

@@ -668,10 +668,31 @@
         } else
             return 0;
     }
 
 
+    private void writeParamAnnotations(List<VarSymbol> params,
+                                       RetentionPolicy retention) {
+        for (VarSymbol s : params) {
+            ListBuffer<Attribute.Compound> buf = new ListBuffer<>();
+            for (Attribute.Compound a : s.getRawAttributes())
+                if (types.getRetention(a) == retention)
+                    buf.append(a);
+            databuf.appendChar(buf.length());
+            for (Attribute.Compound a : buf)
+                writeCompoundAttribute(a);
+        }
+
+    }
+
+    private void writeParamAnnotations(MethodSymbol m,
+                                       RetentionPolicy retention) {
+        databuf.appendByte(m.params.length() + m.extraParams.length());
+        writeParamAnnotations(m.extraParams, retention);
+        writeParamAnnotations(m.params, retention);
+    }
+
     /** Write method parameter annotations;
      *  return number of attributes written.
      */
     int writeParameterAttrs(MethodSymbol m) {
         boolean hasVisible = false;

@@ -690,35 +711,17 @@
         }
 
         int attrCount = 0;
         if (hasVisible) {
             int attrIndex = writeAttr(names.RuntimeVisibleParameterAnnotations);
-            databuf.appendByte(m.params.length());
-            for (VarSymbol s : m.params) {
-                ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
-                for (Attribute.Compound a : s.getRawAttributes())
-                    if (types.getRetention(a) == RetentionPolicy.RUNTIME)
-                        buf.append(a);
-                databuf.appendChar(buf.length());
-                for (Attribute.Compound a : buf)
-                    writeCompoundAttribute(a);
-            }
+            writeParamAnnotations(m, RetentionPolicy.RUNTIME);
             endAttr(attrIndex);
             attrCount++;
         }
         if (hasInvisible) {
             int attrIndex = writeAttr(names.RuntimeInvisibleParameterAnnotations);
-            databuf.appendByte(m.params.length());
-            for (VarSymbol s : m.params) {
-                ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
-                for (Attribute.Compound a : s.getRawAttributes())
-                    if (types.getRetention(a) == RetentionPolicy.CLASS)
-                        buf.append(a);
-                databuf.appendChar(buf.length());
-                for (Attribute.Compound a : buf)
-                    writeCompoundAttribute(a);
-            }
+            writeParamAnnotations(m, RetentionPolicy.CLASS);
             endAttr(attrIndex);
             attrCount++;
         }
         return attrCount;
     }