JDK-6199984 : Printing from Java Applet fails in JRE 142_04 on Solaris/Netscape
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 1.4.2_04
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_9
  • CPU: generic
  • Submitted: 2004-11-24
  • Updated: 2011-02-16
  • Resolved: 2004-12-03
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
From an Applet, trying to do a print using PrintJob.getGraphics() returns 'null'. This happens in Solaris and not in Windows. The same code works fine when running as Application on Solaris.

Code snippet:
  //Inside an action handler of a Frame created from Applet
  PrintJob pj = getToolkit().getPrintJob(this, "Test Print", null);
  if(pj == null) return;
  Graphics g = pj.getGraphics();  // <== NULL 

Testcase is in the attachment of this bug. Open the demoDefault.html in Netscape browser on Solaris. Click on the Print button from the Frame, which brings up 'Confirmation Needed - Print' dialog (for the 1st time). Click the Yes button to continue, which brings up the 'Print' dialog. Click the OK button to print. Open the Java Console and see java.lang.NullPointerException being thrown.


Comments
EVALUATION On unix platform, calling sun.awt.motif.MToolkit.getPrintJob() would show the printDilaog and internally UnixPrintServiceLookup tries to create a temp file to get all the available printer names. When running as application it works fine but as an applet the code throws java.lang.SecurityException, which is caught internally and returned as 'null'. Looking at the history, there was another problem being addressed with bug id 4673221. ###@###.### 2004-11-25 03:36:42 GMT This isn't strictly a bug in plug-in, and its in fact a duplicate of 4930594 ###@###.### 2004-11-26 20:17:43 GMT
25-11-2004

SUGGESTED FIX Thilak from sustaining knows a fix for these. ###@###.### 2004-11-24 15:20:28 GMT The output from the command has to be read from the stream insteadof redirecting to a temp file. But should start reading output before waiting for the command to exit. The wait is also required to get the exit status. file: 142/j2se/src/solaris/classes/sun/print/UnixPrintServiceLookup.java static String[] execCmd(String command) { ... if(lpstat != null){ BufferedReader buf = new BufferedReader( new InputStreamReader(lpstat.getInputStream()), 24); String line; if(buf != null){ while((line=buf.readLine()) != null){ results.add(line); } } lpstat.waitFor(); if(lpstat.exitValue() != 0){ reslutls.clear(); } } ... return (String[])results.toArray(new String[results.size()]); } ###@###.### 2004-11-25 03:36:42 GMT
24-11-2004