Class org.apache.ws.jaxme.xs.parser.impl.LocSAXException (or a some superclass) does not include the class name in the result of toString().

Since the normal toString() behavior is to include the class name
(the Throwable.toString() does that and virtually every exception
class leaves that behavior intact), suppressing the class name is
non-standard, confusing, and simply bad.


For example, for a LocSAXException wrapping an IllegalStateException, the stack trace starts with:

  Exception in thread "main" java.lang.IllegalStateException: ...

making it look like an IllegalStateException was thrown.  If you
try to catch IllegalStateException, you don't catch the exception
(since what is thrown is really something else).


Attached in a test program that demonstrates this behavior (until another JaxMeXs bug this test program exploits is fixed).

This applies to JaxMeXS in JaxMe 0.3.1, 0.4 beta, and the 0.4 CVS
version as of 2005-05-16.

Daniel



package test;

import org.apache.ws.jaxme.xs.*;
import org.apache.ws.jaxme.xs.parser.*;
import org.apache.ws.jaxme.xs.xml.*;
import org.xml.sax.*;
import javax.xml.parsers.ParserConfigurationException;


import java.io.*;

public class CheckBug_OverriddenExceptionToString
{


    public static void main( String[] args )
        throws Exception
    {
        System.err.println( "Checking bug: LocSAXException hides its 
identity..." );
        // Using a bug in JaxMeXS 0.3.1, 0.4 beta, and 0.4 CVS as of 2005-05-16
        // to show exception bug:
        
        String schemaContent =
            ""
            + "<?xml version=\"1.0\" encoding=\"UTF-8\"?> "
            + "<xsd:schema "
            + "  xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"; "
            + "  xmlns:xsdi=\"http://www.w3.org/2001/XMLSchema-instance\"; "
            + "  xsdi:schemaLocation=\"http://www.w3.org/2001/XMLSchema "
            + "  http://www.w3.org/2001/XMLSchema.xsd\"; "
            + "  > "
            + "  <xsd:complexType name=\"complexType-complex-rest.\"> "
            + "    <xsd:complexContent> "
            + "      <xsd:extension base=\"xsd:anyType\"> "
            + "      </xsd:extension> "
            + "    </xsd:complexContent> "
            + "  </xsd:complexType> "
            + " "
            + "</xsd:schema> "
            ;

            InputSource source = 
                new InputSource( new ByteArrayInputStream( 
                                     schemaContent.getBytes( "ASCII" ) ) );
            source.setSystemId( "someScheme://x/whatever");

            /**
               Symptom:  Exception toString() and stack dump start with
               "...IllegalStateException, but catching IllegalStateException
               doesn't catch it since it's really a LocSAXException (that
               wraps the IllegalStateException) that overrides toString()
               and misleadingly hides the fact that it's a LocSAXException.
               
             */
            XSParser parser = new XSParser();
            try {
                XSSchema schema = parser.parse( source );
                System.err.println( 
                    "Parser bug used to show LocSAXException bug has changed."
                    );
            }   
            catch ( IllegalStateException e ) {
                System.err.println( "behavior has changed" );
            }
            catch ( Exception e ) {
                System.err.println( "e = " + e  );
                System.err.println( "e.getClass() = " + e.getClass() );


                if ( e.toString().startsWith( 
                         "java.lang.IllegalStateException: " ) ) {
                    System.err.println( "bug still exists" );
                }
                else {
                    System.err.println( "behavior has changed" );
                    if ( -1 != e.toString().indexOf( e.getClass().getName() ) ) 
{
                        System.err.println( "(bug seems to be fixed)" );
                    }
                    else {
                    }
                }
                throw e;
            }



                
    } // main(...)


} // class CheckBug_OverriddenExceptionToString

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to