Inspections: The value changed at pos++ at line 28 is never used.

I see this inspection pop up for the following code:

private static int getIntFromByte(byte[] bytes) {
int returnNumber = 0;
int pos = 0;
returnNumber = byteToInt(bytes[pos+]) << 24;
returnNumber = byteToInt(bytes[pos+]) << 16;
returnNumber = byteToInt(bytes[pos+]) << 8;
returnNumber = byteToInt(bytes[pos+]) << 0;
return returnNumber;
}


Surely the repeated references to pos++ -are- usages?

2 comments
Comment actions Permalink

Mark Derricutt wrote:

I see this inspection pop up for the following code:

private static int getIntFromByte(byte[] bytes) {
int returnNumber = 0;
int pos = 0;
returnNumber = byteToInt(bytes[pos+]) << 24;
returnNumber = byteToInt(bytes[pos+]) << 16;
returnNumber = byteToInt(bytes[pos+]) << 8;
returnNumber = byteToInt(bytes[pos+]) << 0;
return returnNumber;
}


Surely the repeated references to pos++ -are- usages?


You are correct apart from the last one.
In the last one, pos is used, then incremented and thrown away, which is
why the inspection is correct.

Note: I assume that line 28 is:
returnNumber = byteToInt(bytes[pos+]) << 0;

Regards,
Amnon

0
Comment actions Permalink

And don't let us start this discussion again. It has been discussed many
times now, and everything which can be said regarding this topic has
already been said. Search the forum and you'll find hundreds of comments
about it.

Amnon I. Govrin wrote:

Mark Derricutt wrote:

>> I see this inspection pop up for the following code:
>>
>> private static int getIntFromByte(byte[] bytes) {
>> int returnNumber = 0;
>> int pos = 0;
>> returnNumber = byteToInt(bytes[pos+]) << 24;
>> returnNumber = byteToInt(bytes[pos+]) << 16;
>> returnNumber = byteToInt(bytes[pos+]) << 8;
>> returnNumber = byteToInt(bytes[pos+]) << 0;
>> return returnNumber;
>> }
>>
>>
>> Surely the repeated references to pos++ -are- usages?


You are correct apart from the last one.
In the last one, pos is used, then incremented and thrown away, which is
why the inspection is correct.

Note: I assume that line 28 is:
returnNumber = byteToInt(bytes[pos+]) << 0;

Regards,
Amnon


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0

Please sign in to leave a comment.