typetools / typetools/checker-framework
Misleading cast.unsafe error
Open
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Consider the following code:
class cast_unsafe{
static final float b = 0.75f;
void casting(){
int c = (int)(b);
}
}
Run it by the following command: javac -processor index cast_unsafe.java
Output:
cast_unsafe.java:4: warning: [cast.unsafe] "@DoubleVal(0.75) float" may not be casted to the type "@IntVal(0) int"
int c = (int)(b);
^
cast_unsafe.java:4: warning: [cast.unsafe] "@LowerBoundUnknown float" may not be casted to the type "@NonNegative int"
int c = (int)(b);
^
2 warnings
However, the cast is safe and c evaluates to 0.
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
Reproduce the warning with the supplied cast_unsafe.java example and javac -processor index cast_unsafe.java, then trace the checker entry point that reports the cast.unsafe diagnostic. Done means the safe float-to-int cast no longer produces misleading warnings and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100