This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: gnu.gcj.runtime.StackTrace.findCallerClass()
Mohan Embar writes:
> Hi Andrew,
>
> > > - know that you have to deal with both cases, and now be required to
> > > introduce #ifdef HAVE_BACKTRACE in the caller's code too because there's
> > > no other way to effectively deal with this.
> > >
> > > Even in the current case, the caller is always catching the
> > > ArrayIndexOutOfBoundsException and never letting it trickle up
> > > to a higher level.
> >
> >But that's wrong -- the caller shouldn't do that. The only reasonable
> >thing to do if a caller isn't found in the stack is stop the entire
> >JVM with a RuntimeError. Something has gone badly wrong.
>
> Okay. But what is the caller supposed to do if HAVE_BACKTRACE
> is not set?
If HAVE_BACKTRACE is not set, we don't search but return null.
> If we terminate the JVM if HAVE_BACKTRACE is set,
> can't we call exit() instead of returning null if HAVE_BACKTRACE
> is not set?
An example is worth a thousand words:
caller = findCallerClass(1);
caller_loader = caller ? caller->getClassLoaderInternal() : NULL;
if (caller_loader != NULL && ! caller_loader->isAncestorOf(loader))
s->checkPermission (new RuntimePermission (JvNewStringLatin1 ("getClassLoader")));
When we get round to implementing proper Java security we'll have to
close this loophole. But not yet.
Andrew.