Skip to content

Annotate a few exceptions. - #152

Open
cpovirk wants to merge 1 commit into
mainfrom
ioniolangex
Open

Annotate a few exceptions.#152
cpovirk wants to merge 1 commit into
mainfrom
ioniolangex

Conversation

@cpovirk

@cpovirk cpovirk commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

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.

  • 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 Consider annotating InvocationTargetException, ExecutionException, and CompletionException causes as non-nullable jspecify#490.

(prompted by google/xplat@7ab1a2c)

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants