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().checkCreateClassLoader();
} catch(NullPointerException e) {
}
*/
x() throws SecurityException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) { sm.checkCreateClassLoader(); }
}
}
And here what I got for code size after
javac -O -g:none x.java:
x.class with NullPointerException check: 377 bytes
x.class with if check: 335 bytes
As regarding speed I really doubed that one can gain
anything: with Jit and brunch prediction I would expect
that even when SecurityManager is installed, the "if" case would run as fast as catch
one, and without SecurityManager (which a common case for many Java applications), it
would run I guess at least 10 times faster.
Besides, this "optimization" can hide potential NullPointerException bugs in
SecurityManager implementation.
Regards, Igor
------------------------------------------------------
Get the Latest News at CNN Interactive: http://CNN.com