Community
Participate
Working Groups
It seems like the compiler doesn't handle invalid long values correctly. When a long value is longer than Long.MAX_VALUE it doesn't complain about it and compiles it. When you run the code you get invalid results of course. System.out.println(Long.MAX_VALUE); System.out.println(23092395825689123986L); is compiled and produces this output 9223372036854775807 4645651751979572370
Indeed we don't catch this case. Both javac and jikes are reporting a long value out of range. Philippe, this would be a candidate for RC2.
Created attachment 21961 [details] Proposed fix With this patch, the test case is properly rejected.
+1 for RC2
Corresponding test case: public class X { public static void main(String[] args) { System.out.println(-9223372036854775809L); // KO System.out.println(9223372036854775809L); // KO System.out.println(9223372036854775808L); // KO System.out.println(23092395825689123986L); // KO System.out.println(-9223372036854775808L); // OK System.out.println(9223372036854775807L); // OK System.out.println(2309239582568912398L); // OK } }
Fixed and released in HEAD. Regression test added in org.eclipse.jdt.core.tests.compiler.regression.ConstantTest.test013.
Changes only in org.eclipse.jdt.internal.compiler.ast.LongLiteral.
Verified in N20050606-0010 + JDT/Core HEAD.
Verified for 3.1 RC2 using build I20050610-0010