Bug 97190

Summary: Incorrect handling of large long values
Product: [Eclipse Project] JDT Reporter: Emanuel Kupcik <ekupcik>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: CLOSED FIXED QA Contact:
Severity: blocker    
Priority: P3 CC: philippe_mulet
Version: 3.1   
Target Milestone: 3.1 RC2   
Hardware: All   
OS: Windows 2000   
Whiteboard:
Attachments:
Description Flags
Proposed fix none

Description Emanuel Kupcik CLA 2005-05-30 05:16:34 EDT
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
Comment 1 Olivier Thomann CLA 2005-05-30 09:29:54 EDT
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.
Comment 2 Olivier Thomann CLA 2005-05-30 10:26:27 EDT
Created attachment 21961 [details]
Proposed fix

With this patch, the test case is properly rejected.
Comment 3 Philipe Mulet CLA 2005-05-30 10:55:06 EDT
+1 for RC2
Comment 4 Olivier Thomann CLA 2005-05-30 11:01:23 EDT
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
	}
}
Comment 5 Olivier Thomann CLA 2005-05-30 13:17:09 EDT
Fixed and released in HEAD.
Regression test added in
org.eclipse.jdt.core.tests.compiler.regression.ConstantTest.test013.
Comment 6 Olivier Thomann CLA 2005-05-30 13:18:21 EDT
Changes only in org.eclipse.jdt.internal.compiler.ast.LongLiteral.
Comment 7 Olivier Thomann CLA 2005-06-06 20:31:21 EDT
Verified in N20050606-0010 + JDT/Core HEAD.
Comment 8 David Audel CLA 2005-06-10 09:26:19 EDT
Verified for 3.1 RC2 using build I20050610-0010