From: Erik V. <eri...@hc...> - 2008-10-11 22:15:01
|
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. |