[英]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.