Skip to content

Commit

Permalink
Add Throwable.getCause and getLocalizedMessage() library models (#717)
Browse files Browse the repository at this point in the history
They both can return `null`:

- In its default implementation `getLocalizedMessage()` calls `getMessage()`, so should be treated in the same way.
- Not every throwable was created with a cause, so `getCause()` will often return `null`, as indicated by its javadoc.
  • Loading branch information
XN137 authored Jan 20, 2023
1 parent d190853 commit c4c7c4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ private static class DefaultLibraryModels implements LibraryModels {
new ImmutableSet.Builder<MethodRef>()
.add(methodRef("com.sun.source.tree.CompilationUnitTree", "getPackageName()"))
.add(methodRef("java.lang.Throwable", "getMessage()"))
.add(methodRef("java.lang.Throwable", "getLocalizedMessage()"))
.add(methodRef("java.lang.Throwable", "getCause()"))
.add(methodRef("java.lang.ref.Reference", "get()"))
.add(methodRef("java.lang.ref.PhantomReference", "get()"))
.add(methodRef("java.lang.ref.SoftReference", "get()"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public static void referenceStuff() {
Exception e = new RuntimeException();
// BUG: Diagnostic contains: dereferenced expression
e.getMessage().hashCode();
// BUG: Diagnostic contains: dereferenced expression
e.getLocalizedMessage().hashCode();
// BUG: Diagnostic contains: dereferenced expression
e.getCause().toString();
}

// we will add bug annotations when we have full support for maps
Expand Down

0 comments on commit c4c7c4b

Please sign in to comment.