简体   繁体   English

Java异常流中的意外行为

[英]unexpected behavior in java exception flow

I have written following code snippet:- 我写了以下代码片段:-

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());
                }

}

The weird behavior which is happening is that while iterating through the customPOJO its coming inside elseIf and also setting the value in valueString by executing below code: 发生的怪异行为是,在遍历customPOJO时,将其传入elseIf并通过执行以下代码在valueString中设置值:

else if (customPOJO .getProtocol().equals(protocol))
                    {
                        valueString.append(customPOJO .getPort() + ":"+ protocol + ";");
                    } 

After this elseif its coming directly on line 之后,如果它直接在线

throw new RemoteException("Invalid Argument: Unsupported protocol "+ protocol);

There is no error which is coming in append operation and checked in debug perspective the value is getting appended successfully in valueString. 附加操作中没有错误,并且在调试透视图中检查了值是否成功附加到valueString中。

Please tell what i am missing 请告诉我我在想什么

Figure I should put this as an answer instead of just a comment... 图我应该把它作为答案,而不仅仅是评论...

This sort of behavior can occur when your code (what you are stepping through in the debugger) is out of sync with the compiled class files (that are actually running). 当您的代码(在调试器中逐步执行的操作)与已编译的类文件(实际正在运行)不同步时,可能会发生这种行为。 Since debug information is associated with line numbers, the lines may be different in the class files than in the source code you see. 由于调试信息与行号相关联,因此类文件中的行可能与您看到的源代码中的行不同。

Try running a clean build and make sure that there are no duplicate jars on your classpath that may be causing this. 尝试运行一个干净的版本,并确保您的类路径上没有重复的jar可能导致这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM