Skip to content

Commit 8838c9d

Browse files
ptzieglerHeikoKlare
authored andcommitted
Fix NullPointerException when creating cursor with null device #2414
This is a follow-up to e8aadbb which introduced a regression when working with null devices. If null is passed as argument, the value of Device.getDevice() is used as a fallback when initializing this field. This field must be used for all other operations in the constructor, rather than the constructor argument. Closes #2414
1 parent 39a37ad commit 8838c9d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public final class Cursor extends Resource {
119119
public Cursor(Device device, int style) {
120120
super(device);
121121
this.cursorHandleProvider = new StyleCursorHandleProvider(style);
122-
this.handle = this.cursorHandleProvider.createHandle(device, DEFAULT_ZOOM).getHandle();
122+
this.handle = this.cursorHandleProvider.createHandle(this.device, DEFAULT_ZOOM).getHandle();
123123
init();
124124
this.device.registerResourceWithZoomSupport(this);
125125
}
@@ -160,7 +160,7 @@ public Cursor(Device device, int style) {
160160
public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
161161
super(device);
162162
this.cursorHandleProvider = new ImageDataWithMaskCursorHandleProvider(source, mask, hotspotX, hotspotY);
163-
this.handle = this.cursorHandleProvider.createHandle(device, DEFAULT_ZOOM).getHandle();
163+
this.handle = this.cursorHandleProvider.createHandle(this.device, DEFAULT_ZOOM).getHandle();
164164
init();
165165
this.device.registerResourceWithZoomSupport(this);
166166
}
@@ -229,7 +229,7 @@ private static CursorHandle setupCursorFromImageData(ImageData source, ImageData
229229
public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
230230
super(device);
231231
this.cursorHandleProvider = new ImageDataCursorHandleProvider(source, hotspotX, hotspotY);
232-
this.handle = this.cursorHandleProvider.createHandle(device, DEFAULT_ZOOM).getHandle();
232+
this.handle = this.cursorHandleProvider.createHandle(this.device, DEFAULT_ZOOM).getHandle();
233233
init();
234234
this.device.registerResourceWithZoomSupport(this);
235235
}
@@ -341,7 +341,7 @@ public Cursor(Device device, ImageDataProvider imageDataProvider, int hotspotX,
341341
super(device);
342342
if (imageDataProvider == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
343343
this.cursorHandleProvider = new ImageDataProviderCursorHandleProvider(imageDataProvider, hotspotX, hotspotY);
344-
this.handle = this.cursorHandleProvider.createHandle(device, DEFAULT_ZOOM).getHandle();
344+
this.handle = this.cursorHandleProvider.createHandle(this.device, DEFAULT_ZOOM).getHandle();
345345
init();
346346
this.device.registerResourceWithZoomSupport(this);
347347
}

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ public void test_ConstructorWithImageDataProvider() {
154154
Image sourceImage = new Image(display, 10, 10);
155155
Cursor cursor = new Cursor(display, sourceImage::getImageData, 0, 0);
156156
cursor.dispose();
157+
cursor = new Cursor(null, sourceImage::getImageData, 0, 0);
158+
cursor.dispose();
157159
sourceImage.dispose();
158160

159161
assertThrows("No exception thrown when ImageDataProvider is null",

0 commit comments

Comments
 (0)