redhat-developer / redhat-developer/vscode-java
Editor erroneously reports warning in conditional operator
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 546
- Avg merge
- 20h 1m
- Merged PRs (30d)
- 11
Description
Erroneous warnings are reported in the editor in conditional operators.
Environment
- Operating System: Windows 10 Pro
- JDK version: OpenJDK 11.0.1
- Visual Studio Code version: 1.30.1
- Java extension version: 0.40.0
Steps To Reproduce
Write code like the following:
SpeedController motor;
if (RobotMap.isCompetitionRobot)
{
motor = new WPI_TalonSRX(RobotMap.liftMotorCanDeviceId);
}
else
{
motor = new Spark(RobotMap.centerLegMotorPwmChannel);
}
motor = RobotMap.isCompetitionRobot
? new WPI_TalonSRX(RobotMap.liftMotorCanDeviceId)
: new Spark(RobotMap.centerLegMotorPwmChannel);
where the class Spark extends a class that implements AutoCloseable.
Current Result
No warnings are reported in the if statement. However, the warning:
Resource leak: '<unassigned Closeable value>' is never closed
is reported for the code:
new Spark(RobotMap.centerLegMotorPwmChannel)
in the conditional operator.
Expected Result
No warnings should be reported at all.
Additional Informations
None.
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 the warning with the conditional-operator example in the issue, using the listed Windows, JDK, VS Code, and Java extension versions where possible. Trace the Java extension's resource-leak analysis for conditional expressions. Done means the conditional expression produces no erroneous warning while the existing if statement behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100