diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/SWTFontProvider.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/SWTFontProvider.java index 235cd48aafa..7312a5acb20 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/SWTFontProvider.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/SWTFontProvider.java @@ -74,6 +74,9 @@ public static long getFontHandle(Font font, int zoom) { if (font == null) { SWT.error(SWT.ERROR_NULL_ARGUMENT); } + if (font.isDisposed()) { + return 0; + } return Font.win32_getHandle(getFont(font.getDevice(), font.getFontData()[0], zoom)); } diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Canvas.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Canvas.java index 2b4e2315393..9eade51b27f 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Canvas.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Canvas.java @@ -108,6 +108,17 @@ public void test_setFontLorg_eclipse_swt_graphics_Font() { font.dispose(); } +@Test +public void test_CaretWithDisposedFontDoesNotThrowException_issue2323() { + Caret caret = new Caret(canvas, SWT.NONE); + Font font = new Font(canvas.getDisplay(), "Default", 10, SWT.BOLD); + shell.open(); + caret.setFont(font); + font.dispose(); + canvas.setFocus(); + canvas.setCaret(caret); +} + /* custom*/ @Test public void test_consistency_MenuDetect() {