From b6b12dfee94777729f557ea87d703c0c539d75f0 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sat, 26 Sep 2020 14:15:23 -0700 Subject: [PATCH] Test case for issue #3281 --- checker/tests/regex/Issue3281.java | 66 +++++++++++++++++++ .../dataflow/cfg/CFGBuilder.java | 3 - 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 checker/tests/regex/Issue3281.java diff --git a/checker/tests/regex/Issue3281.java b/checker/tests/regex/Issue3281.java new file mode 100644 index 00000000000..a8729a7e418 --- /dev/null +++ b/checker/tests/regex/Issue3281.java @@ -0,0 +1,66 @@ +// Test case for Issue 3281: +// https://github.com/typetools/checker-framework/issues/3281 + +// @skip-test until the bug is fixed + +import org.checkerframework.checker.regex.RegexUtil; +import org.checkerframework.checker.regex.qual.Regex; + +public class Issue3281 { + + @Regex String f = null; + + public boolean b = false; + + void m1(String s) { + if (true) { + // :: error: (argument.type.incompatible) + Pattern.compile(s); + } + } + + void m2(String s) { + RegexUtil.isRegex(s); + if (true) { + // :: error: (argument.type.incompatible) + Pattern.compile(s); + } + } + + void m2f(String s) { + RegexUtil.isRegex(s); + if (true) { + // :: error: (assignment.type.incompatible) + f = s; + } + } + + void m3(String s) { + if (RegexUtil.isRegex(s)) { + Pattern.compile(s); + } + } + + void m4(String s, String s2) { + RegexUtil.isRegex(s); + if (RegexUtil.isRegex(s2)) { + Pattern.compile(s); + } + } + + void m4f(String s, String s2) { + RegexUtil.isRegex(s); + if (RegexUtil.isRegex(s2)) { + // :: error: (assignment.type.incompatible) + f = s; + } + } + + void m5f(String s, String s2) { + RegexUtil.isRegex(s); + if (b) { + // :: error: (assignment.type.incompatible) + f = s; + } + } +} diff --git a/dataflow/src/main/java/org/checkerframework/dataflow/cfg/CFGBuilder.java b/dataflow/src/main/java/org/checkerframework/dataflow/cfg/CFGBuilder.java index a3b1c9ca5a1..47df04104b9 100644 --- a/dataflow/src/main/java/org/checkerframework/dataflow/cfg/CFGBuilder.java +++ b/dataflow/src/main/java/org/checkerframework/dataflow/cfg/CFGBuilder.java @@ -2718,9 +2718,6 @@ public MethodInvocationNode visitMethodInvocation(MethodInvocationTree tree, Voi return null; } - // TODO? Variable wasn't used. - // boolean isBooleanMethod = TypesUtils.isBooleanType(method.getReturnType()); - ExpressionTree methodSelect = tree.getMethodSelect(); assert TreeUtils.isMethodAccess(methodSelect) : "Expected a method access, but got: " + methodSelect;