JDK-5083478 : Unable to print Java applets(with charts) thru Solaris version of j2re1.4.2_04
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.2_04
  • Priority: P5
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2004-08-05
  • Updated: 2016-07-18
  • Resolved: 2016-07-18
Related Reports
Relates :  
Description
Unable to print Java applets(with charts) thru Solaris version of j2re1.4.2_04
==============================================================================

While using Jpanel.printComponents(Graphics) in JPI1.4.2_04, the print is not 
working but while trying to  use Jpanel.print(Graphics) or 
Jpanel.printAll(Graphics) , it is working fine. Basically the problem is 
observed while printing the Chart thru java applets using j2re1.4.2_04.


But j2re1.4.2_04  is  working fine  in windows. The problem is coming only 
while using j2re1.4.2_04 in solaris


The following code segment is not working in solaris version of j2re1.4.2_04

***********************************************************************************
 public void print (Graphics page, Dimension pSize)
   {

       Component compList[] = _summaryPanel.getComponents();
       Image scaleImg;
       int height = (pSize.height - 160) / 3;
       int ycoord = 110;

       page.setColor (Color.gray);

       // Rsp Time Section
       page.drawLine (  0,  ycoord, 250, ycoord);
       page.drawLine (370,  ycoord, pSize.width, ycoord);
       page.setColor (Color.black);
       page.drawString (PropHandler.PROPS.getGUIStr("rspTimes"),250, 
ycoord+3);
       page.translate (-29, ycoord + 7);
       ((JPanel)compList[0]).printComponents (page);
       page.translate (29, -(ycoord+7));
       scaleImg = _rspTimeChart.snapshot().getScaledInstance (
                               pSize.width - compList[0].getSize().width 
+ 43,
                               height, Image.SCALE_SMOOTH);
      page.drawImage (scaleImg, compList[0].getSize().width - 50,
                       ycoord + 6, null); */

       // Error Section
       ycoord += height + 15;
       page.setColor (Color.gray);
       page.drawLine (0, ycoord, 270, ycoord);
       page.drawLine (310, ycoord, pSize.width, ycoord);
       page.setColor (Color.black);
       page.drawString (PropHandler.PROPS.getGUIStr("errors"), 270, 
ycoord+3);
       page.translate (5, ycoord+7);
        PropHandler.PROPS.displayErrorMsg((Frame)this.getTopLevelAncestor(), 
"In Error Section , Before printComponents");
       ((JPanel)compList[2]).printComponents (page);
       page.translate (-5, -(ycoord+7));
       scaleImg = _errChart.snapshot().getScaledInstance (
                               pSize.width - compList[2].getSize().width - 3,
                               height, Image.SCALE_SMOOTH);
       page.drawImage (scaleImg, compList[2].getSize().width - 3,
                       ycoord + 6, null);  */

       // Threshold Section
       ycoord += height + 20;
       page.setColor (Color.gray);
       page.drawLine (  0, ycoord, 250, ycoord);
       page.drawLine (379, ycoord, pSize.width, ycoord);
       page.setColor (Color.black);
       page.drawString (PropHandler.PROPS.getGUIStr("thrsSummary"),
                        250, ycoord+3);
       page.translate (5, ycoord+30);
       ((JPanel)compList[4]).printComponents (page);
       page.translate (-5, -(ycoord+30));
       scaleImg = _thrsChart.snapshot().getScaledInstance (
                               pSize.width - compList[4].getSize().width - 3,
                               height, Image.SCALE_SMOOTH);
      /* page.drawImage (scaleImg, compList[4].getSize().width - 3, 
ycoord + 6,
                       null); */

       page.dispose();
   }
***********************************************************************************
========
Unable to attach the testcase in the bugtraq. The tar
file is in
 /net/oasis.west.sun.com/export/scratch/manish/customers/cisco/calls/829098/printDemo.tar

With the testcase provided by PTS (printdemo.tar):

When running with 1.4.2_04 sol-sparc it gives the following exception and
prints few text components. (open the ps/prn file in ghostviewer).
With 1.3.1_09 sol-sparc it works fine without any exception.
With 1.4.2_06 win-i586 it works fine without any exception.

java.lang.NullPointerException
        at java.awt.geom.Area.<init>(Area.java:54)
        at sun.print.PSPathGraphics.drawImageToPS(PSPathGraphics.java:1020)
        at sun.print.PSPathGraphics.drawImage(PSPathGraphics.java:495)
        at sun.print.PSPathGraphics.drawImage(PSPathGraphics.java:406)
        at sun.print.PSPathGraphics.drawImage(PSPathGraphics.java:345)
        at sun.print.PSPathGraphics.drawImage(PSPathGraphics.java:288)
        at sun.print.PSPathGraphics.drawImage(PSPathGraphics.java:197)
        at sun.print.ProxyGraphics.drawImage(ProxyGraphics.java:814)
        at DemoScroller.print(DemoScroller.java:230)
        at DemoFrame.actionPerformed(DemoFrame.java:177)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
        at java.awt.Component.processMouseEvent(Component.java:5100)
        at java.awt.Component.processEvent(Component.java:4897)
        at java.awt.Container.processEvent(Container.java:1569)
        at java.awt.Component.dispatchEventImpl(Component.java:3615)
        at java.awt.Container.dispatchEventImpl(Container.java:1627)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
        at java.awt.Container.dispatchEventImpl(Container.java:1613)
        at java.awt.Window.dispatchEventImpl(Window.java:1606)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

###@###.### 2004-08-31
========================================
To run the test case:
% java -classpath "demo.jar:jcchart362J.jar" DemoFrame 

###@###.### 2004-09-02
========================================

Comments
With jdk9, the testcase present in demo.jar and jcchart362.jar results in Exception in thread "main" java.lang.NoSuchMethodError: java.awt.Component.getPeer()Ljava/awt/peer/ComponentPeer; at jclass.chart.ChartText.recalc(ChartText.java:517) at jclass.chart.JCTitle.recalc(JCTitle.java:283) at jclass.chart.ChartText.setParent(ChartText.java:631) at jclass.chart.JCChart.init(JCChart.java:443) at jclass.chart.JCChart.<init>(JCChart.java:576) at Demo_RTChart.<init>(Demo_RTChart.java:71) at Demo_RTChart.<init>(Demo_RTChart.java:61) at Demo_RTChart.<init>(Demo_RTChart.java:42) at DemoScroller.createNormalChart(DemoScroller.java:192) at DemoScroller.<init>(DemoScroller.java:73) at DemoFrame.<init>(DemoFrame.java:40) at DemoFrame.main(DemoFrame.java:254) Also, it seems it was mentioned "Submitter agreed to marking this bug fixed in Tiger."
18-07-2016

EVALUATION With the j2se source code, a call to java.awt.Container.printComponents() is similar to javax.swing.JComponent.printAll(). In both cases, the components are taken from the Component component[] array of java.awt.Container class. And on each component of the array a call to printAll() is made. Otherwise the bug also resembles the bug # 4968560, where the print issue was due to printer thread's immature termination. To clarify the things to the root cause, we need more information as Phil has mentioned down. ###@###.###/jwsse-java-apac Aug-11-2004 ---------------------------------------------------------- Its really hard to say for sure from this snippet, and the description what the problem is. We need an example that can be run. Also "not working" is far too vague. Does the job not print? Or is some of it missing or incorrect? Looking at the code there is one thing that is incorrect in the code and could lead to missing output. The majority of the output on the page is 2 images. These images are obtained using getScaledInstance(). The javadoc for getScaledInstance states "The new Image object may be loaded asynchronously even if the original source image has already been loaded completely." This means the return value from getScaledInstance must be passed to a MediaTracker instance, and that MediaTracker used to determine when that image is fully loaded. This is particularly important in applets where one might expect that original source image to be reloaded from a URL. Failure to do this could (depending on luck and details of the implementation) apparently work sometimes and fail other times. Thus it appears that this code is buggy and could fail at any time. Given the statement that this bug's manifestation is distinguished by using printComponents vs printAll, then this could be a red herring, but nonetheless the code doesn't look safe, unless there is something elsewhere that has ensured that the original image is loaded first (ie what does getSnapShot() do?) So it is important to ensure the image is loaded, which can be done by using MediaTracker to wait for the image to be fully loaded. For information on using MediaTracker see : http://java.sun.com/j2se/1.4.2/docs/api/java/awt/MediaTracker.html Marking this bug incomplete until 1) A fuller description of the observed behaviour is added. 2) A corrected and complete test case which can (still) demonstrate the problem is added to the bug report. ###@###.### 2004-08-09 ============================ ###@###.### 2004-08-12 ============================== Submitter agreed to marking this bug fixed in Tiger. ###@###.### 2004-08-16 ==================================================== The stack trace :- java.lang.NullPointerException at java.awt.geom.Area.<init>(Area.java:54) at sun.print.PSPathGraphics.drawImageToPS(PSPathGraphics.java:1020) This can only be caused if the clip on the graphics is null. Its not normally null, probably should see how that occured Easy enough to check for though and then there's no need to do the intersection. I am surprised this didn't reproduce on 1.3.1 as all the relevant printing code and the code in the Area class are the same. So it seems like the clip was non-null then? Also the code is *still* unchanged in 1.5, so we really need to understand why it doesn't manifest on 1.5. It looks as if the vulnerability is there. There may also be a workaround for the app if it is responsible for setting the clip to null, it could do something different. ###@###.### 2004-08-31 ============================ sathianantha.thilagar confirmed this is reproducible in tiger. Removed fixed/integrated status. ###@###.### 2004-09-02 =================================== Test case was using Graphics.setClip(null), which triggers the NullPointerException while printing. Java API documentation do mention about Graphics.setClip(Shape s) API argument restriction. It can either use the value returned by Graphics.getClip() or has to be an instance of java.awt.Rectangle. The test case has to be changed to not pass a 'null' argument to setClip method. This can be assumed as NOT A BUG. ###@###.### 2004-09-10 ----------------------------------------- The applet should be a signed one to print from an unix platform. The reason being - unix has commands (which are executables like lpstat) to manipulate the printers. Whereas MS Windows provides API to access printers. To access local machine resources like printer, file the applet should be granted with such privileges. This can be done via a signed applet. ###@###.### 2004-10-05 ----------------------------------------- ###@###.### 10/5/04 13:41 GMT
05-10-2004