-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 #3620: throw a meaningful exception if no kind/plural, default plural #3624
Conversation
Can one of the admins verify this patch? |
...es-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/ResourceDefinitionContext.java
Outdated
Show resolved
Hide resolved
223a239
to
10d60fb
Compare
kind is not strictly needed. updated the pr to relax that. |
10d60fb
to
25128d6
Compare
Sonar is complaining about the use of |
I'm a fan of not duplicating code - I know this is somewhat trivial, but anything else would simply be a copy of that. |
if (kind == null) { | ||
throw new IllegalArgumentException("Neither kind nor plural was set, at least one is required"); | ||
} | ||
plural = Utils.getPluralFromKind(kind); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is tricky because the target class might use a different plural version than the one computed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the context is constructed from a class it will use the annotation to populate this field. This will only occur in case where someone is manually constructing the context. Every method the specifies both a context and a class has been deprecated - it's not expected that a user will manually construct the context when a class is used.
When Alex reported that issue, I was thinking more of an Objects.requireNonNull wherever the plural was consumed to compute the URL. However, I haven't analyzed and maybe it's a better approach to validate the definition context, or both. |
Since these contexts are the only place that the plural can come from and are immutable it's sufficient to validate them as they are created. That will also provide the most meaningful feedback. |
...lient/src/test/java/io/fabric8/kubernetes/client/dsl/base/ResourceDefinitionContextTest.java
Outdated
Show resolved
Hide resolved
…sl/base/ResourceDefinitionContextTest.java Co-authored-by: Chris Laprun <[email protected]>
Kudos, SonarCloud Quality Gate passed! |
Description
fix #3620: throw a meaningful exception if no kind/plural, and default plural based upon kind.
It looks like the code is tolerant to the other fields being missing - including group.
Type of change
test, version modification, documentation, etc.)
Checklist