-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Enable Error Prone check: AnnotateFormatMethod #14933
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
Changes from all commits
c47502a
0a47b89
ea4c436
6479924
2764f59
d2036b3
3a09752
d1f0b9b
5b04fba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,7 +110,7 @@ public ListenableFuture<Void> execute( | |
| propertyMetadata.decode(objectValue); | ||
| } | ||
| catch (RuntimeException e) { | ||
| throw semanticException(INVALID_SESSION_PROPERTY, statement, e.getMessage()); | ||
| throw semanticException(INVALID_SESSION_PROPERTY, statement, "Invalid session property value '%s': %s", propertyName.toString(), e.getMessage()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SET SESSION is invoked for a particular session property.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other places that throw in this method do provide the property name, so I wanted to be consistent.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. awesome. can this be a separate change, or even separate PR? |
||
| } | ||
|
|
||
| stateMachine.addSetSessionProperties(propertyName.toString(), value); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ | |
| import com.google.common.collect.LinkedHashMultimap; | ||
| import com.google.common.collect.Multimap; | ||
| import com.google.common.collect.Streams; | ||
| import com.google.errorprone.annotations.FormatMethod; | ||
| import com.google.errorprone.annotations.FormatString; | ||
| import io.trino.Session; | ||
| import io.trino.execution.warnings.WarningCollector; | ||
| import io.trino.metadata.OperatorNotFoundException; | ||
|
|
@@ -758,7 +760,7 @@ protected Type visitDereferenceExpression(DereferenceExpression node, StackableA | |
| for (RowType.Field rowField : rowType.getFields()) { | ||
| if (fieldName.equalsIgnoreCase(rowField.getName().orElse(null))) { | ||
| if (foundFieldName) { | ||
| throw semanticException(AMBIGUOUS_NAME, field, "Ambiguous row field reference: " + fieldName); | ||
| throw semanticException(AMBIGUOUS_NAME, field, "Ambiguous row field reference: %s", fieldName); | ||
| } | ||
| foundFieldName = true; | ||
| rowFieldType = rowField.getType(); | ||
|
|
@@ -1243,7 +1245,7 @@ protected Type visitFunctionCall(FunctionCall node, StackableAstVisitorContext<C | |
| Expression expression = arguments.get(0); | ||
| Type expressionType = process(expression, context); | ||
| if (!(expressionType instanceof VarcharType)) { | ||
| throw semanticException(TYPE_MISMATCH, node, format("Expected expression of varchar, but '%s' has %s type", expression, expressionType.getDisplayName())); | ||
| throw semanticException(TYPE_MISMATCH, node, "Expected expression of varchar, but '%s' has %s type", expression, expressionType.getDisplayName()); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1273,7 +1275,7 @@ protected Type visitFunctionCall(FunctionCall node, StackableAstVisitorContext<C | |
| // After optimization, array constructor is rewritten to a function call. | ||
| // For historic reasons array constructor is allowed to have 254 arguments | ||
| if (node.getArguments().size() > 254) { | ||
| throw semanticException(TOO_MANY_ARGUMENTS, node, "Too many arguments for array constructor", function.getSignature().getName()); | ||
| throw semanticException(TOO_MANY_ARGUMENTS, node, "Too many arguments for array constructor: %s", function.getSignature().getName()); | ||
| } | ||
| } | ||
| else if (node.getArguments().size() > 127) { | ||
|
|
@@ -1491,7 +1493,7 @@ else if (frame.getType() == GROUPS) { | |
| } | ||
| } | ||
| else { | ||
| throw semanticException(NOT_SUPPORTED, frame, "Unsupported frame type: " + frame.getType()); | ||
| throw semanticException(NOT_SUPPORTED, frame, "Unsupported frame type: %s", frame.getType()); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -2421,7 +2423,7 @@ protected Type visitLambdaExpression(LambdaExpression node, StackableAstVisitorC | |
|
|
||
| if (types.size() != lambdaArguments.size()) { | ||
| throw semanticException(INVALID_PARAMETER_USAGE, node, | ||
| format("Expected a lambda that takes %s argument(s) but got %s", types.size(), lambdaArguments.size())); | ||
| "Expected a lambda that takes %s argument(s) but got %s", types.size(), lambdaArguments.size()); | ||
| } | ||
|
|
||
| ImmutableList.Builder<Field> fields = ImmutableList.builder(); | ||
|
|
@@ -2557,7 +2559,7 @@ public Type visitJsonValue(JsonValue node, StackableAstVisitorContext<Context> c | |
| !isDateTimeType(returnedType) || | ||
| returnedType.equals(INTERVAL_DAY_TIME) || | ||
| returnedType.equals(INTERVAL_YEAR_MONTH)) { | ||
| throw semanticException(TYPE_MISMATCH, node, "Invalid return type of function JSON_VALUE: " + node.getReturnedType().get()); | ||
| throw semanticException(TYPE_MISMATCH, node, "Invalid return type of function JSON_VALUE: %s", node.getReturnedType().get()); | ||
| } | ||
|
|
||
| JsonPathAnalysis pathAnalysis = jsonPathAnalyses.get(NodeRef.of(node)); | ||
|
|
@@ -2803,7 +2805,7 @@ private ResolvedFunction getInputFunction(Type type, JsonFormat format, Node nod | |
| if (isStringType(type)) { | ||
| yield QualifiedName.of(VARBINARY_TO_JSON); | ||
| } | ||
| throw semanticException(TYPE_MISMATCH, node, format("Cannot read input of type %s as JSON using formatting %s", type, format)); | ||
| throw semanticException(TYPE_MISMATCH, node, "Cannot read input of type %s as JSON using formatting %s", type, format); | ||
| } | ||
| case UTF8 -> QualifiedName.of(VARBINARY_UTF8_TO_JSON); | ||
| case UTF16 -> QualifiedName.of(VARBINARY_UTF16_TO_JSON); | ||
|
|
@@ -2828,23 +2830,23 @@ private ResolvedFunction getOutputFunction(Type type, JsonFormat format, Node no | |
| if (isStringType(type)) { | ||
| yield QualifiedName.of(JSON_TO_VARBINARY); | ||
| } | ||
| throw semanticException(TYPE_MISMATCH, node, format("Cannot output JSON value as %s using formatting %s", type, format)); | ||
| throw semanticException(TYPE_MISMATCH, node, "Cannot output JSON value as %s using formatting %s", type, format); | ||
| } | ||
| case UTF8 -> { | ||
| if (!VARBINARY.equals(type)) { | ||
| throw semanticException(TYPE_MISMATCH, node, format("Cannot output JSON value as %s using formatting %s", type, format)); | ||
| throw semanticException(TYPE_MISMATCH, node, "Cannot output JSON value as %s using formatting %s", type, format); | ||
| } | ||
| yield QualifiedName.of(JSON_TO_VARBINARY_UTF8); | ||
| } | ||
| case UTF16 -> { | ||
| if (!VARBINARY.equals(type)) { | ||
| throw semanticException(TYPE_MISMATCH, node, format("Cannot output JSON value as %s using formatting %s", type, format)); | ||
| throw semanticException(TYPE_MISMATCH, node, "Cannot output JSON value as %s using formatting %s", type, format); | ||
| } | ||
| yield QualifiedName.of(JSON_TO_VARBINARY_UTF16); | ||
| } | ||
| case UTF32 -> { | ||
| if (!VARBINARY.equals(type)) { | ||
| throw semanticException(TYPE_MISMATCH, node, format("Cannot output JSON value as %s using formatting %s", type, format)); | ||
| throw semanticException(TYPE_MISMATCH, node, "Cannot output JSON value as %s using formatting %s", type, format); | ||
| } | ||
| yield QualifiedName.of(JSON_TO_VARBINARY_UTF32); | ||
| } | ||
|
|
@@ -3137,7 +3139,8 @@ private void coerceType(StackableAstVisitorContext<Context> context, Expression | |
| coerceType(expression, actualType, expectedType, message); | ||
| } | ||
|
|
||
| private Type coerceToSingleType(StackableAstVisitorContext<Context> context, Node node, String message, Expression first, Expression second) | ||
| @FormatMethod | ||
|
ksobolew marked this conversation as resolved.
|
||
| private Type coerceToSingleType(StackableAstVisitorContext<Context> context, Node node, @FormatString String message, Expression first, Expression second) | ||
| { | ||
| Type firstType = UNKNOWN; | ||
| if (first != null) { | ||
|
|
@@ -3163,7 +3166,9 @@ private Type coerceToSingleType(StackableAstVisitorContext<Context> context, Nod | |
| return superType; | ||
| } | ||
|
|
||
| throw semanticException(TYPE_MISMATCH, node, message, firstType, secondType); | ||
| @SuppressWarnings("FormatStringAnnotation") // Error Prone wants the types of format arguments to be the same as where @FormatString is declared, but we need them to be different | ||
| TrinoException exception = semanticException(TYPE_MISMATCH, node, message, firstType, secondType); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new TrinoException?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know, I think it's valid, just hits some limitations of Java type system (or Error Prone's interpretation of it)
ksobolew marked this conversation as resolved.
|
||
| throw exception; | ||
| } | ||
|
|
||
| private Type coerceToSingleType(StackableAstVisitorContext<Context> context, String description, List<Expression> expressions) | ||
|
|
@@ -3184,12 +3189,12 @@ private Type coerceToSingleType(StackableAstVisitorContext<Context> context, Str | |
| for (Type type : types) { | ||
| Optional<Type> newSuperType = typeCoercion.getCommonSuperType(superType, type); | ||
| if (newSuperType.isEmpty()) { | ||
| throw semanticException(TYPE_MISMATCH, Iterables.get(typeExpressions.get(type), 0).getNode(), format( | ||
| throw semanticException(TYPE_MISMATCH, Iterables.get(typeExpressions.get(type), 0).getNode(), | ||
| "%s must be the same type or coercible to a common type. Cannot find common type between %s and %s, all types (without duplicates): %s", | ||
| description, | ||
| superType, | ||
| type, | ||
| typeExpressions.keySet())); | ||
| typeExpressions.keySet()); | ||
| } | ||
| superType = newSuperType.get(); | ||
| } | ||
|
|
@@ -3200,12 +3205,12 @@ private Type coerceToSingleType(StackableAstVisitorContext<Context> context, Str | |
|
|
||
| if (!type.equals(superType)) { | ||
| if (!typeCoercion.canCoerce(type, superType)) { | ||
| throw semanticException(TYPE_MISMATCH, Iterables.get(coercionCandidates, 0).getNode(), format( | ||
| throw semanticException(TYPE_MISMATCH, Iterables.get(coercionCandidates, 0).getNode(), | ||
| "%s must be the same type or coercible to a common type. Cannot find common type between %s and %s, all types (without duplicates): %s", | ||
| description, | ||
| superType, | ||
| type, | ||
| typeExpressions.keySet())); | ||
| typeExpressions.keySet()); | ||
| } | ||
| addOrReplaceExpressionsCoercion(coercionCandidates, type, superType); | ||
| } | ||
|
|
@@ -3559,7 +3564,7 @@ public static ExpressionAnalyzer createWithoutSubqueries( | |
| session, | ||
| TypeProvider.empty(), | ||
| parameters, | ||
| node -> semanticException(errorCode, node, message), | ||
| node -> semanticException(errorCode, node, "%s", message), | ||
| warningCollector, | ||
| isDescribe); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.