Skip to content
Snippets Groups Projects
Commit 406dc08c authored by Cole Faust's avatar Cole Faust Committed by Kevin Liu
Browse files

Fix crash in RequiresPermissionChecker.java

Bug: 265320139
Test: atest --host error_prone_android_framework_test
Change-Id: Ia46d5e7cab4d39888c4975ded18c59d5eb918ffa
parent d648d084
No related branches found
No related tags found
No related merge requests found
......@@ -412,11 +412,11 @@ public final class RequiresPermissionChecker extends BugChecker
private static ParsedRequiresPermission parseRequiresPermissionRecursively(
MethodInvocationTree tree, VisitorState state) {
if (ENFORCE_VIA_CONTEXT.matches(tree, state)) {
if (ENFORCE_VIA_CONTEXT.matches(tree, state) && tree.getArguments().size() > 0) {
final ParsedRequiresPermission res = new ParsedRequiresPermission();
res.allOf.add(String.valueOf(ASTHelpers.constValue(tree.getArguments().get(0))));
return res;
} else if (ENFORCE_VIA_CHECKER.matches(tree, state)) {
} else if (ENFORCE_VIA_CHECKER.matches(tree, state) && tree.getArguments().size() > 1) {
final ParsedRequiresPermission res = new ParsedRequiresPermission();
res.allOf.add(String.valueOf(ASTHelpers.constValue(tree.getArguments().get(1))));
return res;
......
......@@ -415,4 +415,27 @@ public class RequiresPermissionCheckerTest {
"}")
.doTest();
}
@Test
public void testInvalidFunctions() {
compilationHelper
.addSourceFile("/android/annotation/RequiresPermission.java")
.addSourceFile("/android/annotation/SuppressLint.java")
.addSourceFile("/android/content/Context.java")
.addSourceLines("Example.java",
"import android.annotation.RequiresPermission;",
"import android.annotation.SuppressLint;",
"import android.content.Context;",
"class Foo extends Context {",
" private static final String RED = \"red\";",
" public void checkPermission() {",
" }",
" @RequiresPermission(RED)",
" // BUG: Diagnostic contains:",
" public void exampleScoped(Context context) {",
" checkPermission();",
" }",
"}")
.doTest();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment