Skip to content

Commit b24bccf

Browse files
committed
Return EMPTY instance if allocated with 0 length
1 parent bcfcaba commit b24bccf

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/java/at/favre/lib/bytes/Bytes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ public static Bytes allocate(int length) {
8686
* @return new instance
8787
*/
8888
public static Bytes allocate(int length, byte defaultValue) {
89+
if (length == 0) return EMPTY;
8990
byte[] array = new byte[length];
90-
if (defaultValue != 0 && length > 0) {
91+
if (defaultValue != 0) {
9192
Arrays.fill(array, defaultValue);
9293
}
9394
return wrap(array);

0 commit comments

Comments
 (0)