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-Private Fields/Members


> // 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) {
>         }
>     }
> }

Andrew> m() in p1.T151221am3a can't implement m() in p1.T151221am3b
Andrew> because it is non-public.

Actually, T151221am3b.m() is implicitly public because it is declared
in an interface.

Andrew> So, AFAICS T151221am3d isn't legal because there isn't
Andrew> an implementation of m().  However, perhaps an abstract class doesn't
Andrew> have to implement all of the methods in its interfaces?

Right, an abstract class doesn't have to implement or declare the
methods it inherits from interfaces (or abstract methods from
superclasses for that matter).  This is where "Miranda methods" come
in...

I think the code above, while twisted, is legal.  This is pretty
pathological though.  I suppose this is a candidate for an exception
to the "no Jacks regressions" rule, particularly since Ranjit's patch
is an overall improvement in an already buggy part of gcj.

The previous gcj code was probably wrong anyway.  I suspect it would
let T151221am3d inherit T151221am3b.m(), which is wrong.

Tom


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