8234377: new BitArray(0).toString() throws ArrayIndexOutOfBoundsException

Reviewed-by: mullan, wetmore
This commit is contained in:
Weijun Wang 2019-11-20 08:12:14 +08:00
parent f4a087036a
commit d5b423d17c
2 changed files with 42 additions and 1 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -241,6 +241,10 @@ public class BitArray {
* Returns a string representation of this BitArray.
*/
public String toString() {
if (length == 0) {
return "";
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
for (int i = 0; i < repn.length - 1; i++) {