|
Quick Lists
|
|
Bug ID:
|
4949583
|
|
Votes
|
0
|
|
Synopsis
|
(cs) String(byte[]) constructor does not work on enormous byte arrays
|
|
Category
|
java:classes_nio
|
|
Reported Against
|
1.4.2
|
|
Release Fixed
|
|
|
State
|
11-Closed, duplicate of 4949631,
bug
|
|
Priority:
|
4-Low
|
|
Related Bugs
|
|
|
Submit Date
|
05-NOV-2003
|
|
Description
|
FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
FULL OS VERSION :
customer Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
String Constructor public String(byte[] bytes) produces a BufferOverflowEception in nio package when passing a large array of a certain size
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a new String customer passing an byte array of size 28664105.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The bug is reproducible for array sizes incremented by 4 (e.g. 28664105, 28664109, 28664113,...) It works fine for values between (e.g. 28664106, 28664107, 28664108).
ACTUAL -
The constructor throws a BufferoverflowException
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.nio.BufferOverflowException
at java.nio.charset.CoderResult.throwException(Unknown Source)
at java.lang.StringCoding$CharsetSD.decode(Unknown Source)
at java.lang.StringCoding.decode(Unknown Source)
at java.lang.StringCoding.decode(Unknown Source)
at java.lang.String.<init>(Unknown Source)
at java.lang.String.<init>(Unknown Source)
at TestBufferOverflow.main(TestBufferOverflow.java:18)
Exception in thread "main"
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TestBufferOverflow {
public static void main(String[] args) {
int maxNumber = 28664105;
byte[] ByteArray = new byte[maxNumber];
String newStr = new String (ByteArray);
}
}
---------- END SOURCE ----------
(Incident Review ID: 198982)
======================================================================
|
|
Work Around
|
N/A
|
|
Evaluation
|
True, but this is a fairly inefficient way to convert large byte sequences to
strings. You'd be better off using java.nio.charset.CharsetDecoder directly.
-- xxxxx@xxxxx 2003/11/15
This is clearly a duplicate of
4949631: String.getBytes() does not work on some strings larger than 16MB
which has been fixed for mustang.
xxxxx@xxxxx 2005-2-13 04:13:37 GMT
|
|
Comments
|
Submitted On 23-DEC-2003
solidmat
This look to me the same as bug # 4949631
Submitted On 27-DEC-2004
jryingst
I agree with solidmat; this is the same sort of problem as # 4949631. The offending code in this case is in java/lang/StringCoding.java, lines 176-8:
char[] decode(byte[] ba, int off, int len) {
int en = (int)(cd.maxCharsPerByte() * len);
char[] ca = new char[en];
Since maxCharsPerByte() returns a float, the result of multiplication is a float. Truncating to int results in losing some bits, which causes errors for some file sizes longer than 16 MB. A fix for this code would be simple:
char[] decode(byte[] ba, int off, int len) {
int en = (int)(cd.maxCharsPerByte() * len * 1.00001);
char[] ca = new char[en];
Of course, all other code that makes use of maxCharsPerByte() should probably be investigated also. But please don
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |