Skip to content

Conversation

@ptziegler
Copy link
Contributor

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

@ptziegler
Copy link
Contributor Author

@vogella You contributed the original method. wdyt?

@github-actions
Copy link
Contributor

github-actions bot commented Oct 17, 2024

Test Results

 1 214 files   -   306   1 214 suites   - 306   1h 31m 50s ⏱️ - 1m 49s
 7 729 tests ±    0   7 495 ✅  -     6  233 💤 + 5  1 ❌ +1 
16 232 runs   - 6 456  15 716 ✅  - 6 419  515 💤  - 38  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 5ee6314. ± Comparison against base commit 1876695.

This pull request skips 5 tests.
org.eclipse.ui.genericeditor.tests.HoverTest ‑ testEnabledWhenHover
org.eclipse.ui.genericeditor.tests.HoverTest ‑ testMultipleHover
org.eclipse.ui.genericeditor.tests.HoverTest ‑ testProblemHover
org.eclipse.ui.genericeditor.tests.HoverTest ‑ testSingleHover
org.eclipse.ui.genericeditor.tests.ShowInformationTest ‑ testInformationControl

♻️ This comment has been updated with latest results.

@vogella
Copy link
Contributor

vogella commented Oct 18, 2024

LGTM, thanks @ptziegler

public static ImageDescriptor createFromURI(URI uriIconPath) {
try {
return ImageDescriptor.createFromURL(new URL(uriIconPath.toString()));
} catch (MalformedURLException | NullPointerException e) {
Copy link
Contributor

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

Suggested change
} catch (MalformedURLException | NullPointerException e) {
} catch (MalformedURLException e) {

Copy link
Contributor Author

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.

@ptziegler
Copy link
Contributor Author

I've also noticed that new URL(String) will be deprecated in Java 20, so I switched to the equivalent URI.toURL().

@merks
Copy link
Contributor

merks commented Oct 18, 2024

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

@vogella
Copy link
Contributor

vogella commented Nov 5, 2024

@laeubi do you still have open concerns here?

Copy link
Contributor

@laeubi laeubi left a 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?

@ptziegler
Copy link
Contributor Author

Maybe we should mention in the javadoc that this only works for URIs that can be converted to URLs?

Adding a disclaimer sounds like a good idea.

@HannesWell
Copy link
Member

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.

Copy link
Member

@HannesWell HannesWell left a 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.

Copy link
Member

@HannesWell HannesWell left a 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
@HannesWell
Copy link
Member

Test failures are unrelated, submitting.

Thanks again.

@HannesWell HannesWell merged commit 2866dd0 into eclipse-platform:master Dec 9, 2024
14 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants