Compilation fails because anonymous class constructor formal parameter has inaccessible type

Georgiy Rakov georgiy.rakov at oracle.com
Thu Jul 23 13:58:22 UTC 2015


Hi Srikanth,

I'm not Victor :) but anyway I believe yes, this is the same.

BTW: Test18_2.v1 which I passed to the constructor in the example here 
seems to be nonrelevant to the problem. If null is passed compilation 
still fail:

    class Test18_2 {private static class MyClass {}Test18_2(MyClass mc)
    {}}public class Test18 {public static void main(String[] args) {new
    Test18_2(null){};}}

Thanks,
Georgiy.

On 22.07.2015 17:55, Srikanth wrote:
> Hi Victor,
>
> Thanks, is this the same as 
> https://bugs.openjdk.java.net/browse/JDK-8075799 ?
>
> Srikanth
>
> On Wednesday 22 July 2015 07:33 PM, Georgiy Rakov wrote:
>> Hello,
>>
>> let's consider following example:
>>
>>     class Test18_2 {private static class MyClass {}public static
>>     MyClass v1 = new MyClass();Test18_2(MyClass mc) {}}public class
>>     Test18 {public static void main(String[] args) {new
>>     Test18_2(Test18_2.v1){};}}
>>
>>
>> this example fails to compile on JDK9b73 with following error:
>>
>>     Error:(9, 34) java: Test18_2.MyClass has private access in Test18_2
>>
>> However according to my understanding compilation should succeed as 
>> per assertion jls-15.9.5.1-200:
>>
>>     Note that it is possible for the signature of the anonymous
>>     constructor to refer to an inaccessible type (for example, if
>>     such a type occurred in the signature of the superclass
>>     constructor |cs|). This does not, in itself, cause any errors at
>>     either compile-time or run-time.
>>
>> It seems to be a javac bug. Could you please tell if you agree.
>>
>> Thanks,
>> Georgiy.
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150723/cbdfed11/attachment-0001.html>


More information about the compiler-dev mailing list