Skip to content

Return null through ternary operator does not give Type mismatch error #436

Closed

Description

@ADTC

Returning null through a ternary operator does not give Type mismatch error. It should.

Code 1:

public double getValue() {
    return null;
}

null is error-underlined with the error [Java] Type mismatch: cannot convert from null to double.
image

Code 2:

public double getValue() {
    return value == null ? null : Double.parseDouble(value);
}

No errors shown on the returned null.
image

Code 3:

public double getValue() {
    if (value == null)
        return null;
    else
        return Double.parseDouble(value);
}

Same error:
image

Environment
  • Operating System: Windows 10 x64
  • JDK version: 8
  • Visual Studio Code version: 1.20.0
  • Java extension version: 0.18.1
Steps To Reproduce
  1. Make code shown.
  2. Look for error.
Current Result

Code 1 & 3 shows error. Code 2 doesn't.

Expected Result

All Code blocks should show error.

Additional Information

Please let me know if you need any logs or anything.

Activity

  1. fbricon commented on Feb 12, 2018

    @fbricon
    Collaborator

    This is a known bug in the jdt compiler: https://bugs.eclipse.org/bugs/show_bug.cgi?id=416815

  2. ADTC commented on Feb 12, 2018

    @ADTC
    Author

    Since 2013? 😮

  3. robstryker commented on Oct 28, 2026

    @robstryker
    Contributor

    As much as I'd like to keep this open, we have 900+ issues, and this one is clearly upstream. So I'm closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions