Skip to content

Checking of boxed primitives (e.g. Double) for case null with JEP 441 #3830

Description

@gorankarlic

Does not properly support checking of boxed Double or Float for case null with JEP 441 pattern switching. Instead it shows Case constants in a switch on 'Double' must have type 'double' Java(2099252).

Environment
  • Operating System: MacOS 15.0.1
  • JDK version: JDK 21
  • Visual Studio Code version: Version: 1.94.2 (Universal)
  • Java extension version: v1.35.1
Steps To Reproduce
public class Test
{
    public static void main(final String[] args)
    {
        switch(Double.valueOf(1.0))
        {
            case null -> System.out.println("is null");
            default -> System.out.println("is not null");
        }
    }
}
Current Result

This displays the following error in VSCode:

Case constants in a switch on 'Double' must have type 'double' Java(2099252)
Expected Result

As Java 21 compiles and runs the above code it should not show an error.

Activity

  1. sworthiness commented on Dec 5, 2024

    @sworthiness

    I have a similar issue where an error is shown in vs-codium, but the code compiles in other IDEs and with maven CLI just fine.

    Error:

    Type mismatch: cannot convert from Object to boolean Java(16777233)

    Environment:

    (VS Codium - SSH remote development)

    • Version: 1.95.3
    • Release: 24321
    • Commit: dc5a551c256719475d2d0959270e3836c9bbb632
    • Date: 2024-11-16T09:16:49.983Z
    • Electron: 32.2.5
    • ElectronBuildId: undefined
    • Chromium: 128.0.6613.186
    • Node.js: 20.18.0
    • V8: 12.8.374.38-electron.0
    • OS: Windows_NT x64 10.0.19045
    • JDK: 17

    Steps to reproduce

    public class Test {
      public <T> T someMethod() {
        return (T) Boolean.TRUE;
      }
    
      public void someOtherMethod() {
        if (this.someMethod()) { // Type mismatch: cannot convert from Object to boolean Java(16777233)
        }
      }
    }

    Current Result

    The following compilation error is shown in vs-codium:
    Type mismatch: cannot convert from Object to boolean Java(16777233)
    The error is not seen if the result of this.someMethod() is stored in a Boolean var first

    Expected Result

    No compilation error should be seen here

  2. snjeza commented on Dec 5, 2024

    @snjeza
    Collaborator

    Does not properly support checking of boxed Double or Float for case null with JEP 441 pattern switching. Instead it shows Case constants in a switch on 'Double' must have type 'double' Java(2099252).

    This issue has been fixed in VS Code pre-release

    I have a similar issue where an error is shown in vs-codium, but the code compiles in other IDEs and with maven CLI just fine.

    "java.jdt.ls.javac.enabled": "on", fixes this.

  3. sworthiness commented on Dec 5, 2024

    @sworthiness

    @snjeza Sadly i am limited to java 17 so can't use this javac feature

  4. snjeza commented on Dec 5, 2024

    @snjeza
    Collaborator

    Sadly i am limited to java 17 so can't use this javac feature

    @sworthiness You only need to run VS Code with Java 23. Your project can use JDK >= 1.8

  5. sworthiness commented on Dec 6, 2024

    @sworthiness

    @snjeza sorry, i have a pretty locked down environment to work with - i managed to find a way to try out JDK23 but now suffer with this issue: #3807

    I have updated that issue with symptoms etc

  6. snjeza commented on Dec 6, 2024

    @snjeza
    Collaborator

    @sworthiness Could you provide a project example?

  7. sworthiness commented on Dec 9, 2024

    @sworthiness

    @snjeza if you’re asking for an example of this issue, i’ve given one above that is easily reproducible
    If youre asking for an example of the issue i just linked, i will list it there

  8. snjeza commented on Dec 9, 2024

    @snjeza
    Collaborator

    If youre asking for an example of the issue i just linked, i will list it there

    I have asked for an example of the linked issue.

  9. fbricon commented on Oct 14, 2025

    @fbricon
    Collaborator

    The original issue with boxed primitives is fixed, so I'm closing this issue. I've opened #4211 specifically for the other one found by @sworthiness.

  10. gorankarlic commented on Nov 12, 2025

    @gorankarlic
    Author

    Hvala @snjeza!

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions