Skip to content

Conversation

@mpritham
Copy link
Contributor

@mpritham mpritham commented Mar 31, 2023

Before this PR

One of the refaster templates removed in this PR, replaced calls to InvocationTargetException.getTargetException with InvocationTargetException.getCause.

After this PR

==COMMIT_MSG==
Add check: Use InvocationTargetException.getCause instead of getTargetException.
==COMMIT_MSG==

@changelog-app
Copy link

changelog-app bot commented Mar 31, 2023

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Add check: Use InvocationTargetException.getCause instead of getTargetException.

Check the box to generate changelog(s)

  • Generate changelog entry

@mpritham mpritham self-assigned this Mar 31, 2023
link = "https://github.com/palantir/gradle-baseline#baseline-error-prone-checks",
linkType = BugPattern.LinkType.CUSTOM,
severity = SeverityLevel.SUGGESTION,
summary = "Use InvocationTargetException.getCause instead of InvocationTargetException.getTargetException")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's helpful to describe the reason rather than state rules. We can link+summarize the javadoc (which is actually a super interesting -- if you're into that sort of thing -- detail):

https://docs.oracle.com/en/java/javase/17/docs/api//java.base/java/lang/reflect/InvocationTargetException.html#getTargetException()

This method predates the general-purpose exception chaining facility. The Throwable.getCause() method is now the preferred means of obtaining this information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, will update.


I was deciding between adding more detail (like the API note from the javadoc) or being super concise. Decided on being concise because I thought a dev would just want the fastest resolution, and wouldn't think too much about the difference.

But you're right. Since we have a suggested fix anyway, they will know how to change their code, and we can use the summary to provide context. For times we don't have a suggested fix, maybe we'd favor conciseness over context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. I have also missed updating the README for this check, and the collections.size() == 0 check... will update.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't been updating hte readme lately -- imo we should codegen the list of checks and use the summary from annotations, but it's not high enough on my list to implement at the moment!

Copy link
Contributor Author

@mpritham mpritham Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: posted this before I read your latest comment.

Also, what are your thoughts on moving the giant list of checks out of the main README, and into a separate md file? Each check can be a heading, so we could link directly to the check in the link argument of the BugPattern, and add as much detail as we'd like.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool. Made a task in the backlog.

Pritham Marupaka added 2 commits March 31, 2023 16:44
Copy link
Contributor

@carterkozak carterkozak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

bulldozer-bot bot pushed a commit to palantir/witchcraft-api that referenced this pull request Apr 5, 2023
###### _excavator_ is a bot for automating changes across repositories.

Changes produced by the roomba/latest-baseline-oss check.

# Release Notes
## 5.4.0
| Type | Description | Link |
| ---- | ----------- | ---- |
| Feature | Add check: Use InvocationTargetException.getCause instead of getTargetException. | palantir/gradle-baseline#2541 |



To enable or disable this check, please contact the maintainers of Excavator.
This was referenced Apr 5, 2023
@mpritham mpritham changed the title Add check: Use InvoationTargetException.getCause instead of getTargetException Add check: Use InvocationTargetException.getCause instead of getTargetException Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants