RFR: [Backport] JDK14-8235778: No compilation error reported when a record is declared in a local class

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Jan 28 09:11:10 UTC 2020


Good point - I  don't think this was the intent of the fix - but this test:

assertFail("compiler.err.record.declaration.not.allowed.in.inner.classes",
  519                 """
  520                 class Outer {
  521                     void m() {
  522                         record A() {
  523                             record B() { }
  524                         }
  525                     }
  526                 }
  527                 """);

Seems wrong/non conformant with the spec. The problem with the fix is 
that it bans records if they happen to be declared inside a 'type'. 
There are at least three cases where this doesn't create (at least in 
principle) any issues:

* record inside interfaces (interfaces are always static)
* record inside enum (enums are always static)
* record inside static nested class
* record inside record (records are always static)

Now I believe that the first three are implicitly handled by the fact 
that such records are not considered 'local' by javac (you cannot have 
enums or static classes inside a method), so the check tweaked by this 
patch doesn't apply. But record inside a local record is a possibility.

We should probably add extra tests for all these cases.

Maurizio

On 28/01/2020 07:51, Tagir Valeev wrote:
> Hello!
>
> Why a record inside the local record is not allowed, given that the
> local record is implicitly static and static members are allowed
> inside? Could you please point me where this is disabled in the
> specification? Thanks.
>
> With best regards,
> Tagir Valeev.
>
> On Tue, Jan 28, 2020 at 6:29 AM Maurizio Cimadamore
> <maurizio.cimadamore at oracle.com> wrote:
>> Looks good
>>
>> Maurizio
>>
>> On 27/01/2020 22:45, Vicente Romero wrote:
>>> Please review backport of bug [1] into JDK14. The fix was initially
>>> pushed to JDK15. The fix for JDK14 can be seen at [2]. The initial
>>> review thread for the fix that got pushed into JDK15 can be seen at [3].
>>>
>>> Thanks,
>>> Vicente
>>>
>>> [1] https://bugs.openjdk.java.net/browse/JDK-8235778
>>> [2] http://cr.openjdk.java.net/~vromero/8235778_jdk14/webrev.00/
>>> [3]
>>> https://mail.openjdk.java.net/pipermail/compiler-dev/2019-December/014076.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20200128/fc009d39/attachment-0001.htm>


More information about the compiler-dev mailing list