Why "Numeric overflow in expression" warning occurs

Manish Patel picture Manish Patel · Feb 8, 2016 · Viewed 8.3k times · Source

Using intellij 15.0.3 + Java 8u65...

lower = System.currentTimeMillis();
long upper = lower + 31536000000L; //add a year-ish

Works fine. But if I do:

lower = System.currentTimeMillis();
long upper = lower + (1000L*60*60*24*365); 

Intellij now gives a warning "Numeric overflow in expression". I'd understand if this were in fact true, and it was consistently warning over both expressions, but it's not.

Anyone know why the 2nd expression generates the warning? I'd rather have the breakdown this way than a number because it's easier for other devs on the project to understand what it's doing (though I suppose I could comment). Code still compiles obviously but I find warnings in my builds like an itch that I can't scratch.

EDIT Thanks for responses... I think this is just a caching issue in Intellij... If I know copy/paste the above I don't get the warning. If I try to edit it after the paste 1 or 2 times out of 10 I get the warning popping in.

Answer

Steve Bosman picture Steve Bosman · Feb 8, 2016

I have just tried this on my machine. Same version of intellij, but a slightly newer java 1.8.0_66. If I copy paste your code and assume lower is a long, I don't get the warning. If I remove the "L" I get the warning (obviously). If I put the "L" back the warning doesn't go away. If I close and reopen IntelliJ the warning goes away.

Added to the issue tracker: IDEA-151378