[英]unexpected behavior in java exception flow
我寫了以下代碼片段:-
public Collection<?> constructResponse (...........) throws RemoteException {
while (keyIterator.hasNext())
{
String keyValue = (String) keyIterator.next();
keyString = new StringBuilder(); // since multiple keys will be there in map need to ensure every time keyString and valueString is created
valueString = new StringBuilder();
keyString.append(keyValue + ";" + "name");
List<CustomValuePOJO> customPOJOlist = employeeValuesMap.get(keyValue );
for (CustomValuePOJO customPOJO : customPOJOlist )
{
if (protocol == null || protocol.equals(""))
{
valueString.append(rpNatPOJO.getDcnPort() + ":"+ rpNatPOJO.getProtocol() + ";");
}
else if (customPOJO .getProtocol().equals(protocol))
{
valueString.append(customPOJO .getPort() + ":"+ protocol + ";");
}
else
{ throw new RemoteException("Invalid Argument: Unsupported protocol "+ protocol);
}
}
if (valueString.length() == 0)
{
return generateErrorResponse("No info found");
}
responseMap.put(keyString.toString(), valueString.toString());
}
}
發生的怪異行為是,在遍歷customPOJO時,將其傳入elseIf並通過執行以下代碼在valueString中設置值:
else if (customPOJO .getProtocol().equals(protocol))
{
valueString.append(customPOJO .getPort() + ":"+ protocol + ";");
}
之后,如果它直接在線
throw new RemoteException("Invalid Argument: Unsupported protocol "+ protocol);
附加操作中沒有錯誤,並且在調試透視圖中檢查了值是否成功附加到valueString中。
請告訴我我在想什么
圖我應該把它作為答案,而不僅僅是評論...
當您的代碼(在調試器中逐步執行的操作)與已編譯的類文件(實際正在運行)不同步時,可能會發生這種行為。 由於調試信息與行號相關聯,因此類文件中的行可能與您看到的源代碼中的行不同。
嘗試運行一個干凈的版本,並確保您的類路徑上沒有重復的jar可能導致這種情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.