Skip to content

Commit 43e21c6

Browse files
committed
Create static variant of ImageDescriptor.imageDescriptorFromURI()
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
1 parent 929564c commit 43e21c6

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

bundles/org.eclipse.jface/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.jface;singleton:=true
5-
Bundle-Version: 3.35.100.qualifier
5+
Bundle-Version: 3.36.0.qualifier
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
88
Export-Package: org.eclipse.jface,

bundles/org.eclipse.jface/src/org/eclipse/jface/resource/ImageDescriptor.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2023 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -212,18 +212,37 @@ public static ImageDescriptor createFromURLSupplier(boolean useMissingImage, Sup
212212
* @param uriIconPath The URI of the image file.
213213
* @return a new image descriptor
214214
*
215-
* @since 3.19
215+
* @since 3.36
216216
*/
217-
public ImageDescriptor imageDescriptorFromURI(URI uriIconPath) {
217+
public static ImageDescriptor createFromURI(URI uriIconPath) {
218+
if (uriIconPath == null) {
219+
return getMissingImageDescriptor();
220+
}
218221
try {
219-
return ImageDescriptor.createFromURL(new URL(uriIconPath.toString()));
220-
} catch (MalformedURLException | NullPointerException e) {
222+
return ImageDescriptor.createFromURL(uriIconPath.toURL());
223+
} catch (MalformedURLException e) {
221224
// return the missing image placeholder to indicate
222225
// the incorrect call without interfering with the user flow
223226
return getMissingImageDescriptor();
224227
}
225228
}
226229

230+
/**
231+
* Convenient method to create an ImageDescriptor from an URI
232+
*
233+
* Delegates to ImageDescriptor createFromURL
234+
*
235+
* @param uriIconPath The URI of the image file.
236+
* @return a new image descriptor
237+
*
238+
* @since 3.19
239+
* @deprecated Use {@link #createFromURI(URI)} instead.
240+
*/
241+
@Deprecated(since = "3.36", forRemoval = true)
242+
public ImageDescriptor imageDescriptorFromURI(URI uriIconPath) {
243+
return createFromURI(uriIconPath);
244+
}
245+
227246
@Override
228247
public Object createResource(Device device) throws DeviceResourceException {
229248
Image result = createImage(false, device);

0 commit comments

Comments
 (0)