Skip to content

Convert to Switch Save Action improper use #2370 #2719

@mebigfatguy

Description

@mebigfatguy

Using Eclipse
Version: 2025-12 (4.38.0)
Build id: 20251204-0850

With jdk 21 (altho targetting jdk17)

on Linux Mint 22
This class

package eclipsesaveactions;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class SaveActionsBug {

enum GiantSounds {Fee, Fi, Fo, Fum};

public List<String> convertToSwitchIssue(GiantSounds gs) {
    String key;
    switch (gs) {
        case Fee: 
            key = "Oh My";
        break;
        
        case Fi: 
            key = "Wow";
        break;
        
        case Fo: 
            key = "Uh oh";
        break;
        
        default: return Collections.emptyList();
    }
    
    return Arrays.asList("Yikes", key);
}
}

When convert to switch expressions is turned on and you auto save converts to

package eclipsesaveactions;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class SaveActionsBug {

enum GiantSounds {
    Fee,
    Fi,
    Fo,
    Fum
}

public List<String> convertToSwitchIssue(GiantSounds gs) {
    String key;
    key = switch (gs) {
        case Fee -> key = "Oh My";
        case Fi -> key = "Wow";
        case Fo -> key = "Uh oh";
        default -> {
            return Collections.emptyList();
        }
    };
    return Arrays.asList("Yikes", key);
}
}

which is incorrect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions