-
Notifications
You must be signed in to change notification settings - Fork 228
Create static variant of ImageDescriptor.imageDescriptorFromURI() #2416
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
Conversation
|
@vogella You contributed the original method. wdyt? |
Test Results 1 214 files - 306 1 214 suites - 306 1h 31m 50s ⏱️ - 1m 49s For more details on these failures, see this check. Results for commit 5ee6314. ± Comparison against base commit 1876695. This pull request skips 5 tests.♻️ This comment has been updated with latest results. |
|
LGTM, thanks @ptziegler |
bundles/org.eclipse.jface/src/org/eclipse/jface/resource/ImageDescriptor.java
Outdated
Show resolved
Hide resolved
4017574 to
d58f6ec
Compare
| 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? |
laeubi
left a comment
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?
43e21c6 to
7307874
Compare
Adding a disclaimer sounds like a good idea. |
That's right. |
7307874 to
49f09b5
Compare
HannesWell
left a comment
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.
Lets move this forward. The change looks good to me and unless somebody objects I plan to submit this within the next days.
Thank you @ptziegler.
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
That's right. But here an URI is converted into a URL and as far as I know URIs are strict regarding their content and therefore the conversion URI -> URL should be (relatively) save? But maybe I'm wrong. It's definitively not true for the opposite: URL -> URL can have many problems since URLs are not strictly validating their content.
Since there was no opposition I assume that assessment is right, but with the current state of the doc even a more dangerous behavior would be fine.
bundles/org.eclipse.jface/src/org/eclipse/jface/resource/ImageDescriptor.java
Outdated
Show resolved
Hide resolved
49f09b5 to
09cb82d
Compare
HannesWell
left a comment
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 there are no further remarks, I plan to submit this Monday (European) evening.
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
09cb82d to
5ee6314
Compare
|
Test failures are unrelated, submitting. Thanks again. |
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