By ByronNevins on May 20, 2012
I was debugging some GlassFish code today. This one Admin Command needed to find out if a given node was local or remote. It is (obviously, clearly) impossible for the node to change this attribute during this command call. The code calls this method:
Now if you write a final getter method this is perfectly OK because the compiler will simply inline the code so that it becomes a simple variable access.
But NO WAY is that happening in this case. The "node" object is a proxy. The value needs to get processed through code that resolves tokens, etc. The stack shows 8 calls to get this value. So it is an expensive call.
I had a breakpoint in this method. It was called over TWENTY times by the same command! That's 152 or so pointless method calls.
What it needed was just ONE line of code:
boolean isLocal = node.isLocal();