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

Message format checks use instanceof rather than catching #821

Merged
merged 2 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
return Description.NO_MATCH;
}

String message;
try {
message = (String) ((LiteralTree) messageArg).getValue();
} catch (ClassCastException exception) {
if (!(messageArg instanceof LiteralTree)) {
return Description.NO_MATCH;
}
LiteralTree literalTreeMessageArg = (LiteralTree) messageArg;

Object value = literalTreeMessageArg.getValue();

if (!(value instanceof String)) {
return Description.NO_MATCH;
}
String message = (String) value;

return matchMessageFormat(tree, message, state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,17 @@ public Description matchNewClass(NewClassTree tree, VisitorState state) {
return Description.NO_MATCH;
}

String message;
try {
message = (String) ((LiteralTree) messageArg).getValue();
} catch (ClassCastException exception) {
if (!(messageArg instanceof LiteralTree)) {
return Description.NO_MATCH;
}
LiteralTree literalTreeMessageArg = (LiteralTree) messageArg;

Object value = literalTreeMessageArg.getValue();

if (!(value instanceof String)) {
return Description.NO_MATCH;
}
String message = (String) value;

if (message.contains("{}")) {
return buildDescription(tree)
Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-821.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Message format checks use instanceof rather than catching
links:
- https://github.com/palantir/gradle-baseline/pull/821