|
Quick Lists
|
|
Bug ID:
|
4433326
|
|
Votes
|
0
|
|
Synopsis
|
VM doesn't throw required NegativeArraySizeException
|
|
Category
|
java:runtime
|
|
Reported Against
|
1.3
|
|
Release Fixed
|
1.4.2(mantis)
|
|
State
|
10-Fix Delivered,
Verified,
bug
|
|
Priority:
|
4-Low
|
|
Related Bugs
|
4433476
,
4723534
,
4735980
,
6392733
,
6392741
,
4767373
|
|
Submit Date
|
03-APR-2001
|
|
Description
|
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
According to JLS 15.10.1, and to JVMS 6, multianewarray, if ANY dimension
expression is negative in an array creation expression, then a
NegativeArraySizeException MUST be thrown. However, this program executes
without problems:
class Foo {
public static void main(String[] args) {
try {
Object o = new int[0][-1];
System.out.println("Oops - shouldn't get here");
} catch(NegativeArraySizeException nase) {
System.out.println("Correct behavior");
}
}
}
(Review ID: 119887)
======================================================================
|
|
Work Around
|
Manually check for a negative dimension when a previous one was 0.
======================================================================
|
|
Evaluation
|
The first array element is zero size therfor we silently discontunue evaluating next array element size. This will not be fixed. This is not a bug. If user puts [1][-1] an exception will be thrown as desired and spec'd.
Closing as a will not fix.
xxxxx@xxxxx 2002-04-08
FWIW, this contradicts the JVMS and the JLS. So it is a bug.
I doubt if it makes a big difference to anyone either way, but the KVM
behaves differently (and for once, they're right).
xxxxx@xxxxx 2002-07-31
|
|
Comments
|
Submitted On 10-APR-2002
eblake
This is a VM bug, and you should not have closed it. The
specs of JVMS 6 specifically say that all dimensions must be
non-negative; and do not allow you to short-circuit
evaluation just because a 0-size dimension was encountered.
Besides, when using reflection, the similar construct WILL
throw the appropriate NegativeArraySizeException:
java.lang.reflect.Array.newInstance(int.class, new int[]
{0,-1});
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |