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

getBytes abbreviations exceed Long storage but no Exception is thrown #170

Closed
mslinn opened this issue Jun 14, 2014 · 3 comments · Fixed by #173
Closed

getBytes abbreviations exceed Long storage but no Exception is thrown #170

mslinn opened this issue Jun 14, 2014 · 3 comments · Fixed by #173

Comments

@mslinn
Copy link

mslinn commented Jun 14, 2014

Given the following in a configuration file (2 yottabytes):

bytes2=2Y

Attempting to read using getBytes returns zero and no exception is thrown:

myConfig.getBytes("bytes2")

I don't think it makes sense to support any abbreviations that result in Long overflow, yet the source code shows support for K (kilo), M (mega), G (giga), T(tera), P (peta), E (exa), Z (zetta) and Y (yotta). Most of these silently fail instead of throwing an exception like

new ArithmeticException("Long overflow");
@havocp
Copy link
Collaborator

havocp commented Jun 14, 2014

heh - I guess I just copied a list of units prefixes from somewhere and didn't think about it much. agreed it should throw.

@mslinn
Copy link
Author

mslinn commented Jun 15, 2014

Might be good to document all of the supported conversions: K (kilo), M (mega), G (giga), T(tera), P (peta), E (exa), Z (zetta) and Y (yotta). I saw Kibi..Yobi in the code, not sure how they would be notated in a config file so that might also be a good thing to document.

How about providing a version that supports arbitrarily large numbers by returning BigInteger instead of Long? Might call it getBytesAsBigInteger. I think the practical upper limit for BigInteger is something like (2^31)-1 digits (maximum length of a String), so no problem to store a YottaByte in BigInteger.

@havocp
Copy link
Collaborator

havocp commented Jun 23, 2014

The sizes are documented here: https://github.com/typesafehub/config/blob/master/HOCON.md#size-in-bytes-format

I agree it would be nice to have a BigInteger version. I added #172 for that to keep it separate from fixing the bug in the existing getBytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants