jai-imageio / jai-imageio-core

JAI ImageIO Core (without javax.media.jai dependencies)
Other
234 stars 87 forks source link

JDK9 throws NumberFormatException #50

Open ptahchiev opened 6 years ago

ptahchiev commented 6 years ago

Hi there,

my code works fine with JDK8, however when I try to run it with JDK9 I get this exception:

Caught and handled this exception :
java.lang.NumberFormatException: For input string: ""
    at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.base/java.lang.Integer.parseInt(Integer.java:662)
    at java.base/java.lang.Integer.parseInt(Integer.java:770)
    at com.github.jaiimageio.impl.common.ImageUtil.processOnRegistration(ImageUtil.java:1401)
    at com.github.jaiimageio.impl.plugins.bmp.BMPImageWriterSpi.onRegistration(BMPImageWriterSpi.java:105)
    at java.desktop/javax.imageio.spi.SubRegistry.registerServiceProvider(ServiceRegistry.java:788)
    at java.desktop/javax.imageio.spi.ServiceRegistry.registerServiceProvider(ServiceRegistry.java:330)
    at java.desktop/javax.imageio.spi.IIORegistry.registerApplicationClasspathSpis(IIORegistry.java:212)
    at java.desktop/javax.imageio.spi.IIORegistry.<init>(IIORegistry.java:136)
    at java.desktop/javax.imageio.spi.IIORegistry.getDefaultInstance(IIORegistry.java:157)
    at java.desktop/javax.imageio.ImageIO.<clinit>(ImageIO.java:66)
    at com.nemesis.platform.module.barcode.core.service.impl.BarcodeServiceImpl.createBarcodeImage(BarcodeServiceImpl.java:102)

The image is rendered however, I just don't like the exception being logged.

Jugen commented 6 years ago

There's a new release 1.4.0 that fixes this.

ptahchiev commented 6 years ago

Pardon my ignorance, but isn't imageio part of JDK? Does that mean that we need to communicate with the JDK team to include the latest release?

Jugen commented 6 years ago

It used to be part of java.net but Oracle shutdown it down about a year ago, if I'm not mistaken. So jai-imageio became orphaned and this is now one of a few efforts to keep it available. (BTW if you needed jai-imageio for TIF images then Java 9 supports TIF now.)

ptahchiev commented 6 years ago

I use it for rendering PNG images:

ImageIO.write(img, "png", baos);

and apparently javax.imageio.ImageIO is class that comes from the JDK

Jugen commented 6 years ago

According to the stack trace you provided above, you have a barcode library by nemises that triggers javax.imageio to register plugins (looking specifically for BMP image writers, I think). So maybe this library is bundled with the nemises barcode library ?

ptahchiev commented 6 years ago

Yep, you are absolutely right:

[INFO] --- maven-dependency-plugin:3.0.2:tree (default-cli) @ samplestore ---
[INFO] com.nemesis.archetype:samplestore:war:2.0.0.BUILD-SNAPSHOT
[INFO] \- com.nemesis.platform.module:nemesis-module-barcode:jar:2.0.0.BUILD-SNAPSHOT:compile
[INFO]    \- com.google.zxing:javase:jar:3.3.2:compile
[INFO]       \- com.github.jai-imageio:jai-imageio-core:jar:1.3.1:runtime
[INFO] ------------------------------------------------------------------------
lbellonda commented 6 years ago

If using Maven, you can exclude the 1.3.1 dependency from barcode module and add the new 1.4.0 in your pom if 1.3.1 and 1.4.0 are binary compatible as I think. You need to test extensively your program.

Hope that helps.

Jugen commented 6 years ago

You can try removing this dependency in zxing/javase/pom.xml as it may not even be needed any more.

https://github.com/zxing/zxing/blob/274159117ac631ef8d48913f22ec48b0bb8d7543/javase/pom.xml#L34-L39

Note that removing the dependency probably won't produce a compile error, but your tests should fail if an image codec is needed that isn't built into Java.