Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow JavaTemplate to throw new Exception #4260

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

timtebeek
Copy link
Contributor

What's changed?

Update BlockStatementTemplateGenerator to separately handle J.MethodInvocation, and not produce an assignment when the methodInvocation has a void return type. This prevents a compiler error for such templates. Additionally wrap any generated template for J.MethodInvocation in a block (class Template {{ ... }}, as opposed to class Template { ... }) to allow for throwing exceptions.

What's your motivation?

Broke the recipes generated for this one, which contained final JavaTemplate after = JavaTemplate.builder("throw new AssertionError();").build();.
https://github.com/PicnicSupermarket/error-prone-support/blob/d81fe19836db9f0001fb9c01370a3b808c46b440/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TestNGToAssertJRules.java#L156-L167

Have you considered any alternatives or workarounds?

Could have nested the generated template in the j instanceof Expression conditional just below it, but this seemed cleaner.

Any additional context

As part of the work done towards

@timtebeek timtebeek added bug Something isn't working enhancement New feature or request labels Jun 15, 2024
@timtebeek timtebeek requested a review from knutwannheden June 15, 2024 20:44
@timtebeek timtebeek self-assigned this Jun 15, 2024
@timtebeek timtebeek merged commit 0e35478 into main Jun 17, 2024
2 checks passed
@timtebeek timtebeek deleted the allow-JavaTemplate-to-throw-exceptions branch June 17, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants