Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 5061359
Votes 0
Synopsis No error for ambiguous member of intersection
Category java:compiler
Reported Against b82 , tiger-beta2
Release Fixed 7(b03)
State 10-Fix Delivered, bug
Priority: 2-High
Related Bugs 6421111 , 6488960 , 6199146
Submit Date 10-JUN-2004
Description


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 :
 customer  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) 
======================================================================
Posted Date : 2005-08-31 23:04:30.0
Work Around
N/A
Evaluation
All three errors should be reported.

  xxxxx@xxxxx   2004-06-11
---

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
Posted Date : 2006-10-23 03:53:47.0

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> {
                  ^
Posted Date : 2006-10-23 04:13:27.0

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
Posted Date : 2006-10-23 04:12:25.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang