Community
Participate
Working Groups
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
Move to JDT/UI
The example is wrong. Should be: static final long two = 2; long much = two * Integer.MAX_VALUE; Can reproduce using I20090217-2200.
(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...
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.
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.
Created attachment 126451 [details] Fix
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;').