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

fix(cache): OnDemandType in no longer an enum #4673

Merged
merged 3 commits into from Jun 15, 2020
Merged

fix(cache): OnDemandType in no longer an enum #4673

merged 3 commits into from Jun 15, 2020

Conversation

claymccoy
Copy link
Contributor

Plugins that wanted to add an OnDemandType previously wouldn't be able to add to the enum.

Plugins that wanted to add an OnDemandType previously wouldn't be able to add to the enum.
public class OnDemandType {
private final String value;

public static OnDemandType fromString(String value) {
Copy link
Contributor

@ezimanyi ezimanyi Jun 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enum had the property that for a given string s, fromString(s) always returned a reference to the same OnDemandType. Now a new object is created every time, so it is longer true that fromString("abc") == fromString("abc").

This will break any place where we compare OnDemandType objects using ==, which appears to be in a lot of places.

It's probably a lot easier/safer to update fromString to retain the prior behavior than to update all the usages.

Copy link
Contributor Author

@claymccoy claymccoy Jun 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ezimanyi Thank you, great catch! You are right. Where == is used in Java files it will do an instance comparison and fail. I'd like to discourage instance comparison because it would only work for the built in types that exist in the OnDemandType class. I looked through all the files and only found three cases where instance comparison happens so I just changed those.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I guess as one more thing I'd love to see a test on .equals to make sure it's behaving how it seems...looks correct but if we're now depending on that in more places would be good to have a test on this new function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ezimanyi Added a plain java junit test as not to add an Groovy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks! Yeah I've also stopped writing even tests in Groovy, +1 to Java unit tests.

@claymccoy claymccoy merged commit 14c9515 into spinnaker:master Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants