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-43496] - Add handling of the null Node#createComputer() result. #2922
[JENKINS-43496] - Add handling of the null Node#createComputer() result. #2922
Conversation
it is a follow-up to jenkinsci#2836 (comment) De-facto many Cloud plugins return `null` in `Node#createLauncher()`, but it has never been documented. In order to prevent possible API misusages in the future, I have added annotations and fixed handling of the extension point in `AbstractCIBase#updateComputer()` which may fail in the case of `null` or `RuntimeException` in the Node implementation.
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.
One question to answer
*/ | ||
@CheckForNull | ||
@Restricted(NoExternalUse.class) |
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.
Won't this cause compilation failures for sub-classes? (and if it doesn't then won't the subclass method be invocable anyway, in which case the annotation is useless
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.
Agreed
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.
@stephenc @jglick My intention was to reflect the Nobody but {@link Jenkins#updateComputerList()} should call this method.
comment in Javadoc. If you know a better annotation for it, just let me know. Not sure if I can dedicate time to writing another restriction if it is missing, so I will just remove it in such case
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.
@oleg-nenashev ah, were you looking for ProtectedExternally
then?
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.
@jglick Yep, it should work better in this case
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.
Apparently gratuitous restriction on createComputer
. I do not know offhand of Node
s which are neither Jenkins
nor Slave
s, but the API seems designed to make it possible.
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.
The annotation on Slave
does not appear to match reality. I do not know what it would mean to return null, but apparently some plugins do so for some reason.
* Nobody but {@link Jenkins#updateComputerList()} should call this method. | ||
* @return Created instance of the computer. | ||
* Can be {@code null} if the {@link Node} implementation does not support it (e.g. {@link Cloud} agent). |
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.
Is this actually true? A Cloud
agent would ultimately be a Slave
, and that is now documented to return non-null—which seems to contradict your statement that some implementations do return non-null.
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.
Fixed. Slave#createLauncher()
now can create nulls
@@ -306,6 +306,8 @@ public void setLabelString(String labelString) throws IOException { | |||
return new GetClockDifference1(); | |||
} | |||
|
|||
@Override | |||
@Nonnull |
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 is not true in the case of GoogleSlave
, from a quick search.
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.
I agree. Better to just remove since the parent Javadoc describes the null
case in a portable way
Needs another review |
@reviewbybees done, passing to @jenkinsci/code-reviewers |
used.add(c); | ||
} else { | ||
// TODO: Maybe it should be allowed, but we would just get NPE in the original logic before JENKINS-43496 | ||
LOGGER.log(Level.WARNING, "Node {0} has not executors. Cannot udate the Computer instance for it", n.getNodeName()); |
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.
… has no … update its …
@daniel-beck fine for you? |
In IRC @daniel-beck said he sees no obvious issues, hence merging |
…lt. (#2922) * [JENKINS-43496] - Add handling of the null Node#createComputer() result. it is a follow-up to #2836 (comment) De-facto many Cloud plugins return `null` in `Node#createLauncher()`, but it has never been documented. In order to prevent possible API misusages in the future, I have added annotations and fixed handling of the extension point in `AbstractCIBase#updateComputer()` which may fail in the case of `null` or `RuntimeException` in the Node implementation. * [JENKINS-43496] - Use ProtectedExternally to protect Node#createComputer() * [JENKINS-43496] - Remove the erroneous Nonnull annotation after the feedback from @jglick * [JENKINS-43496] - Fix typos noticed by @daniel-beck (cherry picked from commit bcf55ec)
it is a follow-up to #2836 (comment)
De-facto many Cloud plugins return
null
inNode#createLauncher()
, but it has never been documented.In order to prevent possible API misusages in the future, I have added annotations and fixed handling of the extension point in
AbstractCIBase#updateComputer()
which may fail in the case ofnull
orRuntimeException
in the Node implementation.See JENKINS-43496.
Changelog entries
Proposed changelog entries:
Node
implementation in a plugin does not support creation of ad-hoc computers or throws a runtime exception.Submitter checklist
Desired reviewers
@reviewbybees