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
[JENKINS-38048] Relax nullability on Item/ItemGroup context parameters #68
[JENKINS-38048] Relax nullability on Item/ItemGroup context parameters #68
Conversation
The underlying checks already handle null values. Makes it easier to provide credentials dropdowns in global configuration.
This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation. |
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.
My initial feeling is that this is a direction I do not want the API to take
Can you explain why? These newly introduced methods take a |
Well if we allow I am open to debate on this subject. Just my initial push-back |
Well instead of return new StandardListBoxModel()
.includeEmptyValue()
.includeMatchingAs(
project instanceof Queue.Task
? Tasks.getAuthenticationOf((Queue.Task) project)
: ACL.SYSTEM,
project,
StandardUsernameCredentials.class,
GitURIRequirementsBuilder.fromUri(url).build(),
GitClient.CREDENTIALS_MATCHER)
.includeCurrentValue(credentialsId); you could inline the implementation of StandardListBoxModel model = new StandardListBoxModel().includeEmptyValue();
model.addMissing(CredentialsProvider.listCredentials(
StandardUsernameCredentials.class,
project,
project instanceof Queue.Task
? Tasks.getAuthenticationOf((Queue.Task) project)
: ACL.SYSTEM,
GitURIRequirementsBuilder.fromUri(url).build(),
GitClient.CREDENTIALS_MATCHER)));
return model.includeCurrentValue(credentialsId); and then to satisfy proposed stricter nullability you would have to say StandardListBoxModel model = new StandardListBoxModel().includeEmptyValue();
Authentication authentication = project instanceof Queue.Task
? Tasks.getAuthenticationOf((Queue.Task) project)
: ACL.SYSTEM;
List<DomainRequirement> domainRequirements = GitURIRequirementsBuilder.fromUri(url).build();
CredentialsMatcher matcher = GitClient.CREDENTIALS_MATCHER);
model.addMissing(project != null ?
CredentialsProvider.listCredentials(
StandardUsernameCredentials.class,
project,
authentication,
domainRequirements,
matcher) :
CredentialsProvider.listCredentials(
StandardUsernameCredentials.class,
Jenkins.getInstance(),
authentication,
domainRequirements,
matcher));
return model.includeCurrentValue(credentialsId); which does not feel like an improvement to me, much as I also like explicit APIs. |
Compromise suggestion... make the |
Well the motivating case (as shown above) involves a null
Why would it make sense to allow null in some calls but not others? That sort of inconsistency is the whole point of this PR. |
Conclusion with @stephenc:
project instanceof Queue.Task ? Tasks.getAuthenticationOf((Queue.Task) project): ACL.SYSTEM |
@@ -467,7 +468,7 @@ | |||
* @since 2.1.0 | |||
*/ | |||
public AbstractIdCredentialsListBoxModel<T, C> includeMatchingAs(@NonNull Authentication authentication, | |||
@NonNull Item context, | |||
@Nullable Item context, |
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.
All other variants patched here wind up delegating to this one, which uses context
only to call CredentialsProvider.listCredentials
, which accepts a @Nullable Item
.
Made the requested short-term change and filed JENKINS-39324 for the rest. |
Used implicitly by jenkinsci/git-plugin#437 and jenkinsci/subversion-plugin#169.
@reviewbybees