tags:

views:

111

answers:

1

I'm trying to write some simple code to resize an image, and I am getting a JVM crash. As far as I can tell I'm using the APIs correctly. Here is the code:

import java.awt.image.*;
import java.io.*;
import javax.imageio.*;

public class Resizer {
  public static void main(String[] args) {
    BufferedImage img = null;
    try {
      img = ImageIO.read(new File("C:\\Users\\Owner\\Desktop\\export\\10.jpg"));
    } catch (IOException e) {
      System.out.println(e);
      return;
    }
    RescaleOp ro = new RescaleOp(1.25f, 0.0f, null);
    BufferedImage output = ro.filter(img, null); //JVM CRASHES ON THIS LINE

    // Also crashes if I use these lines instead:
    //BufferedImage output = ro.createCompatibleDestImage(img, img.getColorModel());
    //ro.filter(img, output);

    try {
      ImageIO.write(output, "png", new File("C:\\Users\\Owner\\Desktop\\export\\10.output.png"));
    } catch (IOException ioe) {
      System.out.println(ioe);
      return;
    }
  }
}

And I'm getting this error:

#
# An unexpected error has been detected by Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d524c5d, pid=13076, tid=11172
#
# Java VM: Java HotSpot(TM) Client VM (10.0-b23 mixed mode windows-x86)
# Problematic frame:
# C  [mlib_image.dll+0x54c5d]
#
# An error report file with more information is saved as:
# C:\Users\Owner\Documents\src\Java\ImageSizer\hs_err_pid13076.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
+2  A: 

This is most likely a bug in the JVM, as typically only native code can crash the JVM and it doesn't look like you're using any 3rd party stuff. You're not the only person that experienced this problem. See this message and the responses to it. See, in particular, this message that may help you do what you're trying to do without this JVM crash.

This is a known issue. See Sun Bug ID 4886506 for the details. The Sun bug report contains a workaround that may help you. It looks like this bug was fixed in JDK 7.

Eddie