redhat-developer / redhat-developer/vscode-java
Return null through ternary operator does not give Type mismatch error
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 546
- Avg merge
- 20h 1m
- Merged PRs (30d)
- 11
Description
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.

Code 2:
public double getValue() {
return value == null ? null : Double.parseDouble(value);
}
No errors shown on the returned null.

Code 3:
public double getValue() {
if (value == null)
return null;
else
return Double.parseDouble(value);
}
Same error:

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
- Make code shown.
- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing Code 1, Code 2, and Code 3 in the Java extension and compare the diagnostics for the ternary and if/else forms. Trace how the Java language support analyzes return expressions, then verify that the ternary case reports the same type mismatch as the other examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100