google / google/error-prone

New check request: autoboxing on ternary operator

Open
#5,214 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

Imagine I have this method:

```java
Boolean returnABoolean()
```

and:

```java
boolean isEnabled = true;
Boolean myValue = isEnabled ? returnABoolean() : false;
```

This will crash if the `returnABoolean()` returns `null` because the [JLS says](https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.25.1):

> If the second and third operands are both of type Boolean, the conditional expression has type Boolean. **Otherwise, the conditional expression has type boolean.**

If ErrorProne could detect this it would be very helpful.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.