-4

以下はコードです: - 例外をスローする理由とそれを回避する方法を教えてください。助けてくれてありがとう..

public Collection getBeansFilteredByAuthorityAndApproach(ITaskContext context)throws CEAppException

{ Collection regApprAuthMapColl = this.getRegulatoryAuthorityApproachMap(context);//Collection of All approach combos

Collection finalAuthApprMapColl = new ArrayList();

ParameterSet pSets = context.getExecutionThread().getParameterSet();

//<RuntimeParameterSet> or list of <RuntimeParameters>

ArrayList apAR =pSets.getRuntimeParameterSet().getRuntimeParametersList();

int apSize = apAR.size() ;

for (int j = 0; j < apSize; j++)

{//1

//Individual <RuntimeParameterSet> or list of <RuntimeParameters>

RuntimeParameters rps = (RuntimeParameters) apAR.get(j);

if (Constants.CLONE_TYPE.equalsIgnoreCase(rps.getType())) //TODO :check if it required or not

{//2

//obtain a list of <RuntimeParameter> or indiviual <RuntimeParameters>

ArrayList rtParams = rps.getRuntimeParameterList();

int rtSize = rtParams.size();

for (int k = 0; k < rtSize; k++)

{//3 FOR EACH RUNTIME PARAMETER , i.e Approach & Authority

//Individual <RuntimeParameter>

Integer inputAuthority = null;

Integer inputApproach = null;

RuntimeParameter rtp = (RuntimeParameter) rtParams.get(k);

logger.debug("========== RuntimeParameter rtp="+rtp);

if (Constants.REGAUTHORITY.equals(rtp.getName()))

{

Integer regAuthority = ReferenceData.getRegAuthority(context,rtp.getValue());

inputAuthority = regAuthority;

} else if (Constants.REGAPPROACH.equals(rtp.getName()))

{

Integer regApproach = ReferenceData.getRegApproach(context,rtp.getValue()) ;

inputApproach = regApproach;

}

//FOR EACH RUNTIME PARAMETER FILTER THE COLLECTIONS

 

//FILTERING DATA

logger.debug("inputApproach :"+inputApproach);

logger.debug("inputAuthority :"+inputAuthority);

if(inputApproach == null)// if APPROACH IS NOT specified in the notification

{

if( inputAuthority == null)// if AUTHORITY IS NOT specified & APPROACH IS NOT specified

{ //Then run for all auhorities and approaches

finalAuthApprMapColl = regApprAuthMapColl;//returning all possible beans

}//end of if

else// if AUTHORITY IS specified & APPROACH IS NOT specified

{ //Then for the given authority, run for all approaches: B1,STD,IRB,AIRB

for (Iterator itr = regApprAuthMapColl.iterator(); itr.hasNext();)

{//looping through all possible values to select

RegulatoryAuthorityApproachMap raaMap = (RegulatoryAuthorityApproachMap)itr.next();

Integer fullAuthorityId = raaMap.getRegulatoryAuthorityId();

if(inputAuthority.intValue() == fullAuthorityId.intValue())// for a given authority

{

finalAuthApprMapColl.add(raaMap);//returning a list of all approaches for a given authority

}

}//end of for loop

}//end of else

}//end of if approach is null

else//if APPROACH IS specified in the notification

{

if(inputAuthority == null)// if AUTHORITY IS NOT specified && APPROACH IS specified

{//Then for the given approach, run for all authorities: FSA,EBK,BIS

for (Iterator itr = regApprAuthMapColl.iterator(); itr.hasNext();)

{//looping through all possible combos to select

RegulatoryAuthorityApproachMap raaMap = (RegulatoryAuthorityApproachMap)itr.next();

Integer fullApproachId = raaMap.getRegulatoryApproachId();

if(inputApproach.intValue() == fullApproachId.intValue())// for a given approach

{

finalAuthApprMapColl.add(raaMap);//returning a list of all authorities for a given approach

}

} //end of for loop

}//end of if

else// if AUTHORITY IS specified & APPROACH IS specified

{

for (Iterator itr = regApprAuthMapColl.iterator(); itr.hasNext();)

{//looping through all possible combos to select

RegulatoryAuthorityApproachMap raaMap = (RegulatoryAuthorityApproachMap)itr.next();

Integer fullApproachId = raaMap.getRegulatoryApproachId();

Integer fullAuthorityId = raaMap.getRegulatoryAuthorityId();

if((inputApproach.intValue() == fullApproachId.intValue()) && (inputAuthority.intValue() == fullAuthorityId.intValue()))// for a given approach

{

finalAuthApprMapColl.add(raaMap);//returning a list of all authorities for a given approach

}

} //end of for loop

}

}//end of else

}//3

}//2

}//1

if(finalAuthApprMapColl.size() == 0){throw new CEAppException("The Authority/Approach mapping is null"); }

else

return finalAuthApprMapColl;

}//end of method
4

1 に答える 1

1

あなたのコードは非常に不明確ですが、私が理解できることから、特定のコレクションに対してイテレータを使用しています:

for(Iterator itr = regApprAuthMapColl.iterator(); itr.hasNext();)

この場合、コレクションはregApprAuthMapColl. ただし、コレクションを繰り返し処理している間にコレクションを変更しているため、for ループには次のようなものがあります。

finalAuthApprMapColl.add(raaMap);

これは許可されていません。コレクションを反復処理すると同時にコレクションを変更することはできず、おそらく例外がスローされる場所です。

于 2012-07-18T16:25:35.937 に答える