Bug 238921 - [compiler] please add compiler warning: >>>= has counter-intuitional semantics for byte/short
Summary: [compiler] please add compiler warning: >>>= has counter-intuitional semantic...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-29 21:08 EDT by Sven Köhler CLA
Modified: 2008-07-02 07:54 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Köhler CLA 2008-06-29 21:08:21 EDT
Build ID: I20080617-2000

Consider the following source code:

	byte b1 = -3;
	byte b2 = -3;		
	b1 >>>= 1;
	b2 >>>= 25;
	System.out.println(b1);
	System.out.println(b2);

The output is:

	-2
	127


Actually, i'd expect >>>=1 to shift the data right, filling the left side with zeros therefore resulting in a positive number. But this doesn't work for the data types byte and short. The semantics of "b1 >>>= 1" is:

	b1 = (byte)( ((int)b1) >>> 1 )

I would say, this is VERY counter-intuitional.
The b2 >>>= 25 explicitly exploits the idea, since it shift by 25 bits, which results in the desired 8 bits.


So you have some nice compiler-warnings concerning semantics:
- accidental assignments
- using char[] in string concat
- etc.

So this might be another candidate.


Please add a compiler-warning if the >>>= operator is applied to byte or short values. Most people will not be aware, what they did there. (And an explanation is hard to find)