Bug 97190 - Incorrect handling of large long values
Summary: Incorrect handling of large long values
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: All Windows 2000
: P3 blocker (vote)
Target Milestone: 3.1 RC2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-30 05:16 EDT by Emanuel Kupcik CLA
Modified: 2005-06-10 09:26 EDT (History)
1 user (show)

See Also:


Attachments
Proposed fix (4.25 KB, patch)
2005-05-30 10:26 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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