我有以下方法 . 我遇到了关于下面的WHILE循环的奇怪行为 .
我最初将布尔值 notDone
的值设置为 true
. 在WHILE循环内部,第一次出现异常,因此程序控制转到CATCH块 . 第二次调用execute()方法成功 . 我还看到println语句( getProperties() postExecute()
)具有正确的 notDone
值(正确设置为 false
) . 但是 despite this the, while loop condition gets satisfied and the execute() method gets invoked again . 关于什么导致while条件失败的任何想法?
public List<Property> getProperties() {
int count = 0;
boolean notDone = true;
while (notDone) {
System.out.println("getProperties() notDone => " + notDone);
try {
execute();
notDone = false;
System.out.println("getProperties() postExecute() " + notDone);
} catch (Exception e) {
System.out.println("getProperties() Exception occured " + notDone);
if (e instanceof java.net.UnknownHostException) {
// Potentially proxy error.
if (ConfigManager.getInstance().getConfig().isUseProxy()) {
System.out
.println("UnknownHostException - Switching off proxy");
ConfigManager.getInstance().getConfig()
.setUseProxy(false);
} else {
System.out
.println("UnknownHostException - Switching on proxy");
ConfigManager.getInstance().getConfig()
.setUseProxy(true);
}
}
if (count > 2) {
break;
}
count++;
}
}
return result;
}