-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
5.0
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
If scaling an graphics object to scale (0,0) for a JPanel (or probably any component) it does, as expected, not paint. The NPE that is thrown from sun.java2d.SunGraphics2D.getClipBounds(SunGraphics2D.java:1605) is not expected however.
One solution would be that a graphics object would not accept an AffineTransform with zero scale, throwing an IllegalArgumentException with relevant explanation (much better than the current seemingly unrelated NPE).
Another solution would be to paint at scale 0, i.e. not paint at all.
The latter suggestion would be on par with how other "inivisible" items are painted (i.e. by setting the scale to (epsilon, epsilon) for instance), i.e. not painted at all but without a NPE.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run provided example code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A JFrame showing nothing (in this particular case).
ACTUAL -
A stacktrace.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.java2d.SunGraphics2D.getClipBounds(SunGraphics2D.java:1605)
at javax.swing.JComponent.paint(JComponent.java:961)
at test.TestFrame$1.paint(TestFrame.java:15)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
at java.awt.Container.paint(Container.java:1709)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)
at java.awt.Component.dispatchEventImpl(Component.java:4031)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Window.dispatchEventImpl(Window.java:1778)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
public class TestFrame {
public static void main(String arg[]) {
JPanel panel = new JPanel() {
public void paint(Graphics g) {
((Graphics2D) g).scale(0,0);
super.paint(g);
}
};
Frame f = new Frame();
f.setLayout(new BorderLayout());
f.add(panel, BorderLayout.CENTER);
f.setSize(400,300);
f.setVisible(true);
}
}
---------- END SOURCE ----------
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
If scaling an graphics object to scale (0,0) for a JPanel (or probably any component) it does, as expected, not paint. The NPE that is thrown from sun.java2d.SunGraphics2D.getClipBounds(SunGraphics2D.java:1605) is not expected however.
One solution would be that a graphics object would not accept an AffineTransform with zero scale, throwing an IllegalArgumentException with relevant explanation (much better than the current seemingly unrelated NPE).
Another solution would be to paint at scale 0, i.e. not paint at all.
The latter suggestion would be on par with how other "inivisible" items are painted (i.e. by setting the scale to (epsilon, epsilon) for instance), i.e. not painted at all but without a NPE.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run provided example code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A JFrame showing nothing (in this particular case).
ACTUAL -
A stacktrace.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.java2d.SunGraphics2D.getClipBounds(SunGraphics2D.java:1605)
at javax.swing.JComponent.paint(JComponent.java:961)
at test.TestFrame$1.paint(TestFrame.java:15)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
at java.awt.Container.paint(Container.java:1709)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)
at java.awt.Component.dispatchEventImpl(Component.java:4031)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Window.dispatchEventImpl(Window.java:1778)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
public class TestFrame {
public static void main(String arg[]) {
JPanel panel = new JPanel() {
public void paint(Graphics g) {
((Graphics2D) g).scale(0,0);
super.paint(g);
}
};
Frame f = new Frame();
f.setLayout(new BorderLayout());
f.add(panel, BorderLayout.CENTER);
f.setSize(400,300);
f.setVisible(true);
}
}
---------- END SOURCE ----------
- relates to
-
JDK-4264298 null pointer exception at hitClip() and getClipBounds(Rectangle) of Graphics
-
- Resolved
-