From: Mark S. <mar...@gm...> - 2008-10-11 20:39:43
|
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. |