-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MapSubject#containsExactlyEntriesIn throws NPE for null
values of keys
#468
Comments
null
values of keysnull
values of keys
Given the How does Kotlin define |
|
Probably we should be calling |
(@PeteGillin if he wants to look at this. Otherwise, I'll get to it eventually.) |
@lowasser Thanks. Kotlin is irrelevant here, I can get the same error with Java 8: @Test
void testComparingMapWithNullValues() {
Map<String, String> m = new HashMap<>();
Map<String, String> n = new HashMap<>();
m.put("key", "value");
n.put("key", null);
Truth.assertThat(m).containsExactlyEntriesIn(n);
}
|
Yeah, this is my fault. I originally introduced it back in December (aad4f3a). I agree with the fix @cpovirk proposed to use String.valueOf. I'll see if I can throw a fix together today or tomorrow. I'm vaguely surprised we haven't seen this before, since AFAICS it affects any failing isEqualTo, containsExactly, or containsExactlyElementsIn (non-fuzzy) on any Map with null values in it. I guess people really don't have null values very often? Anyway, thanks for the report, and sorry for the trouble. |
(Actually, not "any failing" test of those forms, only ones where it has the right key with the wrong value. Nevertheless.) I had a look around, and I don't think that we have similar issues in IterableSubject or MultimapSubject, or MapSubject's fuzzy assertions. |
FYI, this was fixed internally on Friday, I think we have to wait for it to get synced here. |
This is now fixed at github master in bf2cc0d . (Sorry for the delay, we had a slight administrative hitch with the syncing process.) Assuming everyone is happy with this, can someone who has the appropriate permissions mark this as fixed. |
Fix released in Truth 0.42. |
Version: Truth 0.41
Consider the following test
This test fails with the wrong message. I get a NPE from within Truth, instead of the expected Assertion exception ("value" != null).
The NPE originates in
com.google.common.truth.MapSubject
:The text was updated successfully, but these errors were encountered: