-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.1.4
-
sparc
-
solaris_2.6
allan.jacobs@Eng 1997-10-30
javac accepts decimal int literals greater than 2147483648.
javac accepts decimal int literals less than -2147483648.
javac accepts decimal int literals greater than 9223372036854775808L.
javac accepts decimal int literals less than -9223372036854775808L.
The language specification in section 3.10.1 says that "a compile-time
error occurs if a decimal literal of type int is larger than 2147483648
(2^31), or if the literal 2147483648 appears anywhere other than as
the operand of the unary - operator, or if a hexadecimal or octal int
literal does not fit in 32 bits."
The language specification in section 3.10.1 says that "a compile-time
error occurs if a decimal literal of type long is larger than
9223372036854775808L (2^63), or if the literal 9223372036854775808L appears
anywhere other than as the operand of the unary - operator, or if a
hexadecimal or octal long literal does not fit in 64 bits."
algol% cat X.java
class X{
public static void main( String[] argv ) {
int i0 = 2147483647;
int i1 = -2147483648;
int i2 = 2147483648;
int i3 = 10000000000;
int i4 = -10000000000;
long l0 = 9223372036854775807L;
long l1 = -9223372036854775808L;
long l2 = 9223372036854775808L;
long l3 = 10000000000000000000L;
long l4 = -10000000000000000000L;
}
}
algol% javac -d . X.java
X.java:6: Numeric overflow.
int i2 = 2147483648;
^
X.java:11: Numeric overflow.
long l2 = 9223372036854775808L;
^
X.java:12: Numeric overflow.
long l3 = 10000000000000000000L;
^
X.java:13: Numeric overflow.
long l4 = -10000000000000000000L;
^
4 errors
algol% fastjavac -d . X.java
Java WorkShop 2.0 fastjavac 1.0 Copyright (c) 1997 Sun Microsystems, Inc.
X.java:6: Literal overflows capacity of int type
int i2 = 2147483648;
^
X.java:7: Literal overflows capacity of int type
int i3 = 10000000000;
^
X.java:8: Literal overflows capacity of int type
int i4 = -10000000000;
^
X.java:11: Literal overflows capacity of long type
long l2 = 9223372036854775808L;
^
X.java:11: Literal overflows capacity of long type
long l2 = 9223372036854775808L;
^
X.java:12: Literal overflows capacity of long type
long l3 = 10000000000000000000L;
^
X.java:13: Literal overflows capacity of long type
long l4 = -10000000000000000000L;
^
7 errors
- duplicates
-
JDK-4035346 integer declaration to long does not complain
- Closed