mr-sun / hamcrest

Hamcrest matchers for c++ (using with carnamock)
0 stars 0 forks source link

Exception from String.valueOf() in BaseDescription makes some Exceptions un-reportable. #184

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In org.hamcrest.BaseDescription, the method appendValue will fail with an 
exception if String.valueOf throws an exception.

This cause the JUnit test to fail with the not very helpful message: "Exception 
in 'main'".

This makes an expectation failure almost impossible to track down (with out 
sitting in the debugger) if the reporting of that failure also causes an 
expectation failure.  This is simple to encounter if an object involved has a 
non-trivial toString method that runs into an expectation error.

The appendValue method needs to rap the String.valueOf with a catch(Throwable) 
and report in some safe way that toString caused an error.  Otherwise, trying 
to report an exception causes that same exception to be thrown again.

Example below:

        } catch (Throwable t) {
            try {
                System.out.println(t);
            } catch (Throwable t2) {
                //here: t2==t, thus the exception cant be logged.
                System.out.println(t2);
            }
        }

Original issue reported on code.google.com by chris.h...@hcs.us.com on 23 May 2012 at 6:10

GoogleCodeExporter commented 8 years ago

Original comment by t.denley on 23 May 2012 at 10:08

GoogleCodeExporter commented 8 years ago
I've addressed this on commit 
https://github.com/hamcrest/JavaHamcrest/commit/6d06cb384f253a5d01e1cf74ff4b938f
713ca6fd

Original comment by t.denley on 31 May 2012 at 8:04