User account creation filtered due to spam.

Bug 18119 - Private inner class is visible when it shouldn't be
Summary: Private inner class is visible when it shouldn't be
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.4.2
: P2 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
Keywords: rejects-valid
Depends on:
Blocks: 18131 20697
  Show dependency treegraph
Reported: 2004-10-23 00:49 UTC by Casey Marshall
Modified: 2005-07-07 14:47 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2005-01-23 17:25:18


Note You need to log in before you can comment on or make changes to this bug.
Description Casey Marshall 2004-10-23 00:49:58 UTC
GCJ erroneously looks up inner classes (usually private) before classes in other

For example, I have three files a/, b/, and b/

-- a/
package a;
public abstract class A
  public abstract void a();

  public void b()
    new B().innerB();

  private class B
    public void innerB()
      System.out.println ("inner b!");

-- b/
package b;
class B
  public void b()
    System.out.println ("b!");

-- b/
package b;
import a.A;
class C extends A
  public void a()
    System.out.println ("aaa!");

  public static final void main (String[] argv)
    C c = new C();
    B b = new B();

$ gcj -C a/ b/ b/
b/ error: Nested class a.A$B is private; cannot be accessed from here.
       B b = new B();
1 error
$ gcj --version
gcj (GCC) 3.4.2

This is easy to work around (just say "b.B b = new b.B()"), but is still
incorrect. Javac and jikes do not fail.
Comment 1 Andrew Pinski 2004-10-23 16:13:20 UTC
Comment 2 Bryce McKinlay 2005-06-18 01:49:35 UTC
GCJ actually has the resolution order correct here. The problem is that a.A.B is
not visible from b.C, because its a private class. Instead of an error, however,
GCJ needs to resolve to the visible class b.B instead.

I'm testing a patch.
Comment 3 CVS Commits 2005-07-07 14:44:23 UTC
Subject: Bug 18119

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	2005-07-07 14:44:03

Modified files:
	libjava        : ChangeLog 
	libjava/testsuite/libjava.jacks: jacks.xfail 
	gcc/java       : ChangeLog parse.y 

Log message:
	2005-07-07  Bryce McKinlay  <>
	PR java/18119
	* parse.y (inner_class_accessible): New function. Logic moved from
	(check_inner_class_access): Use inner_class_accessible.
	(resolve_inner_class): Simplify arguments. Create circularity hash
	here. Keep looking for classes if we found one that was
	inaccessible. Return the inaccessible class only if there is no other
	(do_resolve_class): Update for new resolve_inner_class arguments.
	Don't create circularity_hash here.


Comment 4 Bryce McKinlay 2005-07-07 14:47:45 UTC
Fixed on HEAD.