Inspection?: overflowed Integer constant for long field
Hi, I just had a bug caused by this code:
private static final long CHECKSUM_INIT = 0xffff0000;
the bug was that the initial value was -65536, because 0xffff0000 is an
integer constant, not a float constant.
I feel sure that there was or is an inspection for this, but I couldn't
find it. Does anyone else know what this inspection is called, or did I
make it up?
Please sign in to leave a comment.
"Implicit numeric conversion" would have warned here.
Bas
Keith Lea wrote:
Is there no inspection to determine when an integer constant has overflowed?
Bas Leijdekkers wrote:
>> Hi, I just had a bug caused by this code:
>>
>> private static final long CHECKSUM_INIT = 0xffff0000;
>>
>> the bug was that the initial value was -65536, because 0xffff0000 is
>> an integer constant, not a float constant.
>>
>> I feel sure that there was or is an inspection for this, but I
>> couldn't find it. Does anyone else know what this inspection is
>> called, or did I make it up?
It's only an issue with hex, right? Otherwise it's a compile-time error. Considering that hex is so often used for bitmaps rather than math, I'd imagine this would have more false positives than not.
--Dave Griffith
I don't understand how it could ever be a false positive. Don't you
think it's always a bug?
Dave Griffith wrote:
If I just see 0xffff0000 with no context, I most likely think that's meant to be a bit mask. The fact that it represents a negative integer would, if reported, be a false positive. If it's a question of the fact that you've got an integer constant for a long field, there's already an inspection for that, "Implicit numeric conversion".
It's entirely possible I'm missing the issue here.
--Dave Griffith
I see now, I was wrong, I was thinking because 0xffff0000 overflows,
it's not a valid integer, or something like that. Maybe an inspection
"hex value will be negative" would be cool. I'll think about it.
Dave Griffith wrote: