This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

java/9866: static nested class refers to private member of outer class


>Number:         9866
>Category:       java
>Synopsis:       static nested class refers to private member of outer class
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          support
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 26 17:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Brian DeRocher
>Release:        gcj-3.2, gij-3.2
>Organization:
>Environment:
GNU/Debian Linux (woody mostly)
>Description:
This bug comes from compiling ant-1.5.1, specifically  ProjectHelperImpl.java.  They create a nested static class.  In the nested class, they make an explicit reference to the outer class.  And finally they refer to a private member of the outer class.

Here's a simplification of the code:

public class PHI
        {
        public static void main( String args[] )
                {
                PHI phi = new PHI();
                RH rh = new RH( phi );
                rh.setLocator( "TheHound" );
                }

        private String locator;

        static class RH
                {
                PHI phi;
                public RH( PHI phi )
                        {
                        this.phi = phi;
                        }
                public void setLocator( String locator )
                        {
                        phi.locator = locator;
                        }
                }
        }

brian at mahogany:Personal/Workshop/Test/ :) gcj -C PHI.java
brian at mahogany:Personal/Workshop/Test/ :) gij PHI
Exception in thread "main" java.lang.IllegalAccessError
   at 0x40174218: java.lang.Throwable.Throwable() (/usr/lib/libgcj.so.2)
   at 0x4016a7c4: java.lang.Error.Error() (/usr/lib/libgcj.so.2)
   at 0x4016c908: java.lang.LinkageError.LinkageError() (/usr/lib/libgcj.so.2)
   at 0x4016b6a4: java.lang.IncompatibleClassChangeError.IncompatibleClassChangeError() (/usr/lib/libgcj.so.2)
   at 0x4016b404: java.lang.IllegalAccessError.IllegalAccessError() (/usr/lib/libgcj.so.2)
   at 0x40149d5a: _Jv_ResolvePoolEntry(java.lang.Class, int) (/usr/lib/libgcj.so.2)
   at 0x401516f0: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.2)
   at 0x40152703: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.2)
   at 0x4014e671: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/usr/lib/libgcj.so.2)
   at 0x4023b114: ?? (??:0)
   at 0x4023b25f: ffi_call_SYSV (/usr/lib/libgcj.so.2)
   at 0x4023b227: ffi_raw_call (/usr/lib/libgcj.so.2)
   at 0x4014e8db: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.2)
   at 0x40152703: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_InterpMethodInvocation) (/usr/lib/libgcj.so.2)
   at 0x4014e671: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/usr/lib/libgcj.so.2)
   at 0x4023b114: ?? (??:0)
   at 0x4015565f: gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.2)
   at 0x4015fb63: java.lang.Thread.run_(java.lang.Object) (/usr/lib/libgcj.so.2)
   at 0x4023a6a4: ?? (??:0)
   at 0x403dff76: GC_start_routine (/usr/lib/libgcjgc.so.1)
   at 0x403f7fa5: ?? (??:0)
   at 0x4050c8ea: __clone (/lib/libc.so.6)

In my personal opinion, i don't think this is a bug.  The inner class does have access to the private members of the outer class, but this is through an implicit reference.  Static classes don't have the implicit reference.  The question is, what is the definied behavior of an explicit reference.

So why do i report it?  Because obviously other compilers have compiled and executed ProjectHelperImpl successfully.

A related PR is 9369.

Just hypothetically here, if the compiler does generate a function void setLocator( String Locator )
	{ this.Locator = Locator }
in the outer class PHI, does this function become accessible to the public (or to subclasses)?  I hope not, since this would change the definition of the class.
>How-To-Repeat:
gcj -C PHI.java
gij PHI
>Fix:
If the outer data member is protected, there's no error.
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]