United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 5061359 No error for ambiguous member of intersection
5061359 : No error for ambiguous member of intersection

Details
Type:
Bug
Submit Date:
2004-06-10
Status:
Closed
Updated Date:
2010-07-09
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
tools
OS:
generic,windows_xp
Sub-Component:
javac
CPU:
x86,generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
5.0,6
Fixed Versions:
7

Related Reports
Backport:
Duplicate:
Duplicate:
Relates:

Sub Tasks

Description
Name: rmT116609			Date: 06/10/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
When an ambiguous reference is made to a member of a type variable (either a method or an inner class), no error is reported.

Also, the acessibility checking for members is incorrect when the type variable has multiple bounds.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Test.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test.java:7: reference to Inner is ambiguous
Test.java:9: reference to m1() is ambiguous
ACTUAL -
Test.java:8: _field is not public in Base; cannot be accessed from outside package
        t._field = 3;         // This should not be an accessibility error
         ^
1 error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.*;

public class Test<T extends Base & Intf> {

    public void foo() {
        T t = null;
        T.Inner inner = null; // This should be an ambiguous error
        t._field = 3;         // This should not be an accessibility error
        t.m1();               // This should be an ambiguous error
    }

}

class Base {
    static class Inner {}
    int _field;
    int m1(){ return 0;}
}

interface Intf {
    static final String C1 = "BLAH";
    static class Inner{}
    void m1();
}

---------- END SOURCE ----------
(Incident Review ID: 276926) 
======================================================================

                                    

Comments
EVALUATION

---

The submitter was almost right.  There should be two errors.  However,
the problem with m1() should be reported when the type variable T is
defined:

Test.java:3: m1() in Base cannot implement m1() in Intf; attempting to assign weaker access privileges; was public
public class Test<T extends Base & Intf> {
                  ^
Test.java:7: reference to Inner is ambiguous, both class Base.Inner in Base and class Intf.Inner in Intf match
        T.Inner inner = null; // This should be an ambiguous error
         ^
2 errors
                                     
2006-10-23
EVALUATION

If we public to Base.m1():

Test.java:3: m1() in Base cannot implement m1() in Intf; attempting to use incompatible return type
found   : int
required: void
public class Test<T extends Base & Intf> {
                  ^
                                     
2006-10-23
SUGGESTED FIX

Index: j2se/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
6-10-22 21:21:15.000000000 -0700
+++ /tmp/getb22606	2006-10-22 21:21:15.000000000 -0700
@@ -342,7 +342,6 @@
         // Enter and attribute type parameters.
         List<Type> tvars = enter.classEnter(typarams, env);
         attr.attribStats(typarams, env);
-        attr.attribBounds(typarams);
 
         // Enter and attribute value parameters.
         ListBuffer<Type> argbuf = new ListBuffer<Type>();
@@ -406,7 +405,6 @@
             (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) {
             addEnumMembers(tree, env);
         }
-        attr.attribBounds(tree.typarams);
         memberEnter(tree.defs, env);
     }
 
Index: j2se/src/share/classes/com/sun/tools/javac/comp/Attr.java
--- /tmp/geta12673	2006-10-24 22:24:16.000000000 -0700
+++ /tmp/getb12673	2006-10-24 22:24:16.000000000 -0700
@@ -532,10 +532,10 @@
 
         Lint lint = env.info.lint.augment(m.attributes_field, m.flags());
         Lint prevLint = chk.setLint(lint);
-
+        try {
         chk.checkDeprecatedAnnotation(tree.pos(), m);
 
-        try {
+            attribBounds(tree.typarams);
 
             // If we override any other methods, check that we do so properly.
             // JLS ???
@@ -2642,6 +2642,7 @@
         chk.validateAnnotations(tree.mods.annotations, c);
 
         // Validate type parameters, supertype and interfaces.
+        attribBounds(tree.typarams);
         chk.validateTypeParams(tree.typarams);
         chk.validate(tree.extending);
         chk.validate(tree.implementing);
                                     
2006-10-23
SUGGESTED FIX

Webrev of changes: http://sa.sfbay/projects/langtools/bugid_summary.pl?bugid=5061359
See also attachment 5061359.tar.gz.
                                     
2006-10-23
EVALUATION

The problem is the order of compilation.  If the classes are moved
into seperate compilation unit, the result varies:

$ javac Base.java Intf.java Test.java
Test.java:3: m1() in Base cannot implement m1() in Intf; attempting to use incompatible return type
found   : int
required: void
public class Test<T extends Base & Intf> {
                  ^
Test.java:8: _field is not public in Base; cannot be accessed from outside package
        t._field = 3;         // This should not be an accessibility error
         ^
2 errors
$ javac Test.java Base.java Intf.java
Test.java:8: _field is not public in Base; cannot be accessed from outside package
        t._field = 3;         // This should not be an accessibility error
         ^
1 error
                                     
2006-10-23
PUBLIC COMMENTS

...
                                     
2004-07-17
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mustang


                                     
2004-07-17
EVALUATION

All three errors should be reported.

###@###.### 2004-06-11
                                     
2004-06-11



Hardware and Software, Engineered to Work Together