Make exception messages match the ones from OpenJDK/Android

This commit changes the exception message format of
ClassCastException and CloneNotSupportedException.
This commit is contained in:
Simon Ochsenreither 2013-05-14 01:23:03 +02:00
parent 4a69496ab4
commit e088fa07ae
2 changed files with 18 additions and 4 deletions

View File

@ -266,8 +266,13 @@ clone(Thread* t, object o)
reinterpret_cast<void**>(o) + 1, reinterpret_cast<void**>(o) + 1,
size - BytesPerWord); size - BytesPerWord);
} else { } else {
object classNameSlash = className(t, objectClass(t, o));
PROTECT(t, classNameSlash);
THREAD_RUNTIME_ARRAY(t, char, classNameDot, byteArrayLength(t, classNameSlash));
replace('/', '.', RUNTIME_ARRAY_BODY(classNameDot),
reinterpret_cast<char*>(&byteArrayBody(t, classNameSlash, 0)));
throwNew(t, Machine::CloneNotSupportedExceptionType, "%s", throwNew(t, Machine::CloneNotSupportedExceptionType, "%s",
&byteArrayBody(t, className(t, objectClass(t, o)), 0)); RUNTIME_ARRAY_BODY(classNameDot));
} }
return clone; return clone;

View File

@ -3034,10 +3034,19 @@ void
checkCast(MyThread* t, object class_, object o) checkCast(MyThread* t, object class_, object o)
{ {
if (UNLIKELY(o and not isAssignableFrom(t, class_, objectClass(t, o)))) { if (UNLIKELY(o and not isAssignableFrom(t, class_, objectClass(t, o)))) {
object classNameFrom = className(t, objectClass(t, o));
object classNameTo = className(t, class_);
PROTECT(t, classNameFrom);
PROTECT(t, classNameTo);
THREAD_RUNTIME_ARRAY(t, char, classFrom, byteArrayLength(t, classNameFrom));
THREAD_RUNTIME_ARRAY(t, char, classTo, byteArrayLength(t, classNameTo));
replace('/', '.', RUNTIME_ARRAY_BODY(classFrom),
reinterpret_cast<char*>(&byteArrayBody(t, classNameFrom, 0)));
replace('/', '.', RUNTIME_ARRAY_BODY(classTo),
reinterpret_cast<char*>(&byteArrayBody(t, classNameTo, 0)));
throwNew throwNew
(t, Machine::ClassCastExceptionType, "%s as %s", (t, Machine::ClassCastExceptionType, "%s cannot be cast to %s",
&byteArrayBody(t, className(t, objectClass(t, o)), 0), RUNTIME_ARRAY_BODY(classFrom), RUNTIME_ARRAY_BODY(classTo));
&byteArrayBody(t, className(t, class_), 0));
} }
} }