United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6724345 incorrect method resolution for enum classes entered as source files
6724345 : incorrect method resolution for enum classes entered as source files

Details
Type:
Bug
Submit Date:
2008-07-10
Status:
Closed
Updated Date:
2011-05-31
Project Name:
JDK
Resolved Date:
2011-05-18
Component:
tools
OS:
linux,windows_xp
Sub-Component:
javac
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
6,6u20,6u25
Fixed Versions:
7

Related Reports
Backport:
Duplicate:
Duplicate:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0_10-rc"
Java(TM) SE Runtime Environment (build 1.6.0_10-rc-b27)
Java HotSpot(TM) Client VM (build 11.0-b14, mixed mode)


A DESCRIPTION OF THE PROBLEM :
Compilation of the enclosed program is very sensitive to the order in which the source files are presented.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Unpack the sources and try

javac U.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compiles successfully
ACTUAL -
Fails to compile

ERROR MESSAGES/STACK TRACES THAT OCCUR :
U.java:5: cannot find symbol
symbol  : method i()
location: class E
	E.V.i();
           ^
1 error


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
==> I.java <==
interface I {
 void i();
}

==> E.java <==
enum E implements I {
 V { public void i() { } };
 // public abstract void i();
}

==> U.java <==
class U {
 {
   I i = E.V;
   i.i();
   E.V.i();
 }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
running 'javac E.java && javac U.java' succeeds.

Uncommenting line 3 of E.java also works around the problem.

                                    

Comments
EVALUATION

This is a resolution bug due to the fact that javac doesn't check for superinterfaces method when resolving a method invoked on a receiver whose type is an enum type. In the submitted example we have that i() is invoked on the enum type E. Since abstract method checking is disabled, no such method is found in E. On the other hand, if we compile the enum first (or if we simply alter the order in which classes get compiled) the enum gets translated by javac into an abstract class, thus enabling abstract method checking as a side-effect. This explains why the program compiles only when a given compilation order is specified.
                                     
2008-07-22
SUGGESTED FIX

A webrev of this fix is available at the following URL
http://sa.sfbay.sun.com/projects/langtools_data/7/6724345
                                     
2008-07-22



Hardware and Software, Engineered to Work Together