Skip to content

Detect suspicious use of Enum.valueOf #24

@jzbrooks

Description

@jzbrooks

Enum.valueOf shouldn't be called using an Enum.name property. Since the name of the enum variants may change over time, this might constitute a runtime-only error. This is most suspicious when a different enum's name is being used as the argument. e.g.

val model = CarModel.CIVIC
val make = CarMake.valueOf(model.name)

Dealing with the enum variants more directly (like switching on the enum variant) comes with more compile-time guarantees (especially in Kotlin). Conversion between enums with similar variants should happen with these switching constructs rather than depending on the similarity of enum variant names.

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