I reacently had problems using Java Advanced Imaging (JAI).
Here is the simplified version of the problem:
SomeClass c = (SomeClass) obj.getSomeClassParent()
not always but it happens sometimes to trigger exception
org.somepackage.SomeClass can't be cast to org.somepackage.SomeClass
Original code
ImageInputStream iis = ImageIO.createImageInputStream(src);
Iterator<ImageReader> iter =
ImageIO.getImageReadersByFormatName("DICOM");
ImageReader reader = iter.next();
DicomImageReadParam param =
(DicomImageReadParam) reader.getDefaultReadParam();
And the original exception
org.dcm4che2.imageio.plugins.dcm.DicomImageReadParam
can't be cast to org.dcm4che2.imageio.plugins.dcm.DicomImageReadPara
The problem was that I was missing that sometime the class is loaded by different class loader
and it can happen that the casted class is not the same whit the one form the default class loader.
The question on StackOverflow
Posted by Andon Sikavica on January 14, 2010 at 09:55 PM CET #