Skip to content

Conversation

@copybara-service
Copy link
Contributor

Produce a build error for calls like containsExactly(null) that always lead to NPE.

These calls need to be written as containsExactly((Object) null) instead.

javac produces a warning for such cases, but it's easy to ignore and somewhat difficult to understand.

@copybara-service copybara-service bot force-pushed the test_814389578 branch 4 times, most recently from d98f50f to 50a22db Compare October 9, 2025 12:52
…ays lead to NPE.

These calls need to be written as `containsExactly((Object) null)` instead.

javac produces a warning for such cases, but it's easy to ignore and somewhat difficult to understand.

PiperOrigin-RevId: 817159968
@copybara-service copybara-service bot merged commit 9abc44f into master Oct 9, 2025
@copybara-service copybara-service bot deleted the test_814389578 branch October 9, 2025 13:36
copybara-service bot pushed a commit to google/j2cl that referenced this pull request Oct 13, 2025
…looks for calls like `asList(null)` that always throw NPE.

(To produce a list that contains only a null element, the calls needs to be `asList((Foo) null)` (with a cast to the array's _element_ type), not `asList(null)` or `asList((Foo[]) null)` (with a cast to the _array_ type).

([the check](google/error-prone#5263))

PiperOrigin-RevId: 818769295
copybara-service bot pushed a commit to google/truth that referenced this pull request Oct 13, 2025
…looks for calls like `asList(null)` that always throw NPE.

(To produce a list that contains only a null element, the calls needs to be `asList((Foo) null)` (with a cast to the array's _element_ type), not `asList(null)` or `asList((Foo[]) null)` (with a cast to the _array_ type).

([the check](google/error-prone#5263))

PiperOrigin-RevId: 818740054
copybara-service bot pushed a commit to google/truth that referenced this pull request Oct 13, 2025
…looks for calls like `containsExactly(null)` that always throw NPE.

(To check for a list that contains only a null element, the calls will soon need to be `containsExactly((Object) null)` (with a cast to the array's _element_ type), not `containsExactly(null)` or `containsExactly((Object[]) null)` (with a cast to the _array_ type).)

Also, sidestep other null-varargs fun by using `Collections.singleton` instead of the varargs methods `Arrays.asList` and `Stream.of`.)

([the check](google/error-prone#5263))

PiperOrigin-RevId: 818740054
copybara-service bot pushed a commit to google/truth that referenced this pull request Oct 13, 2025
…looks for calls like `containsExactly(null)` that always throw NPE.

(To check for a list that contains only a null element, the calls will soon need to be `containsExactly((Object) null)` (with a cast to the array's _element_ type), not `containsExactly(null)` or `containsExactly((Object[]) null)` (with a cast to the _array_ type).)

Also, sidestep other null-varargs fun by using `Collections.singleton` instead of the varargs methods `Arrays.asList` and `Stream.of`.)

([the check](google/error-prone#5263))

PiperOrigin-RevId: 818803000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant