This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: remove redundant test


Tom Tromey writes:
 > I'm checking this in.
 > 
 > This removes a redundant test.  I think this test was needed with an
 > earlier version of Andrew's stack trace patch.
 > 
 > Tom
 > 
 > Index: java/util/natResourceBundle.cc
 > ===================================================================
 > RCS file: /cvs/gcc/gcc/libjava/java/util/natResourceBundle.cc,v
 > retrieving revision 1.4
 > diff -u -r1.4 natResourceBundle.cc
 > --- java/util/natResourceBundle.cc 5 Dec 2002 00:49:30 -0000 1.4
 > +++ java/util/natResourceBundle.cc 10 Dec 2002 01:28:20 -0000
 > @@ -22,8 +22,6 @@
 >  java::util::ResourceBundle::getCallingClassLoader ()
 >  {
 >    gnu::gcj::runtime::StackTrace *t = new gnu::gcj::runtime::StackTrace(6);
 > -  if (! t)
 > -    return NULL;
 >    for (int i = 3; i < 6; ++i)
 >      {
 >        jclass klass = t->classAt(i);

I'd like to suggest this alternative patch.  It removes the arbitrary
upper limit on scanning the stack and catches the
ArrayIndexOutOfBoundsException.  On the other hand, perhaps the upper
limit of 6 is so that we can handle interpreter and native methods.
Is it okay for the invocation API when interpreted?

Maybe we need to keep that upper limit, but we surely must catch
ArrayIndexOutOfBoundsException.  

Maybe we ought to define getCallingClass() as a macro or an inline
method in a header file to avoid this repetition.

I'm beginning to wonder if we ought to throw a security exception if
we don't find the class.  This is for targets that support
backtrace(), post 3.3 branch.

Andrew.

Index: natResourceBundle.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/natResourceBundle.cc,v
retrieving revision 1.4
diff -c -2 -p -r1.4 natResourceBundle.cc
*** natResourceBundle.cc	5 Dec 2002 00:49:30 -0000	1.4
--- natResourceBundle.cc	10 Dec 2002 10:32:41 -0000
*************** java::util::ResourceBundle::getCallingCl
*** 23,34 ****
  {
    gnu::gcj::runtime::StackTrace *t = new gnu::gcj::runtime::StackTrace(6);
!   if (! t)
!     return NULL;
!   for (int i = 3; i < 6; ++i)
      {
!       jclass klass = t->classAt(i);
!       if (klass != NULL)
! 	return klass->getClassLoaderInternal();
      }
    return NULL;
  }
--- 23,40 ----
  {
    gnu::gcj::runtime::StackTrace *t = new gnu::gcj::runtime::StackTrace(6);
!   java::lang::Class *klass = NULL;
!   try
      {
!       for (int i = 3; ; i++)
! 	{
! 	  klass = t->classAt (i);
! 	  if (klass != NULL)
! 	    return klass->getClassLoaderInternal();
! 	}
      }
+   catch (::java::lang::ArrayIndexOutOfBoundsException *e)
+     {
+     }
+ 
    return NULL;
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]