JDK-5005072 : binary compatibility rules cause wrong method to be called!
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8
  • CPU: generic
  • Submitted: 2004-02-28
  • Updated: 2004-07-16
  • Resolved: 2004-07-16
Related Reports
Duplicate :  
Description
The current binary compatibility rules require the marked call
to be statically resolved to T2.m() at compile time, but to
generate T2a as the qualifying type in the binary.  This results
in the wrong method being called at runtime.

//////////////////////////////////////////////////////////
import java.util.*;

import static java.lang.System.out;

public class T2 {

    public static void main(String[] args) {
	Collection c = T2a.m(new ArrayList<String>());	// => "T2a.m"
    }

    static Collection m(List<String> p) {
	out.println("T2.m");
	return null;
    }
}


class T2a extends T2 {

    static Collection m(List<Number> p) {
	out.println("T2a.m");
	return null;
    }
}

Comments
EVALUATION This example is illegal according to the specification. Specifically: We have class T2a with two member methods named m. Note that 2a.m does not hide T2.m, as its signatures is not a subsignature of that of T2.m. The method T2m is accessible from T2a (otherwise it could not be called as shown, nor could it be a member of T2a). The two methods have the same erasure. The situation described is specified to be illegal. ###@###.### 2004-07-15 Then this is a compiler bug. ###@###.### 2004-07-15
15-07-2004