From: Mark S. <mar...@gm...> - 2008-10-11 23:17:23
|
Sometimes it really helps having a fresh pair of eyes look over the code. :-) On Sat, Oct 11, 2008 at 5:14 PM, Erik Vos <eri...@hc...> wrote: > You're right again. Yesterday I noticed this one too when I restarted the > game the first time after so many months.... > I really don't understand how this one can have slipped through.... > > I have fixed it already by initializing specialProperties in PrivateCompany > to an empty ArrayList rather than to null. Matter of taste, I guess. Mine is > not the best method if conserving memory is a concern, but there aren't that > many privates anyway. > > Erik. > > ------------------------------ > *From:* Mark Smith [mailto:mar...@gm...] > *Sent:* Saturday 11 October 2008 21:40 > *To:* Rails Dev Mailing List > *Subject:* [Rails-devel] Recommended Patch to GameManager.java > > In the process of getting the Rails Devel Source Code to properly load > and compile and run on my XCode, I came across a problem in the > setGameParameters that generated a Null Pointer Exception. I feel the best > way to resolve this is the following change: > > 316 private void setGameParameters () { > 317 > 318 for (PublicCompanyI company : companyManager.getAllPublicCompanies()) { > 319 hasAnyParPrice = hasAnyParPrice || company.hasParPrice(); > 320 canAnyCompanyBuyPrivates = canAnyCompanyBuyPrivates || company.canBuyPrivates(); > 321 canAnyCompanyHoldShares = canAnyCompanyHoldShares || company.canHoldOwnShares(); > 322 } > 323 > 324 loop: for (PrivateCompanyI company : companyManager.getAllPrivateCompanies()) { > 325 for (SpecialPropertyI sp : company.getSpecialProperties()) { > 326 if (sp instanceof SpecialTokenLay > 327 && ((SpecialTokenLay)sp).getToken() instanceof BonusToken) { > 328 bonusTokensExist = true; > 329 break loop; > 330 } > 331 } > 332 > 333 } > 334 } > > TO: > > 316 private void setGameParameters () { > 317 List<SPecialPropertyI> specials; > > 318 for (PublicCompanyI company : companyManager.getAllPublicCompanies()) { > 319 hasAnyParPrice = hasAnyParPrice || company.hasParPrice(); > 320 canAnyCompanyBuyPrivates = canAnyCompanyBuyPrivates || company.canBuyPrivates(); > 321 canAnyCompanyHoldShares = canAnyCompanyHoldShares || company.canHoldOwnShares(); > 322 } > 323 > 324 loop: for (PrivateCompanyI company : companyManager.getAllPrivateCompanies()) { > > specials = company.getSpecialProperties (); > if (specials != null) { > 325 for (SpecialPropertyI sp : specials) { > 326 if (sp instanceof SpecialTokenLay > 327 && ((SpecialTokenLay)sp).getToken() instanceof BonusToken) { > 328 bonusTokensExist = true; > 329 break loop; > 330 } > 331 } > 332 } > 333 } > 334 } > > I never really liked try-catch blocks, and in this case if something in the inner loop has a Null Pointer Exception it needs to be thrown. This will test and skip any specials that are null. > > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Rails-devel mailing list > Rai...@li... > https://lists.sourceforge.net/lists/listinfo/rails-devel > > |