Skip to content

[Enhancement] Replace byte array zeroing loop with Arrays.fill and specify charset in String construction #9460

Open
@cat-and-tomato

Description

@cat-and-tomato

Before Creating the Enhancement Request

  • I have confirmed that this should be classified as an enhancement rather than a bug/feature.

Summary

Enhancement Description

This issue proposes two small improvements to increase code readability, maintainability, and compliance with Java best practices.

Code Changes

// 1. Use Arrays.fill to clear byte array

// Before:
for (int i = 0; i < bytes.length; i++) {
    bytes[i] = (byte) 0x00;
}

// After:
Arrays.fill(bytes, (byte) 0x00);

// ------------------------------------------------------

// 2. Explicitly specify charset when constructing String

// Before:
String s = new String(bos.toByteArray());

// After:
String s = new String(bos.toByteArray(), StandardCharsets.UTF_8);


### Motivation

These changes improve code readability and robustness with no functional impact. They follow standard Java best practices

### Describe the Solution You'd Like

Just like what was mentioned above

### Describe Alternatives You've Considered

Just like what was mentioned above

### Additional Context

_No response_

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions