Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect suspicious use of Enum.valueOf #24

Open
jzbrooks opened this issue Mar 20, 2023 · 0 comments
Open

Detect suspicious use of Enum.valueOf #24

jzbrooks opened this issue Mar 20, 2023 · 0 comments

Comments

@jzbrooks
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant