Bug 282869

Summary: [compiler] Unnecessary cast warning for cast from char to int
Product: [Eclipse Project] JDT Reporter: Gunter Herrmann <gunter_herrmann>
Component: CoreAssignee: Kent Johnson <kent_johnson>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann, srikanth_sankaran
Version: 3.5   
Target Milestone: 3.6 M1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Proposed patch and testcase none

Description Gunter Herrmann CLA 2009-07-08 11:02:26 EDT
Build ID: 20090621-0832

Steps To Reproduce:
1. Use code below
2. See different results



More information:
char a = 65;
String b = "" + a; // -> "A"
String c = "" + (int) a; // -> "65", shows unnecessary cast
Comment 1 Kent Johnson CLA 2009-07-09 10:57:01 EDT
I could not reproduce this with the supplied code after setting 'unnecessary cast' to a warning.

Please attach a complete test project, with jdt.core.prefs file
Comment 2 Gunter Herrmann CLA 2009-07-09 11:14:24 EDT
(In reply to comment #0)
> Build ID: 20090621-0832
> 
> Steps To Reproduce:
> 1. Use code below
> 2. See different results
> 
> 
> 
> More information:
> char a = 65;
> String b = "" + a; // -> "A"
> String c = "" + (int) a; // -> "65", shows unnecessary cast
> 

Sorry I oversimplified the problem.
Now here the code that really did it:

String logText = "Some message ";
char firstChar = 65; // really getting something from a TCP/IP connection
logText += (int) firstChar;
Comment 3 Olivier Thomann CLA 2009-07-15 13:07:05 EDT
Created attachment 141671 [details]
Proposed fix

Kent, please review.
Comment 4 Olivier Thomann CLA 2009-07-15 13:08:59 EDT
The support was already there for binary expression. Therefore this is why the first test case in comment 0 didn't reproduce the problem.
The CompoundAssignment didn't get a specific treatment for unnecessary cast detection.
I'll release a disabled regression test in the CastTest.
Comment 5 Olivier Thomann CLA 2009-07-15 14:08:47 EDT
Added and released disabled test: org.eclipse.jdt.core.tests.compiler.regression.CastTest#_test046
Comment 6 Kent Johnson CLA 2009-07-22 11:49:04 EDT
Created attachment 142290 [details]
Proposed patch and testcase
Comment 7 Kent Johnson CLA 2009-07-22 13:06:41 EDT
Released in HEAD for 3.6M1
Comment 8 Srikanth Sankaran CLA 2009-08-03 06:55:27 EDT
Verified for 3.6M1 using build I20090802-2000