Bug 47171

Summary: Should never use Error to report runtime errors
Product: Batik - Now in Jira Reporter: Sebb <sebb>
Component: GVTAssignee: Batik Developer's Mailing list <batik-dev>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: 1.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Sebb 2009-05-08 15:57:11 UTC
TIFFImageEncoder uses Error to report unexpected conditions, e.g.

        switch(dataType) {
        case DataBuffer.TYPE_BYTE:
            if(sampleSize[0] != 1 && sampleSize[0] == 4 &&
               sampleSize[0] != 8) {
                throw new Error("TIFFImageEncoder2");
            }
            break;

Using Error makes it hard to safely catch the exception, as there are some Errors that should not be caught (e.g. ThreadDeath)

The code should use a more specific Error, e.g. RuntimeException or IllegalArgumentException or InvalidParameterException.

There are over 70 classes where Error is thrown - please can these be changed to something more appropriate?
Comment 1 Helder Magalhães 2009-05-09 00:19:46 UTC
(In reply to comment #0)
> TIFFImageEncoder uses Error to report unexpected conditions, e.g.

Although not very familiar with this, regarding this specific class I'd say there's pending effort into using XML Graphics Commons [1] for the task (this implementation should be abandoned in favor of a more compatible one (see bug 38183 and bug 46513).


> Using Error makes it hard to safely catch the exception, as there are some
> Errors that should not be caught (e.g. ThreadDeath)
[...]
> There are over 70 classes where Error is thrown [...]

I haven't dig up on this enough but, for what it's worth, I'd vote on this also. :-)


[1] http://xmlgraphics.apache.org/commons/#features
Comment 2 Sebb 2009-05-09 03:09:30 UTC
Thanks, did not know about that project.
I've just had a look at the XML Graphics Commons version and that also uses Error with rather cryptic messages, so that part has obviously not been addressed.