JDK-8055769 : Type variable incorrectly resolved to class in a different scope
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,8u20
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_redhat_6.0
  • CPU: x86
  • Submitted: 2014-08-20
  • Updated: 2014-09-02
  • Resolved: 2014-09-02
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) Server VM (build 25.20-b23, mixed mode)

A DESCRIPTION OF THE PROBLEM :
The Java 8 compiler incorrectly resolves type variables to classes if they have the same name in the same package.

REGRESSION.  Last worked in version 7u67

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) Server VM (build 24.65-b04, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the sample that I've attached.  If you change the type variable X of interface A to anything other than X the program compiles.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No compilation error occur.
ACTUAL -
The errors listed below occur.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Error:(38, 58) java: type argument mil.navy.nrl.itd.flying_squirrel.utilities.preferences.ErasureTest.X is not within bounds of type-variable Type
Error:(45, 19) java: getX() in mil.navy.nrl.itd.flying_squirrel.utilities.preferences.ErasureTest.B clashes with getX() in mil.navy.nrl.itd.flying_squirrel.utilities.preferences.ErasureTest.A
  return type X is not compatible with mil.navy.nrl.itd.flying_squirrel.utilities.preferences.ErasureTest.X
Error:(44, 17) java: method does not override or implement a method from a supertype
Error:(47, 17) java: method does not override or implement a method from a supertype

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package mil.navy.nrl.itd.flying_squirrel.utilities.preferences;

import java.util.Collection;
import java.util.List;

import javax.management.DescriptorKey;
import org.junit.Test;

/**
 * Created on 8/20/14 @ 5:17 PM.
 *
 * @author brandon-enochs
 */
public class ErasureTest {

// -------------------------- INNER CLASSES --------------------------

	private interface X<Y> {

// -------------------------- OTHER METHODS --------------------------

		@Test
		Y getY();

	}

	private interface A<Type extends Collection<?>> {

// -------------------------- OTHER METHODS --------------------------

		@DescriptorKey(value = "a")
		Type getX();

		void setX(Type value);

	}

	private interface B<X extends List<?>> extends A<X> {

// ------------------------ INTERFACE METHODS ------------------------

// --------------------- Interface A ---------------------

		@Override
		X getX();

		@Override
		void setX(X value);

	}

}

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

CUSTOMER SUBMITTED WORKAROUND :
You can workaround this bug by renamed your type variable to a name that isn't used for anything else.


Comments
Stripped-down test: public class JDK8055769 { interface X {} interface A<T extends String> {} interface B<X extends String> extends A<X> {} } error: type argument X is not within bounds of type-variable T The problem is that 'X' in 'A<X>' is being interpreted as a reference to the interface 'X', not the type parameter 'X'.
29-08-2014