You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] Numeric conditional with a char operand and an int constant is typed as int #7150
In the sample, the second argument has type char, so c(Integer, char) is applicable by strict invocation and javac selects it in phase 1. c(int, int) needs the unboxing of the first argument and is left to phase 2. PMD types the argument as int. c(Integer, char) is then not applicable in any phase, because int does not convert to char. PMD selects c(int, int).
JLS 15.25.2 gives a numeric conditional expression the type T when one operand has type byte, short or char and the other is a constant expression of type int representable in T. flag ? 'a' : 1 has type char. ConditionalMirrorImpl.getConditionalStandaloneType applies binary numeric promotion to the two operand types instead, which gives int:
The same lines type flag ? b : s with a byte b and a short s as int, where JLS 15.25.2 gives short. javac boxes Object o = flag ? b : s; with Short.valueOf.
Activity
[java] UnnecessaryBoxing: rerun the overload resolution without the u…
Enable test case for pmd#7150
[java] Fix pmd#7150: type of numeric conditionals with byte, short or…