Skip to main content

vendorName == null!

1 reply [Last post]
jstroop
Offline
Joined: 2009-07-29

Greetings,
I am trying to extract the XMP metadata from TIFF headers as part of a larger application. While debugging and running unit tests everything works fine. However, when the application is included in a jar, I receive the following:

Exception in thread "main" java.lang.reflect.InvocationTargetException
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.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: sun.misc.ServiceConfigurationError: javax.imageio.spi.ImageReaderSpi: Provider com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReaderSpi could not be instantiated: java.lang.IllegalArgumentException: vendorName == null!
at sun.misc.Service.fail(Service.java:120)
at sun.misc.Service.access$200(Service.java:111)
at sun.misc.Service$LazyIterator.next(Service.java:276)
at javax.imageio.spi.IIORegistry.registerApplicationClasspathSpis(IIORegistry.java:190)
at javax.imageio.spi.IIORegistry.(IIORegistry.java:121)
at javax.imageio.spi.IIORegistry.getDefaultInstance(IIORegistry.java:142)
at javax.imageio.ImageIO.(ImageIO.java:48)
at edu.princeton.diglib.Util.XMPExtrator.main(XMPExtrator.java:29)
... 5 more
Caused by: java.lang.IllegalArgumentException: vendorName == null!
at javax.imageio.spi.IIOServiceProvider.(IIOServiceProvider.java:59)
at javax.imageio.spi.ImageReaderWriterSpi.(ImageReaderWriterSpi.java:214)
at javax.imageio.spi.ImageReaderSpi.(ImageReaderSpi.java:192)
at com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReaderSpi.(CLibJPEGImageReaderSpi.java:80)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at sun.misc.Service$LazyIterator.next(Service.java:271)
... 10 more

"vandorName == null!" is what jumps out at me. I'm relatively new to Java, and completely new to the JAI classes. Here's a summary a what my code does:

package edu.princeton.diglib.Util;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.stream.ImageInputStream;

import com.sun.media.imageio.plugins.tiff.TIFFDirectory;

public class MdExtrator {
public static void main(String[] args) throws IOException {

ImageInputStream iis = null;
iis = ImageIO.createImageInputStream(new File("/path/to/a.tif"));

Iterator readers;
readers = ImageIO.getImageReadersByMIMEType("image/tiff");
ImageReader image = (ImageReader) readers.next();
image.setInput(iis);

IIOMetadata md = image.getImageMetadata(0);
TIFFDirectory tiffDir = TIFFDirectory.createFromMetadata(md);
String xmp = new String(tiffDir.getTIFFField(700).getAsBytes());
xmp = xmp.replaceAll("<\\?.*\\?>", "").trim();

System.out.println(xmp);

iis.close();
}
}

Any help would be greatly appreciated!
Regards,
Jon

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tizzo
Offline
Joined: 2006-03-08

I'm troubleshooting something similar, in my case related to trying to use the jai_imageio plugins from inside Eclipse. I can probably at least get you started.

The stack trace indicates that a subclass of ImageReaderSpi is trying to instantiate itself with a vendor name set to null. This is clearly a no-no from the ImageReaderSpi javadoc. I ended up using the often useful java2s.com web site to track this down. The site has what looks like the source code for all classes in the JDK. It is clearly not the real source code, and I'm not sure if it is reverse engineered from the binaries, or is based on some kind of open source clone. (I'm sure it's easy to find out where it comes from, but I've never been curious enough to try to find out).

Anyway, the class in question is CLibJPEGImageReaderSpi (presumably because this is the first one found), so I looked at java2s's page on this classes source code, found here:

http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Modules/Java-Adv...

It's clear enough that this class is instantiating itself by invoking super(...), which is ImageReaderSpi(...), with the value of PackageUtil.getVendor() passed in as the value of vendor.

Now, I had a slight advantage over you, because I'm using Eclipse, and in Eclipse the scan process employed by ImageIO API to discover SPIs doesn't happen automatically, I had to trigger it. This gave me the opportunity to peek into what PackageUtil.getVendor() is returning, and in my case it is indeed null. So this sent me back to java2s.

Although not in the code, referenced classes in the source code are helpfully linked from their import statements. The import statement for PackageUtil links you to the source code for that module at:

http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Modules/Java-Adv...

It gets a little confusing here because in this code, getVendor() returns a string constant, so it should never be null. Fortunately, for reasons I don't understand, there's a comment in this code which contradicts the code itself. It says that the vendor name is discovered from the manifest.

Now in my case, because I had unbundled the API and rebundled it as an Eclipse plugin, Eclipse replace the original manifest information with it's own. When I opened the manifest file and added back in the manifest information Eclipse had stripped out, I found that PackageUtil.getVendor() did in fact return the value in the manifest file, and the remainder of the process completed without any trouble.

Here is the stuff I added to the manifest file to get it to work:

Specification-Title: Java Advanced Imaging Image I/O Tools
Specification-Version: 1.0-mr
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: com.sun.media.imageio
Implementation-Version: 1.0_01
Implementation-Vendor: Sun Microsystems, Inc.
Extension-Name: com.sun.media.imageio

Like I said, I can't solve your problem because your environment differs from mine. My guess would be that for whatever reason, the jar file containing your jai_imageio is missing this information in the META-INF/MANIFEST.MF file, or is missing the manifest altogether. It's at least someplace to start looking. Good luck.

Tony