GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] Numeric conditional with a char operand and an int constant is typed as int · Issue #7150 · pmd/pmd

[java] Numeric conditional with a char operand and an int constant is typed as int #7150

New issue
Copy link
New issue
Copy link
Closed
#7162
Closed
[java] Numeric conditional with a char operand and an int constant is typed as int#7150
#7162
Copy link
Labels
in:type-resolutionAffects the type resolution code
Milestone
7.29.0

Description

@saryn17
saryn17
opened on Oct 6, 2026
Issue body actions

Affects PMD Version: 7.28.0 (also 7.29.0-SNAPSHOT)

Description:

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:

pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ast/ConditionalMirrorImpl.java

Lines 103 to 105 in 5c9271c

if (thenType.isNumeric() && elseType.isNumeric()) {
return TypeConversion.binaryNumericPromotion(thenType.unbox(), elseType.unbox());
}

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.

Found while working on #7136.

Code Sample demonstrating the issue:

class Cond {
    static void c(int x, int y) { }
    static void c(Integer x, char y) { }

    void t(Integer value, boolean flag) {
        c(value, flag ? 'a' : 1);
    }
}

Steps to reproduce:

  1. javac Cond.java, also with --release 8, then javap -c -p Cond: the call is c:(Ljava/lang/Integer;C)V.
  2. Run PMD on Cond.java with the XPath rule //MethodCall[pmd-java:matchesSig("Cond#c(int,int)")]. It reports line 6.

Running PMD through: Other (PmdAnalysis API)

Activity

  1. saryn17
    added a commit that references this issue on Oct 6, 2026

    [java] UnnecessaryBoxing: rerun the overload resolution without the u…

    15327e0
  2. adangel
    added
    in:type-resolutionAffects the type resolution code
    on Oct 26, 2026
  3. adangel
    added this to the 7.29.0 milestone on Oct 26, 2026
  4. adangel
    closed this as completedin #7162on Oct 26, 2026
  5. adangel
    added 2 commits that reference this issue on Oct 26, 2026

    Enable test case for pmd#7150

    e0b56be

    [java] Fix pmd#7150: type of numeric conditionals with byte, short or…

    6c892f0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in:type-resolutionAffects the type resolution code

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.29.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.