Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make BYTES_PER_* constants public in DataSize #34469

Open
albertus82 opened this issue Feb 22, 2025 · 2 comments
Open

Make BYTES_PER_* constants public in DataSize #34469

albertus82 opened this issue Feb 22, 2025 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@albertus82
Copy link

albertus82 commented Feb 22, 2025

At the moment the constants in org.springframework.util.unit.DataSize are private and cannot be used, for example, in annotations, so we have to bloat our code with 1024 everywhere.

Thanks.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 22, 2025
@sbrannen sbrannen changed the title Make BYTES_PER_* constants public in "org.springframework.util.unit.DataSize" Make BYTES_PER_* constants public in DataSize Feb 23, 2025
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Feb 23, 2025
@sbrannen sbrannen self-assigned this Feb 23, 2025
@sbrannen
Copy link
Member

Hi @albertus82,

Those constants in DataSize are intentionally private because they represent an internal implementation detail.

One normally uses one of the static parse(...) methods in DataSize to parse a data size string, and DataSize.parse(CharSequence, DataUnit) accepts a DataUnit in case you need to specify one.

Note that Spring Boot also has built-in support for converting application properties to DataSize values. See Converting Data Sizes for details.

At the moment the constants in org.springframework.util.unit.DataSize are private and cannot be used, for example, in annotations, so we have to bloat our code with 1024 everywhere.

Can you please provide concrete examples of how you are using DataSize?

For example, which annotations are you talking about?

Cheers,

Sam

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Feb 24, 2025
@albertus82
Copy link
Author

Hi @sbrannen,

Those constants in DataSize are intentionally private because they represent an internal implementation detail.

Commons IO contains something similar in its org.apache.commons.io.FileUtils class.

IMHO those constants are actually only some specific powers of two. You might reword them before making them public if their name represent an implementation detail (and maybe keep the private ones referencing the public ones).

For example, which annotations are you talking about?

e.g. @jakarta.validation.constraints.Size (on arrays).

Thanks.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

3 participants