Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ public ImmutableSetMultimap<MethodRef, Integer> nonNullParameters() {
return ImmutableSetMultimap.of();
}

/**
* MethodRef signatures are the method name plus argument types with no spaces after commas.
* Overloads need a separate entry each; {@code isEmptyOrNull(java.lang.CharSequence, boolean)}
* (space after the comma) would not match the two-argument method.
*/
@Override
public ImmutableSetMultimap<MethodRef, Integer> nullImpliesTrueParameters() {
return ImmutableSetMultimap.<MethodRef, Integer>builder()
.put(methodRef("org.utilities.StringUtils", "isEmptyOrNull(java.lang.CharSequence)"), 0)
.put(
methodRef("org.utilities.StringUtils", "isEmptyOrNull(java.lang.CharSequence,boolean)"),
0)
.build();
}

Expand Down
7 changes: 7 additions & 0 deletions sample/src/main/java/com/uber/mylib/MyClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ static int checkModel(@Nullable String s) {
return 0;
}

static int checkModelTrim(@Nullable String s) {
if (!StringUtils.isEmptyOrNull(s, true)) {
return s.hashCode();
}
return 0;
}

static void foo() {
log(null);
}
Expand Down
7 changes: 7 additions & 0 deletions sample/src/main/java/org/utilities/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ public class StringUtils {
public static boolean isEmptyOrNull(@Nullable CharSequence value) {
return value == null || value.length() == 0;
}

public static boolean isEmptyOrNull(@Nullable CharSequence value, boolean trim) {
Comment thread
msridhar marked this conversation as resolved.
if (value == null) {
return true;
}
return trim ? value.toString().trim().isEmpty() : value.length() == 0;
}
}