optimization - Java dead code elimination... is this code at risk of being optimized out? -
so, i'm using api little unfriendly in ways. basically, api creates resource can fetched later. resource may or may not still exist when go fetch later.
to fetch created resource, have use result guid so:
string resultkey = "12345"; persistedresult r = mfactory.getpersistedresult(resultkey);
now, tricky thing here getpersistedresult
not throw exception when called invalid guid... persistedresult
lazy loader , fail when 1 of methods called (causing object load itself).
so, try , determine whether or not resource valid, i'm doing following:
persistedresult r = null; if (!stringutils.isempty(resultkey)) { try { r = mfactory.getpersistedresult(resultkey); r.getresultcount(); // triggers exception if result key invalid. } catch (exception e) { // handle exception } }
is call getresultcount
@ risk of being optimized out because i'm not using value?
calling method on persistedresult
goes external database, in case matters.
thanks
the compiler can't assume getresultcount() has no side-effects -- therefore can't remove call.
Comments
Post a Comment