Bug 282869 - [compiler] Unnecessary cast warning for cast from char to int
Summary: [compiler] Unnecessary cast warning for cast from char to int
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M1   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-08 11:02 EDT by Gunter Herrmann CLA
Modified: 2009-08-03 06:55 EDT (History)
2 users (show)

See Also:


Attachments
Proposed fix (1.66 KB, patch)
2009-07-15 13:07 EDT, Olivier Thomann CLA
no flags Details | Diff
Proposed patch and testcase (2.41 KB, patch)
2009-07-22 11:49 EDT, Kent Johnson CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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