RFR: 8372301: Improve error message for jimage command line tool regarding version mismatch
David Beaumont
duke at openjdk.org
Fri Nov 21 17:06:45 UTC 2025
On Fri, 21 Nov 2025 16:43:00 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> Adds a semantic reason for failure which can be optionally interrogated by calling code.
>> Use the 'Reason.BAD_VERSION' value to trigger a different translated error message from the JImageTask.
>>
>> I would consider moving the error message string into the Reason enum to simplify the code triggering the error and avoid message string duplication, but it's not straightforward due to the need to supply the version numbers.
>>
>> We can use this approach to provide translated messages for all the distinct failure reasons if needed.
>
> src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java line 469:
>
>> 467: * semantic reason for failure and allow better user-facing error messages.
>> 468: */
>> 469: public final static class ImageError extends IOException {
>
> Exception names ending in "Error" are usually fatal to the VM, this seems more like a normal exception.
> Generally, we don't add single purpose exceptions, they are little used and just contribute to bloat.
How else do you think it best to reliably detect the semantic difference for the JImageTool while keeping the non-tool usage as it was? This new exception has a vital role for doing that which, if it, or something like it, didn't exist would be done via unsatisfying heuristics on the debug message string.
An alternate version would be to refactor things to have an "open()" method that returns a failure-reason type of some sort. And this approach would pave the way to properly translated strings for all the failure modes (though the others aren't actionable in as distinct a way).
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28456#discussion_r2550413423
More information about the core-libs-dev
mailing list