ADDITIONAL SYSTEM INFORMATION : openjdk version "13" 2019-09-17 OpenJDK Runtime Environment (build 13+33-Ubuntu-1) A DESCRIPTION OF THE PROBLEM : I noticed that Integers (or probably also other data types) can be assigned with unsigned hex, octal or binary literals, but it is still possible to add a minus sign. I think this is not defined in the language specification and there are two issues that can occur: 1. If a minus sign is applied to an already negative literal, there is an implicit double negation, which can be really confusing. 2. Negating the most negative number should not be allowed since it would produce 2,147,483,648, which is bigger than the maximum positive Integer. However, in this case the negation just does nothing or I assume an overflow occurs that produces the same number. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : int a = 0x8000_0001; System.out.println("a: "+a); // -2,147,483,647 int b = -0x8000_0001; // this implicit double negation produces the positive value 0x7FFF_FFFF System.out.println("b: "+b ); // 2,147,483,647 int c = 0x8000_0000; System.out.println("c: "+c); // -2,147,483,648 int d = -0x8000_0000; //Negating the most negative integer should not be allowed, but it just does nothing. System.out.println("d: "+d); // -2,147,483,648 FREQUENCY : always
|