Page 1 of 1

NullPointerException when using CompareCmd via Im4java

Posted: 2013-09-07T18:54:31-07:00
by benze
I'm trying to use the CompareCmd from im4java. When I try it with 2 identical images, the command works properly. When I try with 2 different images (same dimensions), I get an NPE. However, if I output the command to a script using cmd.createScript(), and run the script, it executes properly.

Is this an ImageMagick error/bug, or an Im4Java bug/error? To my knowledge, Im4Java just executes ImageMagick so I am not sure where to post this question.

My code:

Code: Select all

        
        ArrayListErrorConsumer stderr = new ArrayListErrorConsumer();
        IMOperation op = new IMOperation();
        op.metric("AE");
        op.addImage(croppedSource.getAbsolutePath());
        op.addImage(result.getAbsolutePath());
        op.addImage("null:");
        cmd.setErrorConsumer(stderr);
        // execute the operation
        cmd.createScript("/tmp/myscript.sh",op);
        cmd.run(op);
I get the following Error (no stack trace that helps me)

Code: Select all

org.im4java.core.CommandException: java.lang.NullPointerException
	at org.im4java.core.ImageCommand.run(ImageCommand.java:219)
	at dame.action.graphic.CropImageTaskImplTest.doTask(CropImageTaskImplTest.java:114)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
	at org.im4java.core.ImageCommand.finished(ImageCommand.java:252)
	at org.im4java.process.ProcessStarter.run(ProcessStarter.java:314)
	at org.im4java.core.ImageCommand.run(ImageCommand.java:215)
	... 25 more

I'm trying to debug this, but am having difficulty tracking down the error. Is this an Im4Java error or a problem with ImageMagick?

Thanks,

Eric

Re: NullPointerException when using CompareCmd via Im4java

Posted: 2013-09-08T22:15:23-07:00
by dlemstra
It is a bug in im4java. In line 252 of ImageCommand.java there is no check if iErrorText is null.

Code: Select all

  protected void finished(int pReturnCode) throws Exception {
    if (pReturnCode > 0) {
      CommandException ce;
      if (iErrorText.size() > 0) { // this line
	ce = new CommandException(iErrorText.get(0));
I think that your statement 'cmd.setErrorConsumer(stderr);' is causing this.