summaryrefslogtreecommitdiff
path: root/compilerCommon
diff options
context:
space:
mode:
authorYigit Boyar <yboyar@google.com>2021-04-12 16:25:26 -0700
committerYigit Boyar <yboyar@google.com>2021-04-13 15:03:30 +0000
commit881cdfbec14220f48b22312a815e34d449a2ff6c (patch)
tree6dfcb2aba52f69c97b7e015912f8a39f8a3dd2f8 /compilerCommon
parent7a994d028206190eaff72ccfd894ec254003cdc5 (diff)
downloaddata-binding-881cdfbec14220f48b22312a815e34d449a2ff6c.tar.gz
Avoid StackOverflow in code generation by dispatching a real error
When a callback expression returns void but it is expected to return a value, data binding goes into an infinite loop because it tries to find a value but cannot because void cannot be a assigned to a variable. The right fix here would be to check for assignability and throw a better error message but it might break some existing apps because i don't trust our assignability checks. Instead, this CL covers the void return type case to fix this one bug without taking a bigger risk. Fixes: 123260053 Test: SimpleCompilationTest.testCallbackReturnTypeMismatch Change-Id: Ie9b4d03e0e2d818a0613f4cdefc470e1f7221b27
Diffstat (limited to 'compilerCommon')
-rw-r--r--compilerCommon/src/main/java/android/databinding/tool/processing/ErrorMessages.java12
1 files changed, 12 insertions, 0 deletions
diff --git a/compilerCommon/src/main/java/android/databinding/tool/processing/ErrorMessages.java b/compilerCommon/src/main/java/android/databinding/tool/processing/ErrorMessages.java
index 25e3a852..93d6f92c 100644
--- a/compilerCommon/src/main/java/android/databinding/tool/processing/ErrorMessages.java
+++ b/compilerCommon/src/main/java/android/databinding/tool/processing/ErrorMessages.java
@@ -83,6 +83,18 @@ public class ErrorMessages {
"'%s::%s' accepts %d parameter(s), but the assigned expression uses %d parameter(s). The expression should have no " +
"parameters or an equal number of parameters.";
+ public static String callbackReturnTypeMismatchError(
+ String methodName,
+ String expectedReturnType,
+ String expression,
+ String expressionReturnType
+ ) {
+ return "Invalid return type in callback.\n"
+ + "Callback method `" + methodName + "` is expected to return `"
+ + expectedReturnType + "` but expression `"
+ + expression + "` returns `" + expressionReturnType + "`";
+ }
+
public static final String DUPLICATE_CALLBACK_ARGUMENT =
"Callback parameter '%s' is not unique";