United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6709709 javadoc does not get compilation errors after type erasure
6709709 : javadoc does not get compilation errors after type erasure

Details
Type:
Bug
Submit Date:
2008-06-02
Status:
Closed
Updated Date:
2011-10-11
Project Name:
JDK
Resolved Date:
2011-10-11
Component:
tools
OS:
windows_xp
Sub-Component:
javadoc(tool)
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
6u30

Related Reports
Backport:
Backport:
Backport:
Relates:
Relates:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java 1.5.0.12

A DESCRIPTION OF THE PROBLEM :
run javadoc against the following class:
package bug;

import java.util.List;

public class JavaDocGenerics {
 public  void a(List<String> s){}
 public  void a(List<StringBuffer> s){}
}

No warning or error will be reported. The html will be generated, although anchors for both methods will be the same.

However,

Run the javadoc against the following class

package bug;



public class JavaDocNoneGenerics {
   public void b(int a){}
   public void b(int a){}
}

The javadoc will report:
" b(int) is already defined in bug.JavaDocGenerics
   public void b(int a){}
               ^
"
and the html file will be generated will one method in it.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run javadoc against the following class:
package bug;

import java.util.List;

public class JavaDocGenerics {
 public  void a(List<String> s){}
 public  void a(List<StringBuffer> s){}
}

No warning or error will be reported. The html will be generated, although anchors for both methods will be the same.

However,

Run the javadoc against the following class

package bug;



public class JavaDocNoneGenerics {
   public void b(int a){}
   public void b(int a){}
}

The javadoc will report:
" b(int) is already defined in bug.JavaDocGenerics
   public void b(int a){}
               ^
"
and the html file will be generated will one method in it.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

package bug;
import java.util.List;

public class JavaDocGenerics {
 public  void a(List<String> s){}
 public  void a(List<StringBuffer> s){}
}





package bug;

public class JavaDocNoneGenerics {
   public void b(int a){}
   public void b(int a){}
}

---------- END SOURCE ----------

                                    

Comments
SUGGESTED FIX

http://jpsesvr.us.oracle.com:8080/ctetools/CodeStore/4204/webrev/index.html
                                     
2011-08-02
EVALUATION

Change in file Check.java. Putting one condition to check for method signature.

void duplicateErasureError(int pos, Symbol sym1, Symbol sym2) 
	{
		if (!sym1.type.isErroneous() && !sym2.type.isErroneous()) 
		{
			log.error(pos, "name.clash.same.erasure", sym1, sym2);
		}
	}

-----------------------------------

Comment by Maurizio

I approve this fix, as I think that it's good to move error checking earlier in the compiler pipeline. But I must warn you that the fix, as it is now is incomplete, in the sense that there is a very similar test case that, if I'm right, is not covered by your fix; here's the code:

import java.util.List;

class JavaDocGenerics {
    public  void a(String[] s){}
    public  void a(String... s){}
}
If you run javadoc on this source, again javadoc fails to detect this error (you cannot have two methods one accepting a varargs and the other one accepting an array - it's a duplicate error, more or less for the same reason for which it's an error to accept two methods with the same erasure in the same class).

I know that this testcase is not directly related to CR 6709709 and, perhaps, it is outside the scope of this escalation. It's up to you whether to keep the fix as it is now, or to go for a different one that tackles also the varargs issue. Should you go for the latter option, I'd be happy to help, as we already have that fixed in JDK 7.

Maurizio 


----------
Some more cases suspected by Maurizio: 

E.g. another example of thing that might fail with javadoc:

class A<X extends Number> {
   void m(X o) {}
}

class B extends A<Integer> {
   void m(Integer o) {} //ok overrides m(X), where X is Integer
   void m(Number o) {} //error, m(Number) does not override m(X) in A, but have the same erasure
}
                                     
2008-08-19



Hardware and Software, Engineered to Work Together