Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 265448 - [inline] Inlining long constants may change semantics
Summary: [inline] Inlining long constants may change semantics
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5 M6   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-19 08:01 EST by Martin von Zweigbergk CLA
Modified: 2009-02-23 08:35 EST (History)
2 users (show)

See Also:


Attachments
Fix (17.39 KB, patch)
2009-02-23 08:31 EST, Markus Keller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin von Zweigbergk CLA 2009-02-19 08:01:02 EST
If the variable "two" in the snippet below is inlined using "Refactor -> Inline...", the result will change from 2^32-2 to -2. The 2 should be suffixed with 'L' when inlined. This type of bug (in the code below, not the JDT bug) is quite tricky to spot.

long two = 2;
long much = two * Integer.MAX_VALUE;


JDT Version:

Eclipse Java Development Tools

Version: 3.4.0.v20080603-2000-7o7tEAXEFpPqqoXxgaBhhhq
Build id: I20080617-2000
Comment 1 Frederic Fusier CLA 2009-02-19 08:43:56 EST
Move to JDT/UI
Comment 2 Dani Megert CLA 2009-02-19 09:48:22 EST
The example is wrong. Should be:

static final long two = 2;
long much = two * Integer.MAX_VALUE;


Can reproduce using I20090217-2200.
Comment 3 Martin von Zweigbergk CLA 2009-02-20 02:55:41 EST
(In reply to comment #2)
> The example is wrong. Should be:
> 
> static final long two = 2;
> long much = two * Integer.MAX_VALUE;
> 
> 
> Can reproduce using I20090217-2200.
> 

I meant "constant" in the sense of a numerical constant ("2" in this case), rather than in the Java sense (static final). I assume the solution would fix the problem in both versions of the example anyway...
Comment 4 Dani Megert CLA 2009-02-20 03:00:20 EST
Right. The example is not wrong if pasted inside a method. I pasted them as fields and there "Inline" is only available for static final.
Comment 5 Markus Keller CLA 2009-02-23 08:12:32 EST
If you use the code from comment 0 inside a method (i.e. you inline the local variable 'two'), this is a dup of bug 185214.

Will use this bug to fix the same problem for inline constant.
Comment 6 Markus Keller CLA 2009-02-23 08:31:56 EST
Created attachment 126451 [details]
Fix
Comment 7 Markus Keller CLA 2009-02-23 08:35:42 EST
Fixed in HEAD.

We cast to long instead of adding the 'L' suffix to the constant. This makes the implicit conversion explicit and also works in more complex cases (e.g. inline 'long two = 1 + 1;').