Skip to content

Commit

Permalink
Add check for provider
Browse files Browse the repository at this point in the history
In inner classes of Image.

Fixes #1667
  • Loading branch information
fedejeanne committed Dec 20, 2024
1 parent d13fe1e commit 723b1f9
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2041,6 +2041,12 @@ private abstract class AbstractImageProviderWrapper {
abstract ImageHandle getImageMetadata(int zoom);
abstract AbstractImageProviderWrapper createCopy(Image image);

protected void checkProvider(Object provider, Class<?> expectedClass) {
if (provider == null || !expectedClass.isAssignableFrom(provider.getClass())) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
}

@Override
public int hashCode() {
return getProvider().hashCode();
Expand All @@ -2061,7 +2067,8 @@ private class ImageFileNameProviderWrapper extends AbstractImageProviderWrapper
private final ImageFileNameProvider provider;

ImageFileNameProviderWrapper(ImageFileNameProvider provider) {
this.provider = Objects.requireNonNull(provider);
checkProvider(provider, ImageFileNameProvider.class);
this.provider = provider;
}

@Override
Expand Down Expand Up @@ -2111,7 +2118,8 @@ private class ImageDataProviderWrapper extends AbstractImageProviderWrapper {
private final ImageDataProvider provider;

ImageDataProviderWrapper(ImageDataProvider provider) {
this.provider = Objects.requireNonNull(provider);
checkProvider(provider, ImageDataProvider.class);
this.provider = provider;
}

@Override
Expand Down

0 comments on commit 723b1f9

Please sign in to comment.