JDK-5061359 : No error for ambiguous member of intersection
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0,6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2004-06-10
  • Updated: 2017-05-16
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 Other
7 b03Fixed OpenJDK6Resolved
Related Reports
Duplicate :  
Duplicate :  
Relates :  
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
SUGGESTED FIX Webrev of changes: http://sa.sfbay/projects/langtools/bugid_summary.pl?bugid=5061359 See also attachment 5061359.tar.gz.
23-10-2006

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);
23-10-2006

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
23-10-2006

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> { ^
23-10-2006

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
23-10-2006

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
17-07-2004

PUBLIC COMMENTS ...
17-07-2004

EVALUATION All three errors should be reported. ###@###.### 2004-06-11
11-06-2004