Bug 222676 - [compiler] Compiler warning for accidental integer addition in string concatenation expression
Summary: [compiler] Compiler warning for accidental integer addition in string concate...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-13 17:39 EDT by Simon Archer CLA
Modified: 2008-08-22 11:42 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Archer CLA 2008-03-13 17:39:07 EDT
While trying to reduce our string footprint, we saw a case where the code:

  value = ":" + 9443 + "/service";

was replaced with:

  value = ':' + 9443 + "/service";  //$NON-NLS-1$

The result of these expressions are quite different.  The first sets value to ":9443/service", while the second sets value to "9501/service".  This happens because the colon character's integer value is added to 9443, before being concatenated with "/service".

It would be helpful to have a JDT compiler warning for the case where a character is being added to another character, or a number.  Ideally the compiler warning would detect only the case where a character is involved in integer addition, followed by concatenation with a string, but I understand if that is not feasible.

A common work around for such as problem is to do the following:

  value = "" + ':' + 9443 + "/service";  //$NON-NLS-1$ //$NON-NLS-2$

But this is not ideal, since it introduces yet another string, which also needs to be NON-NLS'd.
Comment 1 Philipe Mulet CLA 2008-03-14 07:10:10 EDT
We have one warning for use of char[] in String concatenation... this new one goes in the same direction... time permitting