-
Notifications
You must be signed in to change notification settings - Fork 189
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
Create static variant of ImageDescriptor.imageDescriptorFromURI() #2416
base: master
Are you sure you want to change the base?
Conversation
@vogella You contributed the original method. wdyt? |
LGTM, thanks @ptziegler |
bundles/org.eclipse.jface/src/org/eclipse/jface/resource/ImageDescriptor.java
Outdated
Show resolved
Hide resolved
4017574
to
d58f6ec
Compare
*/ | ||
public ImageDescriptor imageDescriptorFromURI(URI uriIconPath) { | ||
public static ImageDescriptor createFromURI(URI uriIconPath) { | ||
try { | ||
return ImageDescriptor.createFromURL(new URL(uriIconPath.toString())); | ||
} catch (MalformedURLException | NullPointerException e) { |
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.
As we are currently changing the method, catching NPE is really really BAD!
We should check for null
like in createFromURL
} catch (MalformedURLException | NullPointerException e) { | |
} catch (MalformedURLException e) { |
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.
In e.g. createFromURL(), we have an explicit null check where getMissingImageDescriptor() is returned. I think it makes more sense to do the same here, rather than forwarding the exception.
I've also noticed that |
d58f6ec
to
43e21c6
Compare
Be very careful. It looks so innocent and obvious, bu there are cases where URI creation will thrown an exception where URL creation does not. E.g., if there is a space in the string |
@laeubi do you still have open concerns 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.
Looks fine for me, using this method somewhere in the code (even in a testcase) might help to demonstrate its usefulness.
Maybe we should mention in the javadoc that this only works for URIs that can be converted to URLs?
This method is intended to be used as a wrapper for createFromURL() to avoid having to deal with the checked MalformedURLException. However, this method is effectively unusable, as it requires the user to already have an instance of the ImageDescriptor they want to created. Instead, create a new, static createFromURI() method, mark the old method as deprecated and internally delegate to the new method. The old method was created as a response to Bug 559656 [1], in order to match the signature of IResourceUtilities. But because the latter is accessed via an OSGi service, it doesn't need to be static. Which is something that doesn't really work for image descriptors. [1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=559656
43e21c6
to
7307874
Compare
Adding a disclaimer sounds like a good idea. |
That's right. |
This method is intended to be used as a wrapper for createFromURL() to avoid having to deal with the checked MalformedURLException. However, this method is effectively unusable, as it requires the user to already have an instance of the ImageDescriptor they want to created.
Instead, create a new, static createFromURI() method, mark the old method as deprecated and internally delegate to the new method.
The old method was created as a response to Bug 559656 [1], in order to match the signature of IResourceUtilities. But because the latter is accessed via an OSGi service, it doesn't need to be static. Which is something that doesn't really work for image descriptors.
[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=559656