Skip to content
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

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

Open
ADTC opened this issue Feb 12, 2018 · 2 comments
Open

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

ADTC opened this issue Feb 12, 2018 · 2 comments

Comments

@ADTC
Copy link

ADTC commented Feb 12, 2018

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.

@fbricon
Copy link
Collaborator

fbricon commented Feb 12, 2018

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

@ADTC
Copy link
Author

ADTC commented Feb 12, 2018

Since 2013? 😮

@jdneo jdneo added the compile label Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants