RFR: JDK-8309550: jdk.jfr.internal.Utils::formatDataAmount method should gracefully handle amounts equal to Long.MIN_VALUE [v2]
Erik Gahlin
egahlin at openjdk.org
Tue Jun 13 15:29:58 UTC 2023
On Tue, 13 Jun 2023 13:43:24 GMT, Erik Gahlin <egahlin at openjdk.org> wrote:
>> Frederic Thevenet has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Put brackets around the ? condition
>
> JFR uses Long.MIN_VALUE to indicate that a value is not available or not applicable ("N/A"). I think a correct fix should be to check for that before calling the method, or do it in the method.
> Thanks for the clarification, @egahlin
>
> IMHO, putting the responsibility of checking for Long.MIN_VALUE on the caller is taking the risk to run in the same issue in the future, so having `formatDataAmount` return the string `"N/A"` in such a case seems the better solution.
>
> If we deem it preferable to let callers handle this verification, then I believe we should still consider keeping this patch in - which is at least _technically correct_ and avoid a seemingly unrelated exception being thrown - or at least throw a more helpful IllegalArgumentException to avoid further confusion.
>
> What do you think?
The change is an improvement to java.lang.StringIndexOutOfBoundsException. Having the N/A check in the formatDataAmount method is probably best, but I haven't looked at all call sites. Maybe some Long.MIN_VALUE checks can be removed.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14341#issuecomment-1589541438
More information about the hotspot-jfr-dev
mailing list