Skip to content

Commit

Permalink
Strip annotations from MethodSymbol strings (#993)
Browse files Browse the repository at this point in the history
Follow up to #992. This is a better fix for handling type-use
annotations that may be present in MethodSymbol strings from JDK 22
forward.
  • Loading branch information
msridhar committed Jul 12, 2024
1 parent ea80fe8 commit 40576b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
10 changes: 9 additions & 1 deletion nullaway/src/main/java/com/uber/nullaway/LibraryModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,20 @@ public static MethodRef methodRef(String enclosingClass, String methodSignature)
}

public static MethodRef fromSymbol(Symbol.MethodSymbol symbol) {
String methodStr = symbol.toString();
String methodStr = stripAnnotationsFromMethodSymbolString(symbol.toString());

return new MethodRef(
symbol.owner.getQualifiedName().toString(), symbol.name.toString(), methodStr);
}

/**
* Strip annotations from a method symbol string. The logic is specialized to work for strings
* produced by {@link Symbol.MethodSymbol#toString()} and will not work for arbitrary strings.
*/
private static String stripAnnotationsFromMethodSymbolString(String str) {
return str.replaceAll("@[^ ]+ ", "");
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,6 @@ private static class DefaultLibraryModels implements LibraryModels {
"com.google.common.base.Preconditions",
"<T>checkNotNull(T,java.lang.String,java.lang.Object...)"),
0)
// For JDK 22
// TODO check if this is still needed in JDK 23 / subsequent releases
.put(
methodRef(
"com.google.common.base.Preconditions",
"<T>checkNotNull(T,java.lang.String,[email protected] Object...)"),
0)
.put(
methodRef(
"com.google.common.base.Preconditions",
Expand Down Expand Up @@ -523,13 +516,6 @@ private static class DefaultLibraryModels implements LibraryModels {
"com.google.common.base.Verify",
"<T>verifyNotNull(T,java.lang.String,java.lang.Object...)"),
0)
// For JDK 22
// TODO check if this is still needed in JDK 23 / subsequent releases
.put(
methodRef(
"com.google.common.base.Verify",
"<T>verifyNotNull(T,java.lang.String,[email protected] Object...)"),
0)
.put(methodRef("java.util.Objects", "<T>requireNonNull(T)"), 0)
.put(methodRef("java.util.Objects", "<T>requireNonNull(T,java.lang.String)"), 0)
.put(
Expand Down

0 comments on commit 40576b7

Please sign in to comment.