Skip to content

Commit 8f4b928

Browse files
authored
Add library model for Apache Commons CollectionUtils.isNotEmpty (#932) (#1062)
Thank you for contributing to NullAway! Please note that once you click "Create Pull Request" you will be asked to sign our [Uber Contributor License Agreement](https://cla-assistant.io/uber/NullAway) via [CLA assistant](https://cla-assistant.io/). Before pressing the "Create Pull Request" button, please provide the following: - [ ] Added library model for Apache Commons CollectionUtils.isNotEmpty - [ ] related to issue #932 - [ ] `void apacheCollectionsCollectionUtilsIsNotEmpty()` and `void apacheCollectionsCollectionUtilsIsNotEmpty()` tests have been added to `FrameworkTests.java`
1 parent d6b7fa3 commit 8f4b928

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java

+10
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,16 @@ private static class DefaultLibraryModels implements LibraryModels {
741741
.put(methodRef("spark.utils.StringUtils", "isNotBlank(java.lang.CharSequence)"), 0)
742742
.put(methodRef("spark.utils.StringUtils", "hasLength(java.lang.String)"), 0)
743743
.put(methodRef("spark.utils.StringUtils", "hasLength(java.lang.CharSequence)"), 0)
744+
.put(
745+
methodRef(
746+
"org.apache.commons.collections.CollectionUtils",
747+
"isNotEmpty(java.util.Collection)"),
748+
0)
749+
.put(
750+
methodRef(
751+
"org.apache.commons.collections4.CollectionUtils",
752+
"isNotEmpty(java.util.Collection<?>)"),
753+
0)
744754
.put(
745755
methodRef("org.apache.commons.lang.StringUtils", "isNotEmpty(java.lang.String)"), 0)
746756
.put(

nullaway/src/test/java/com/uber/nullaway/FrameworkTests.java

+36
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,42 @@ public void apacheValidateStringValidIndex() {
10171017
.doTest();
10181018
}
10191019

1020+
@Test
1021+
public void apacheCollectionsCollectionUtilsIsNotEmpty() {
1022+
defaultCompilationHelper
1023+
.addSourceLines(
1024+
"Foo.java",
1025+
"package com.uber;",
1026+
"import org.apache.commons.collections.CollectionUtils;",
1027+
"import org.jetbrains.annotations.Nullable;",
1028+
"import java.util.List;",
1029+
"public class Foo {",
1030+
" public void bar(@Nullable List<String> s) {",
1031+
" if(CollectionUtils.isNotEmpty(s))",
1032+
" s.get(0);",
1033+
" }",
1034+
"}")
1035+
.doTest();
1036+
}
1037+
1038+
@Test
1039+
public void apacheCollections4CollectionUtilsIsNotEmpty() {
1040+
defaultCompilationHelper
1041+
.addSourceLines(
1042+
"Foo.java",
1043+
"package com.uber;",
1044+
"import org.apache.commons.collections4.CollectionUtils;",
1045+
"import org.jetbrains.annotations.Nullable;",
1046+
"import java.util.List;",
1047+
"public class Foo {",
1048+
" public void bar(@Nullable List<String> s) {",
1049+
" if(CollectionUtils.isNotEmpty(s))",
1050+
" s.get(0);",
1051+
" }",
1052+
"}")
1053+
.doTest();
1054+
}
1055+
10201056
@Test
10211057
public void filesIsDirectory() {
10221058
defaultCompilationHelper

0 commit comments

Comments
 (0)