NullPointerException through auto-boxing-behavior of Java ternary operator

According to JLS: –

The type of a conditional expression is determined as follows:

  • If the second and third operands have the same type (which may be the null type), then that is the type of the conditional
    expression.
  • If one of the second and third operands is of primitive type T, and the type of the other is the result of applying boxing conversion
    (ยง5.1.7) to T, then the type of the conditional expression is T.

Leave a Comment