Bug 13098 - accepts invalid code referencing package only constructor
Summary: accepts invalid code referencing package only constructor
Status: RESOLVED DUPLICATE of bug 9685
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: 13607
  Show dependency treegraph
 
Reported: 2003-11-18 05:50 UTC by Andrew Pinski
Modified: 2004-04-27 09:06 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-04-18 04:19:16


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2003-11-18 05:50:37 UTC
try to compile this, gcj should reject this.
t/t.java:
package t;
public class t
{
t(){}
}
test.java:
import t.t;
class test {
    public static void main(String argv[]) {
        t b = new t();
    }
}
Comment 1 Sanjay Patel 2003-11-18 09:40:55 UTC
Some more thoughts on this problem...

If a constructor has no access specifier, "... there is default access, which is
permitted only when the access occurs from within the package in which the type
is declared," so in this case access should not be permitted (section 6.6.1 in
the Java Language Specification 2nd ed. available at
http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html).

Sun's compiler and IBM's jikes compiler do not compile the code, yet gcj does
compile it.

gij throws an an IllegalAccessError when running the improperly compiled code,
but oddly both Microsoft's VM and Sun's VM run it without error (the constructor
is actually executed).  It seems to me that this this is a problem with Sun's VM
and Microsoft's VM, and could possibly cause of incompatibilities.

For example what if someone developed a Java program with gcj that accidently
accesses a constructor with default access from outside the package (which is
technically illegal)?  Then the bytecode would run fine on Sun's VM or
Microsoft's VM, but would fail if run with gij, and users might think gij has a bug.
Comment 2 Andrew Pinski 2003-12-27 15:31:17 UTC
Confirmed, there are a couple of access bugs for gcj somewhere.
Comment 3 Andrew Pinski 2003-12-27 21:15:57 UTC
Related to bug 1262.
Comment 4 Ranjit Mathew 2004-04-27 09:06:45 UTC
The patch for 9685:

  http://gcc.gnu.org/ml/java-patches/2004-q2/msg00230.html

also fixes this bug.

*** This bug has been marked as a duplicate of 9685 ***