Bug 1262 - Method with default access can be overridden in another package
Summary: Method with default access can be overridden in another package
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 2.96
: P3 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: 13607
  Show dependency treegraph
 
Reported: 2000-12-20 12:18 UTC by Bryce McKinlay
Modified: 2004-06-29 18:00 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-06-23 10:01:05


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bryce McKinlay 2000-12-20 12:18:27 UTC
It is legal in Java for class to declare a method with the
same name as a default (package-private) method in a 
foreign-package superclass.

However, because it is invisible to the sub-class, the
method should NOT override the superclasses method 
declaration.

Release:
unknown

Environment:
gcc version 2.96 20000525 (experimental)

How-To-Repeat:
Compile the following code:

// file: pkg1/A.java
package pkg1;
public class A 
{
  void foo () 
  {
    System.out.println ("A.foo()");
  }
  
  public static void main(String[] args) {
    A x = new pkg2.B();
    x.foo();
  }
}

// file: pkg2/B.java
package pkg2;
public class B extends pkg1.A 
{
  protected void foo ()
  {
    System.out.println("B.foo()"); 
  }
}

The correct output (as tested on IBM JDK 1.1.8 and Sun 1.2.2)
should read:

$ java pkg1.A
A.foo()

The gcj-compiled output is:

$ ./pkg
B.foo()
Comment 1 Dara Hazeghi 2003-05-11 20:02:32 UTC
From: Dara Hazeghi <dhazeghi@yahoo.com>
To: apbianco@gcc.gnu.org, gcc-gnats@gcc.gnu.org, bryce@albatross.co.nz
Cc:  
Subject: Re: java/1262: Method with default access can be overridden in another package
Date: Sun, 11 May 2003 20:02:32 -0700

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit- 
 trail&database=gcc&pr=1262
 
 Hello,
 
 this PR was filed against (then current) gcc 3.0 snapshot. Would it be  
 possible to determine if this problem is still present in current 3.3  
 or mainline, and update the report accordingly? Thanks,
 
 Dara
Comment 2 Pietu Pohjalainen 2004-04-14 19:03:56 UTC
This bug seems to be still present in the 3.3.3:
When compiled with gcj 3.3.3, or run with gij 3.3, it
returns wrong output

--- clip ---
ppohja@noam:~/test$ gcj -v
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.3/specs
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.3/../../../libgcj.spec
rename spec lib to liborig
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,
objc,ada,treelang --prefix=/usr --mandir=/usr/share/man 
--infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 
--enable-shared --with-system-zlib --enable-nls --without-included-gettext 
--enable-__cxa_atexit --enable-clocale=gnu --enable-debug --enable-java-gc=boehm 
--enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.3 (Debian 20040401)
ppohja@noam:~/test$
ppohja@noam:~/test$
ppohja@noam:~/test$ ls pkg1/ pkg2/
pkg1/:
A.java

pkg2/:
B.java
ppohja@noam:~/test$
ppohja@noam:~/test$
ppohja@noam:~/test$ /usr/local/j2sdk1.4.2_02/bin/javac pkg1/A.java
ppohja@noam:~/test$ /usr/local/j2sdk1.4.2_02/bin/java pkg1.A
A.foo()
ppohja@noam:~/test$
ppohja@noam:~/test$
ppohja@noam:~/test$ gcj pkg1/A.java pkg2/B.java --main=pkg1.A -o gcj-output
ppohja@noam:~/test$ ./gcj-output
B.foo()
ppohja@noam:~/test$
ppohja@noam:~/test$ java -version
gij (GNU libgcj) version 3.3.3 (Debian 20040401)

Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
ppohja@noam:~/test$
ppohja@noam:~/test$
ppohja@noam:~/test$ java pkg1.A
B.foo()

Comment 3 Ranjit Mathew 2004-06-23 10:01:04 UTC
Still present on mainline (3.5.0 - 20040623).
Comment 4 CVS Commits 2004-06-29 17:58:48 UTC
Subject: Bug 1262

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	bryce@gcc.gnu.org	2004-06-29 17:58:45

Modified files:
	gcc/java       : ChangeLog class.c java-tree.h parse.y 

Log message:
	PR java/1262
	* class.c (layout_class_method): Do not override package-private
	method if its in a different package.
	(split_qualified_name): Move here from parse.y. Rename from
	breakdown_qualified. Add comment.
	(in_same_package): Move here from parse.y. Add comment.
	* java-tree.h (break_down_qualified, in_same_package): Declare.
	(in_same_package): Likewise.
	* parse.y (breakdown_qualified, in_same_package): Moved to class.c.
	Callers updated.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1394&r2=1.1395
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/class.c.diff?cvsroot=gcc&r1=1.188&r2=1.189
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/java-tree.h.diff?cvsroot=gcc&r1=1.202&r2=1.203
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/parse.y.diff?cvsroot=gcc&r1=1.488&r2=1.489

Comment 5 Bryce McKinlay 2004-06-29 18:00:33 UTC
Fix checked in to HEAD.