Why catch (NullPointerException e)?

2000-08-18 Thread igor
Hi! I noticed that try { System.getSecurityManager().checkXXX(); } catch(NullPointerException e) { } code is used throw classpath. What is a reason for that? I wrote a simple test case like: class x { /* x() throws SecurityException { try { System.getSecurityManager().checkCreateClassL

Re: Why catch (NullPointerException e)?

2000-08-18 Thread Patrick LAM
On Fri, 18 Aug 2000 [EMAIL PROTECTED] wrote: > I wrote a simple test case like: > class x > { > /* > x() throws SecurityException { > try { >System.getSecurityManager().checkCreateClassLoader(); > } catch(NullPointerException e) { > } > */ > x() throws SecurityException { > Security

Re: Why catch (NullPointerException e)?

2000-08-18 Thread Stuart Ballard
Patrick LAM wrote: > > Catching exceptions is extremely slow, as is anything in general which has > to do with exceptions. I would say that the second idiom should always be > favoured. It depends - suppose catching an exception is 100 times slower than doing a comparision to null. And then supp

Re: Why catch (NullPointerException e)?

2000-08-18 Thread Tom Tromey
> "Stuart" == Stuart Ballard <[EMAIL PROTECTED]> writes: >> Catching exceptions is extremely slow, as is anything in general >> which has to do with exceptions. I would say that the second idiom >> should always be favoured. Stuart> It depends - suppose catching an exception is 100 times slo

Re: Why catch (NullPointerException e)?

2000-08-19 Thread Ian Rogers
Hi, I think this is a very interesting subject. So far two solutions have been proposed: (a) if (sm != null) { sm.XXX(); } (b) try { sm.XXX(); } catch (NullPointerException e){} I'd like to propose a third solution. It requires more programming and results in a larger binary, but on a JIT compi

Re: Why catch (NullPointerException e)?

2000-08-19 Thread Etienne M. Gagnon
Hi all! Two points: [1] You shouldn't explicitely test for "null" pointers, unless a null pointer would normally be expected. If we can assume that "sm" shouldn't be null in a bug free program/library, then try { sm.XXX(); } catch (NullPointerException e){} is the right thing to do, as in a

Re: Why catch (NullPointerException e)?

2000-08-19 Thread Ian Rogers
Hi Etienne, by default a JVM doesn't have a security manager. However, if we're executing applets in a web browser the browser would install a security manager to provide the "sandbox" security model. I agree with your points. I find the idea of exceptions for optimisation an interesting conc

Re: Why catch (NullPointerException e)?

2000-08-19 Thread Etienne M. Gagnon
Hi Ian. Ian Rogers wrote: > by default a JVM doesn't have a security manager. However, if we're > executing applets in a web browser the browser would install a security > manager to provide the "sandbox" security model. I have not looked in details at the code, but do you really need to do the

Re: Why catch (NullPointerException e)?

2000-08-19 Thread Ian Rogers
Hi Etienne, > I have not looked in details at the code, but do you really need to do > the test on every invocation of this specific method? Can't the test > for security manager be done once and for all earlier? Then you can use > inheritance/delegation (or other standard design patterns) to d

Re: Why catch (NullPointerException e)?

2000-08-19 Thread Etienne M. Gagnon
Ian Rogers wrote: > > My comments on exceptions are NOT VM specific. Exceptions should be > > "exceptional". From a VM designer point of view, the last thing to > > optimize (in priority) is exceptions. > > I don't know. Saying exceptions are exceptional is one way of viewing > there use. An al

Re: Why catch (NullPointerException e)?

2000-08-20 Thread Ian Rogers
Hi Etienne/All, I feel as though this conversation has strayed away from what I wanted to discuss. That was design patterns for dealing with null. I propose there are 3 alternative solutions: 1) if (sm != null){sm.XXX();} 2) try {sm.XXX();}catch (NullPointerException e){} 3) initialise sm to a d

Re: Why catch (NullPointerException e)?

2000-08-20 Thread Etienne M. Gagnon
Ian Rogers wrote: > 3) initialise sm to a default_sm object This is probably the best alternative, but you must be careful in the implementation of System.getSecurityManager(). This method should return null when your "default" object is in place. (Otherwise, it wouldn't conform to the API spec

RE: Why catch (NullPointerException e)?

2000-08-21 Thread Cierniak, Michal
Hi Etienne, > From: Etienne M. Gagnon [mailto:[EMAIL PROTECTED]] > Sent: Saturday, August 19, 2000 4:04 PM > Subject: Re: Why catch (NullPointerException e)? > > > Exceptions should be "exceptional". From a VM > > > designer point of view, the last thi

Re: Why catch (NullPointerException e)?

2000-08-22 Thread igor
you wrote: > I agree, however, the explicit null check will slow down the execution > speed of applets. Why? In case of a JIT or compiled Java for applets "if (sm != null)" will be branch predicted and cause no harm at all. Moreover, AFAIK try/catch in general produce more code and eve

RE: Why catch (NullPointerException e)?

2000-08-22 Thread Cierniak, Michal
Hi Igor, > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, August 22, 2000 9:02 AM > Subject: Re: Why catch (NullPointerException e)? > > Ian wrote: > > I agree, however, the explicit null check will slow > > down the execution speed of appl

Re: Why catch (NullPointerException e)?

2000-08-22 Thread Tom Tromey
> "Etienne" == Etienne M Gagnon <[EMAIL PROTECTED]> writes: Etienne> The general rule for exception is: An exception denotes an Etienne> "exceptional" situation (no surprize!), and thus should not Etienne> be used on the normal execution path of a program/library. I first heard this statemen

RE: Why catch (NullPointerException e)?

2000-08-23 Thread igor
Hi, Michal! You wrote: > Hi Igor, > > > Ian wrote: > > > I agree, however, the explicit null check will slow > > > down the execution speed of applets. > > > > Why? In case of a JIT or compiled Java for applets "if (sm != > > null)" will be branch predicted and cause no harm at all. >

RE: Why catch (NullPointerException e)?

2000-08-23 Thread Cierniak, Michal
> Ok, I agree that cache misses with this policy is not that > important although `if (sm != null)' produces less code which > means shorter load time. Well, you mileage may vary. In our VM, the load time hasn't been an issue for any of the benchmarks we looked at. Our VM has two JIT compilers

Re: Why catch (NullPointerException e)?

2000-09-27 Thread Ian Rogers
Hi Igor, > you wrote: > > I agree, however, the explicit null check will slow down the execution > > speed of applets. > > Why? In case of a JIT or compiled Java for applets "if (sm != null)" will be branch >predicted and cause no harm at all. Moreover, AFAIK try/catch in general produce