Project: SWT
Bug 301863 NPE in PrintDialog
Reported: 2010-02-04 12:28:00 | Status: resolved fixed

Windows has code in setPrinterData to ensure that the printerData instanceVariable is never null. This code is missing on every other platform. missing line is in setPrinterData -> if (data == null) data = new PrinterData(); example of NPE from trying to print on Cocoa. java.lang.NullPointerException at org.eclipse.swt.printing.PrintDialog.open(PrintDialog.java:157) at org.eclipse.jface.text.TextViewer.print(TextViewer.java:4516) at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor$11.run(AbstractDecoratedTextEditor.java:1334) at org.eclipse.jface.action.Action.runWithEvent(Action.java:498) at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:185) at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:109) at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476) at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508) at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:470) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:824) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:880) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:569) at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:510) at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:125) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1026) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3705) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1314) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1337) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1322) at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1351) at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1347) at org.eclipse.swt.widgets.Canvas.sendKeyEvent(Canvas.java:440) at org.eclipse.swt.widgets.Control.doCommandBySelector(Control.java:914) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4929) at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method) at org.eclipse.swt.internal.cocoa.NSResponder.interpretKeyEvents(NSResponder.java:56) at org.eclipse.swt.widgets.Composite.keyDown(Composite.java:515) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4839) at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method) at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:209) at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:1890) at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:1983) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4901) at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method) at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:4467) at org.eclipse.swt.widgets.Display.applicationProc(Display.java:4544) at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method) at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:105) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3221) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2407) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2371) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2220) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:367) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:611) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:566) at org.eclipse.equinox.launcher.Main.run(Main.java:1363)

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT Printing/carbon/org/eclipse/swt/printing/PrintDialog.java bundles/org.eclipse.swt/Eclipse SWT Printing/cocoa/org/eclipse/swt/printing/PrintDialog.java bundles/org.eclipse.swt/Eclipse SWT Printing/emulated/org/eclipse/swt/printing/PrintDialog.java bundles/org.eclipse.swt/Eclipse SWT Printing/gtk/org/eclipse/swt/printing/PrintDialog.java bundles/org.eclipse.swt/Eclipse SWT Printing/motif/org/eclipse/swt/printing/PrintDialog.java bundles/org.eclipse.swt/Eclipse SWT Printing/photon/org/eclipse/swt/printing/PrintDialog.java bundles/org.eclipse.swt/Eclipse SWT Printing/wpf/org/eclipse/swt/printing/PrintDialog.java