fix model for TextUtils.isEmpty (#92)
Parameter type is CharSequence, not String
diff --git a/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java b/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java
index 327fd03..dddb334 100644
--- a/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java
+++ b/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java
@@ -245,7 +245,7 @@
private static final ImmutableSetMultimap<MethodRef, Integer> NULL_IMPLIES_TRUE_PARAMETERS =
new ImmutableSetMultimap.Builder<MethodRef, Integer>()
.put(methodRef(Strings.class, "isNullOrEmpty(java.lang.String)"), 0)
- .put(methodRef("android.text.TextUtils", "isEmpty(java.lang.String)"), 0)
+ .put(methodRef("android.text.TextUtils", "isEmpty(java.lang.CharSequence)"), 0)
.build();
private static final ImmutableSet<MethodRef> NULLABLE_RETURNS =
diff --git a/nullaway/src/test/java/com/uber/nullaway/NullAwayTest.java b/nullaway/src/test/java/com/uber/nullaway/NullAwayTest.java
index c8e05c4..f323f27 100644
--- a/nullaway/src/test/java/com/uber/nullaway/NullAwayTest.java
+++ b/nullaway/src/test/java/com/uber/nullaway/NullAwayTest.java
@@ -97,6 +97,7 @@
compilationHelper
.addSourceFile("NullAwayNativeModels.java")
.addSourceFile("androidstubs/WebView.java")
+ .addSourceFile("androidstubs/TextUtils.java")
.doTest();
}
diff --git a/nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayNativeModels.java b/nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayNativeModels.java
index 51b5553..2e38ba6 100644
--- a/nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayNativeModels.java
+++ b/nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayNativeModels.java
@@ -288,5 +288,10 @@
android.webkit.WebView webView = new WebView();
// BUG: Diagnostic contains: dereferenced expression
webView.getUrl().toString();
+ String s = null;
+ if (!android.text.TextUtils.isEmpty(s)) {
+ // no warning due to isEmpty check
+ s.hashCode();
+ }
}
}
diff --git a/nullaway/src/test/resources/com/uber/nullaway/testdata/androidstubs/TextUtils.java b/nullaway/src/test/resources/com/uber/nullaway/testdata/androidstubs/TextUtils.java
new file mode 100644
index 0000000..693e27f
--- /dev/null
+++ b/nullaway/src/test/resources/com/uber/nullaway/testdata/androidstubs/TextUtils.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 Uber Technologies, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+// STUB CLASS FOR PURPOSES OF REGRESSION TESTING ONLY
+
+package android.text;
+
+public class TextUtils {
+
+ public static boolean isEmpty(CharSequence c) {
+ return false;
+ }
+}