-
-
Notifications
You must be signed in to change notification settings - Fork 278
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-37566] - Annotate URLish methods and handle NPE in RemoteClassLoader. #170
[JENKINS-37566] - Annotate URLish methods and handle NPE in RemoteClassLoader. #170
Conversation
…ssLoader. The NPE seems to be non-realistic (why would RemoteClassloader construct URL from File?), but it’s better to fix it just in case.
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.
Probably not introducing a bug, but does not seem to be correctly solving it either.
URL toURL() { | ||
return url; | ||
} | ||
}; | ||
} | ||
|
||
static URLish from(final File f) { | ||
@Nullable | ||
static URLish from(@CheckForNull final File f) { |
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 internal, so why not make it @Nonnull
? Then toURL
could also be @Nonnull
, as could toURLs
. If you want to signal an error, throw an exception.
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.
makes sense
@@ -16,20 +18,28 @@ | |||
abstract class URLish { | |||
private URLish() {} | |||
|
|||
/** | |||
* Converts URLish to the standard {@link URL} type. | |||
* @return URL or {@code null} if the target destination is known to be non-existent. |
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.
Why not throw, say, FileNotFoundException
in such a case, so this can be @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.
We could, of course.
Can do it though now we are rather in the code refactoring area than in the NPE warning fix one
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 After some consideration I feel returning null is a valid behavior. E.g. this code uses abstract URLish, which may be both URL and File pointers. I could refactor all the code to do the same with exceptions, but I do not feel it improves the code much. WDYT?
public URL findResource(String name) {
// first attempt to load from locally fetched jars
URL url = super.findResource(name);
final Channel channel = channel();
if(url!=null || channel == null || !channel.isRemoteClassLoadingAllowed()) return url;
try {
if(resourceMap.containsKey(name)) {
URLish f = resourceMap.get(name);
if(f==null) return null; // no such resource
URL u = f.toURL();
if (u!=null) return u;
}
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.
IIUC it is the line
if (u!=null) return u;
that is under discussion. I think it makes sense to have toURL
throw an exception if it is definitely broken, and for the caller to decide what to do with that—log it, in this case (whatever the catch
block does).
Or fix this method to be @Nonnull
, which seems more natural, and leave it up to the consumer of the resulting URL
to deal with missing resources—they would anyway need to be handling FileNotFoundException
, so it seems pointless to be prechecking that condition.
IOW lines 46–50 seem stupid.
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.
Does not make things any worse, though it misses an opportunity to make the code clearer and more robust.
@@ -16,20 +18,28 @@ | |||
abstract class URLish { | |||
private URLish() {} | |||
|
|||
/** | |||
* Converts URLish to the standard {@link URL} type. | |||
* @return URL or {@code null} if the target destination is known to be non-existent. |
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.
IIUC it is the line
if (u!=null) return u;
that is under discussion. I think it makes sense to have toURL
throw an exception if it is definitely broken, and for the caller to decide what to do with that—log it, in this case (whatever the catch
block does).
Or fix this method to be @Nonnull
, which seems more natural, and leave it up to the consumer of the resulting URL
to deal with missing resources—they would anyway need to be handling FileNotFoundException
, so it seems pointless to be prechecking that condition.
IOW lines 46–50 seem stupid.
I will consider it for the next refactoring phases. It is definitely not the biggest issue in Remoting |
The NPE seems to be non-realistic (why would RemoteClassloader construct URL from File?), but it’s better to fix it just in case.
https://issues.jenkins-ci.org/browse/JENKINS-37566
@reviewbybees