JDK-6355696 : Compiler can not make boxing in a method call
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_2003
  • CPU: x86
  • Submitted: 2005-11-28
  • Updated: 2010-04-02
  • Resolved: 2009-03-13
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows  2000 Server SP4

A DESCRIPTION OF THE PROBLEM :
Compiler does not compile the following code:

class Rare {
    public static void main( String... args ) {
		genericMethod( 5 );
	}
	
    static <T extends Integer> void genericMethod( T i ) {
    	System.out.println( i.getClass().getName() );
    }
}

The output error message is:

Rare.java:3: cannot find symbol
symbol  : method valueOf(int)
location: bound of type variable T
                genericMethod( 5 );
                               ^
Fatal Error: Unable to find method valueOf

The problem seems that the compiler can not do boxing, and show a FatalError making reference to the valueOf method of the Integer wrapper class.

This bug is present with all primitive wrappers: Byte, Short, Integer, Long, Float, Double, Boolean.

The following variations compiles fine

class NotRare {
    public static void main( String... args ) {
		genericMethod( 5 );
	}
	
    static <T extends Number> void genericMethod( T i ) {
    	System.out.println( i.getClass().getName() );
    }
}
Output: java.lang.Integer
( Boxing to Integer works fine )

class NotRare {
    public static void main( String... args ) {
		genericMethod( 5 );
	}
	
    static <T extends Integer> void genericMethod( T... i ) {
    	System.out.println( i.getClass().getName() );
    }
}
Output: [Ljava.lang.Integer;
(Boxing to Array of Integer)


class NotRare {
    public static void main( String... args ) {
		genericMethod( new Integer(5) );
	}
	
    static <T extends Integer> void genericMethod( T i ) {
    	System.out.println( i.getClass().getName() );
    }
}
Output: java.lang.Integer
(Explicit Integer argument)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compiles fine and show the following Output

java.lang.Integer

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Rare.java:3: cannot find symbol
symbol  : method valueOf(int)
location: bound of type variable T
                genericMethod( 5 );
                               ^
Fatal Error: Unable to find method valueOf

REPRODUCIBILITY :
This bug can be reproduced always.

Comments
EVALUATION Not reproducible after jdk 7 b25 (see 6614974)
13-03-2009

EVALUATION A bug. The fix is probably similar to the fix for 6240565.
30-12-2005