This is the mail archive of the gcc-patches@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]

Re: [Patch] PR java/9685: Fix Catching Illegal Access to Package-PrivateFields/Members


Ranjit Mathew writes:
 > 
 >   15.12.2.1-accessibility-method-3 PASSED
 >   15.12.2.1-accessibility-method-5 PASSED
 > 
 > I do not immediately understand the reasons
 > these two are failing - my Java language-laywer
 > skills are rather limited - and would appreciate
 > any insight into why GCJ thinks that the methods
 > in question should have package-private access.

--------------------------------------------------------------------------
// p1/T151221am3c.java 
package p1;
abstract class T151221am3a {
    abstract void m(); // note non-public accessibility
}
interface T151221am3b {
    void m() throws Exception;
}
public abstract class T151221am3c extends T151221am3a implements T151221am3b {
    // inherits 2 versions of m()
}
--------------------------------------------------------------------------
// T151221am3d.java
abstract class T151221am3d extends p1.T151221am3c {
    // a concrete subclass of c will necessarily have an implementation of m
    // that does not throw, in order to implement a.m; but only b.m was
    // inherited here because of accessibility. Since b.m throws, the catch
    // clause is reachable
    {
        try {
            m();
        } catch (Exception e) {
        }
    }
}
--------------------------------------------------------------------------

m() in p1.T151221am3a can't implement m() in p1.T151221am3b because it
is non-public.  So, AFAICS T151221am3d isn't legal because there isn't
an implementation of m().  However, perhaps an abstract class doesn't
have to implement all of the methods in its interfaces?  But to do
this would require a subclass to override a non-public declaration of
m() with a public one.

Javac says:

./p1/T151221am3c.java:8: m() in p1.T151221am3a cannot implement m() in p1.T151221am3b; attempting to assign weaker access privileges; was public
public abstract class T151221am3c extends T151221am3a implements T151221am3b {
                ^
1 error

What does the patched gcj say?

Andrew.


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