From 9ceacf16e9c020ade36dd7e4149261010c17b1f8 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 29 Aug 2012 18:34:51 -0600 Subject: [PATCH] don't throw an exception from resolveClass when throw_ == false resolveClass was correctly respecting throw_ == false if the requested class was not found, but it still threw an exception if e.g. the superclass was missing. Now we catch such exceptions and return null as appropriate. --- src/machine.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index b9782ac3f0..790c9fa1aa 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3983,6 +3983,17 @@ parseClass(Thread* t, object loader, const uint8_t* data, unsigned size, return real; } +uint64_t +runParseClass(Thread* t, uintptr_t* arguments) +{ + object loader = reinterpret_cast(arguments[0]); + System::Region* region = reinterpret_cast(arguments[1]); + Machine::Type throwType = static_cast(arguments[2]); + + return reinterpret_cast + (parseClass(t, loader, region->start(), region->length(), throwType)); +} + object resolveSystemClass(Thread* t, object loader, object spec, bool throw_, Machine::Type throwType) @@ -4028,9 +4039,24 @@ resolveSystemClass(Thread* t, object loader, object spec, bool throw_, { THREAD_RESOURCE(t, System::Region*, region, region->dispose()); + uintptr_t arguments[] = { reinterpret_cast(loader), + reinterpret_cast(region), + static_cast(throwType) }; + // parse class file - class_ = parseClass - (t, loader, region->start(), region->length(), throwType); + class_ = reinterpret_cast + (runRaw(t, runParseClass, arguments)); + + if (UNLIKELY(t->exception)) { + if (throw_) { + object e = t->exception; + t->exception = 0; + vm::throw_(t, e); + } else { + t->exception = 0; + return 0; + } + } } if (Verbose) {