Annotate a few exceptions. - #152
Open
cpovirk wants to merge 1 commit into
Open
Conversation
A couple notes: - `UnsupportedEncodingException`: I didn't look much to see how likely a null argument was. But given that the class provides a no-arg constructor, which results in a null message, I saw no particular reason to restrict callers from passing a null message to the one-arg constructor, especially when most exception types support that. - `MatchException`: The docs are clearer about allowing a null _cause_, but `javac` does [generate calls that pass `null` for both the cause and the message](https://github.com/openjdk/jdk/blob/5121008600e61fc931c486504aad4fecbd46f587/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java#L3835). - I ignored `CoderMalfunctionError` because I was uncertain whether to give it a nullable cause or not. - I generally err on the side of nullable, as in `UnsupportedEncodingException` above. - I see one test in Google's codebase that passes `null`, but doesn't care what it passes, and it could easily be changed not to pass somethign else. - I see a test in some version of Apache Harmony that passes `null` and verifies that it works. - But "clearly" it's "supposed" to have a non-null cause, similar to a type like `InvocationTargetException` or (possibly to a lesser extent, sadly) `ExecutionException`. For discussion of those types, see jspecify/jspecify#490. (prompted by google/xplat@7ab1a2c)
msridhar
approved these changes
Aug 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A couple notes:
UnsupportedEncodingException: I didn't look much to see how likely a null argument was. But given that the class provides a no-arg constructor, which results in a null message, I saw no particular reason to restrict callers from passing a null message to the one-arg constructor, especially when most exception types support that.MatchException: The docs are clearer about allowing a null cause, butjavacdoes generate calls that passnullfor both the cause and the message.I ignored
CoderMalfunctionErrorbecause I was uncertain whether to give it a nullable cause or not.I generally err on the side of nullable, as in
UnsupportedEncodingExceptionabove.I see one test in Google's codebase that passes
null, but doesn't care what it passes, and it could easily be changed not to pass somethign else.I see a test in some version of Apache Harmony that passes
nulland verifies that it works.But "clearly" it's "supposed" to have a non-null cause, similar to a type like
InvocationTargetExceptionor (possibly to a lesser extent, sadly)ExecutionException. For discussion of those types, see Consider annotatingInvocationTargetException,ExecutionException, andCompletionExceptioncauses as non-nullable jspecify#490.(prompted by google/xplat@7ab1a2c)