[Bug java/32638] New: Wrong selection of field in inner class when outer class and super class have a relevant filed named the same

mark at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Thu Jul 5 17:12:00 GMT 2007


The following program should print true, but prints false when compiled with
gcj -C because the wrong field o is selected in the anonymous inner class (the
protected field named o in the super class is more specific than the field o in
the enclosing method).

public class t
{
  static abstract class a
  {
    protected Object o = new Object();
    abstract void print(Object input);
  }

  static class b
  {
    void m()
    {
      final Object o = new Object();
      a x = new a()
        {
          void print(Object input)
          {
            System.out.println(o != input);
          }
        };
      x.print(o);
    }
  }

  public static void main(String[] args)
  {
    new b().m();
  }
}

Since this is pretty hard to see why this code works/doesn't work in the first
place (the super class could be in a completely different file and the field in
the outer class certainly looks like it would be the one that is used in the
inner class) a warning for this kind of usage would be nice.

gcj (GCC) 4.1.2 20070626 (Red Hat 4.1.2-13)


-- 
           Summary: Wrong selection of field in inner class when outer class
                    and super class have a relevant filed named the same
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mark at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32638



More information about the Gcc-bugs mailing list