Community
Participate
Working Groups
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
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
(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;
Created attachment 141671 [details] Proposed fix Kent, please review.
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.
Added and released disabled test: org.eclipse.jdt.core.tests.compiler.regression.CastTest#_test046
Created attachment 142290 [details] Proposed patch and testcase
Released in HEAD for 3.6M1
Verified for 3.6M1 using build I20090802-2000