JDK-6776289 : Regression: javac7 doesnt resolve method calls properly
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2008-11-25
  • Updated: 2011-05-18
  • Resolved: 2011-05-18
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
7 b42Fixed
Related Reports
Relates :  
Description
The following used to compile on JDK 6 and no longer compiles on JDK 7 (b40).
javac 1.7.0-ea
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b40)
Java HotSpot(TM) Server VM (build 14.0-b07, mixed mode)
----------------------------------------------------------------------------

public class Node { ... }

public class AbstractNode extends Node {
    private Image findIcon(int a,int b) { ... }
    ...
}
public class DataNode extends AbstractNode { ... }

public class DataFolder {
   static Image findIcon(int a, String s, String s2) { ... }
   public class FolderNode extends DataNode {
        public Image getOpenedIcon (int type) {
              ...
              Image img = findIcon(someint, somestring, someotherstring);
              ...
        }
   }
}

netbeans_platform/openide/loaders/src/org/openide/loaders/DataFolder.java:1123: method findIcon in class org.openide.nodes.AbstractNode cannot be applied to given types
    [javac] required: int,int
    [javac] found: int,java.lang.String,java.lang.String
    [javac]                 img = findIcon(0, "Nb.Explorer.Folder.icon", "Tree.closedIcon"); // NOI18N
    [javac]                       ^

I have attached a smaller test cases which shows this behaviour:
See Main.java and NewClass.java attached.
It compiles with JDK 6 compiler, and fails with JDK 7.

Comments
SUGGESTED FIX A webrev of this fix is available at the following URL http://hg.openjdk.java.net/jdk7/tl/langtools/rev/1d1f34b36535
26-11-2008

EVALUATION Simplified test case: class A { private void m(int a,int b) { } } class Test { static void m(int a, String s) { } class B extends A { public void test() { m(1, ""); } } } This problem has been caused by the fact that a line has inadvertently been removed from Resolve.selectBest - the line in question is: if (!sym.isInheritedIn(site.tsym, types)) return bestSoFar; Which means that if during method resolution a method symbol is found which has not been inherited by the current class, we should skip the rest of the resolution phase for that symbol; that line has been removed in order to try to generate a better diagnostic in case of resolution failure due to non-accessible method found. The idea was to go through resolution and then, if the found method was not accessible, return an error so that a proper diagnostic could have been displayed. This didn't take into account cases in which the method resolution failed because of e.g. an argument mismatch - in such cases a new and unwanted ResolveError is returned instead of an access error - and this is problematic as it might lead to subsequent resolution failures. Restoring the above line in Resolve.java fixes the problem.
25-11-2008