<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 19 Sep 2020, at 10:23, Tagir Valeev <<a href="mailto:amaembo@gmail.com" class="">amaembo@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hello!<br class=""><br class="">On Fri, Sep 18, 2020 at 10:40 PM Gavin Bierman <<a href="mailto:gavin.bierman@oracle.com" class="">gavin.bierman@oracle.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">- It is annotated with the annotations, if any, that appear on the corresponding<br class=""> record component and whose annotation types are applicable in the method<br class=""> declaration context, or in type contexts, or both. **The rules for these<br class=""> annotation modifiers, if any, on the accessor method are the same as for a<br class=""> method declaration, and are specified in [9.7.4] and [9.7.5].**<br class=""><br class="">The last sentence is new, and mirrors what is said about normal method declarations in §8.4.3.<br class=""><br class="">What do you think?<br class=""></blockquote><br class="">I'm not very good in English but I'm fine if this statement<br class="">unambiguously imply that<br class="">if the annotation is not applicable to the method, then this is a<br class="">compilation error to put it on the record accessor.<br class=""></div></div></blockquote><div><br class=""></div><div>Well it’s as unambiguous as the existing text around annotations on method declarations :-) </div><div><br class=""></div><div>I think to further emphasise this point, I will add the following text after the list of properties of the implicitly declared accessor method:</div><div><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div>An implicitly declared accessor method must satisfy all the rules for a</div></div><div><div>method in a normal class declaration ([8.4]).</div></div></blockquote><div><br class=""></div><div>That makes it crystal clear (I hope). </div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">Btw, we allowed Override on explicit accessors, so now it might be<br class="">unclear whether it's allowed on implicit ones.<br class=""><br class="">Also what if we mark the record component with `@SafeVarargs` and<br class="">define an explicit accessor without this annotation? Like:<br class=""><br class="">record X(@SafeVarargs int y) {<br class=""> @Override<br class=""> public int y() {<br class=""> return y;<br class=""> }<br class="">}<br class=""><br class="">Is this acceptable? Javac 15 happily compiles this.<br class=""></div></div></blockquote><div><br class=""></div>Under the current rules this is acceptable; as the @SafeVarargs annotation is not propagated to the explicitly declared accessor method. </div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">This brings more general question: is it allowed to put an annotation<br class="">that targeted to METHOD only if we define explicit accessor? In this<br class="">case, the annotation is not propagated anywhere and completely<br class="">disappears from the bytecode, even if it has CLASS/RUNTIME retention.<br class="">So probably this code should be rejected as mistaken? <br class=""></div></div></blockquote><br class=""></div><div>That’s a very good question - well spotted. I think there is a good case to call that out as a compile-time error. Opinions everyone?</div><div><br class=""></div><div>Gavin</div><br class=""></body></html>