在以下方法中,我得到一个例外:
public static Ticket executeOrder(final FXOrderData orderData)
throws Exception {
ExecutorService service = Executors.newCachedThreadPool();
Future<Ticket> ticketFuture = service.submit(new Callable<Ticket>() {
@Override
public Ticket call() throws Exception {
try {
if (isSwap(orderData)) {
return FXOrderManager.getInstance().executeFXSwapOrder(orderData);
} else {
return FXOrderManager.getInstance().executeFXOrder(orderData);
}
} catch (final Throwable e) {
Log.error(getClass().getName(), "executeOrder",
"Unable to execute order : " + e.getMessage(), e);
throw new FXMOEException( e.getMessage());
}
}
});
return ticketFuture.get();
}
从未来的任务中抛出此异常的可能情况是什么?这是相应的堆栈跟踪:
java.util.concurrent.ExecutionException: Array index out of range: 0
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
at java.util.concurrent.FutureTask.get(FutureTask.java:83)
at com.indigo.neuron.gui.manualorderentry.ManualOrderUtils.executeOrder(ManualOrderUtils.java:146)
at com.indigo.neuron.gui.manualorderentry.ManualOrderPanel$6$1.run(ManualOrderPanel.java:761)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: Array index out of range: 0
at com.indigo.neuron.gui.manualorderentry.ManualOrderUtils$2.call(ManualOrderUtils.java:141)
at com.indigo.neuron.gui.manualorderentry.ManualOrderUtils$2.call(ManualOrderUtils.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
... 3 more
问题出现在这种方法的调用中:
public Ticket executeFXOrder(FXOrderData fxOrderData) throws Throwable {
validateOrder(fxOrderData);
// execute non-swap order.
StrategyInfo strategyInfo = FXStrategyController.getInstance().createStrategy(fxOrderData);
String strategyID = strategyInfo.getWaveID();
FXStrategyController.getInstance().startStrategy(strategyInfo);
String basketId = fxOrderData.getBasketID();
if (StringUtils.isNullOrWhitespace(basketId)) {
String symbol = fxOrderData.getSymbol();
String side = fxOrderData.getSide();
boolean contra = fxOrderData.isContraTrade();
String currency = SymbolUtils.getDealCurrency(fxOrderData.getSymbol(), fxOrderData.isContraTrade());
BasketCollection bc = ZConnection.getBasketStore();
bc = (BasketCollection) bc.filter(new STBFilter(symbol, side, currency, contra));
if (bc.size() > 0) {
basketId = (String) bc.keySet().iterator().next();
}
}
BasketCollection store = ZConnection.getBasketStore();
Basket basket = store.get(basketId);
if (basket != null) {
Wave wave = basket.getWave(strategyID);
if (wave != null) {
return (Ticket) wave.getTickets().get(0);
}
}
return null;
}
奇怪的是,它只在运行时发生,而不是在调试时发生。
答案 0 :(得分:2)
最常见的例外原因是在标记为&#34;的最后一节中的代码行中引起:&#34;
这是
Caused by: Array index out of range: 0
at com.indigo.neuron.gui.manualorderentry.ManualOrderUtils$2.call(ManualOrderUtils.java:141)
at com.indigo.neuron.gui.manualorderentry.ManualOrderUtils$2.call(ManualOrderUtils.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
注意:第一个异常只是一个包装异常,说明捕获和重新抛出真正异常的位置。
简而言之,始终先读取堆栈跟踪的最后一部分。