-
Bug
-
Resolution: Fixed
-
P4
-
1.1.1, 1.4.0, 1.4.1, 1.4.2
-
tiger
-
x86
-
linux, windows_2000, windows_xp
Name: rmT116609 Date: 08/12/2003
FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
jai-1_1_2-lib-linux-i586-jdk.bin installed
FULL OS VERSION :
Linux moo-hf 2.4.18 #2 SMP Mon May 20 19:08:12 EST 2002 i686 unknown
A DESCRIPTION OF THE PROBLEM :
Cropping an image to height or width of zero or less causes a NullPointerException, when attempting to draw the image or waitFor the image if the image is loaded via JAI, but not if the image is loaded via the awt Toolkit.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program with the name of any image file as the parameter.eg:
java Bug *.jpg
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Four windows should open titled:
Toolkit load
Toolkit crop
JAI load
JAI crop
The cropped windows should be empty the load image should contain the image, if the image is supported (eg a TIFF image will appear in the JAI load window but not in the Toolkit load window). (guess who is trying to add TIFF support to an existing application).
ACTUAL -
The JAI crop window does not appear. Instead a NullPointerException is thrown.
The application works as expected if the crop parameters are all positive.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java Bug *.jpg
Warning: Cannot convert string "-monotype-arial-regular-r-normal--*-140-*-*-p-*-iso8859-1" to type FontStruct
Exception in thread "main" java.lang.NullPointerException
at sun.awt.image.OffScreenImageSource.sendPixels(OffScreenImageSource.java:142)
at sun.awt.image.OffScreenImageSource.produce(OffScreenImageSource.java:161)
at sun.awt.image.OffScreenImageSource.addConsumer(OffScreenImageSource.java:37)
at sun.awt.image.OffScreenImageSource.startProduction(OffScreenImageSource.java:51)
at java.awt.image.FilteredImageSource.startProduction(FilteredImageSource.java:116)
at sun.awt.image.ImageRepresentation.startProduction(ImageRepresentation.java:644)
at sun.awt.image.Image.addWatcher(Image.java:197)
at sun.awt.image.Image.getProperty(Image.java:145)
at javax.swing.ImageIcon.<init>(ImageIcon.java:161)
at Bug.showImage(Bug.java:15)
at Bug.main(Bug.java:47)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class Bug {
static Component component = new JLabel("");
public static void showImage(Image image, String title) {
if (null == image)
return;
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JLabel label = new JLabel(new ImageIcon(image));
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
}
public static Image cropImage(Image image) {
return component.createImage(new FilteredImageSource(image.getSource(),
new CropImageFilter(100,
100,
0,
100)));
}
public static void main(String[] args) {
Image image;
Image croppedImage;
for (int i = 0; i < args.length; i++) {
image = Toolkit.getDefaultToolkit().createImage(args[i]);
showImage(image, "Toolkit load");
croppedImage = cropImage(image);
showImage(croppedImage, "Toolkit crop");
image = javax.media.jai.JAI.create("fileload", args[i]).getAsBufferedImage();
showImage(image, "JAI load");
croppedImage = cropImage(image);
showImage(croppedImage, "JAI crop");
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Explicitly checking crop bounds before cropping.
As the cropping is done deep in a set of libraries I am using, rather in my own code, this is difficult to work around.
(Incident Review ID: 193089)
======================================================================
- duplicates
-
JDK-4780802 ImageIcon.setImage throwing NullPointerException on Image.getScaledInstance
-
- Closed
-