Code review comment: `try (queryAnalysisSpan.makeCurrent()) {` maybe not reasonable in Java8, a compile error will be raised.

Code before review:
public void executeByLegacy(TUniqueId queryId) throws Exception {
context.setStartTime();
plannerProfile.setQueryBeginTime();
context.setStmtId(STMT_ID_GENERATOR.incrementAndGet());
context.setQueryId(queryId);
if (parsedStmt instanceof QueryStmt) {
context.getState().setIsQuery(true);
}
if (parsedStmt instanceof UnifiedLoadStmt) {
final UnifiedLoadStmt unifiedLoadStmt = (UnifiedLoadStmt) parsedStmt;
unifiedLoadStmt.init();
final StatementBase proxyStmt = unifiedLoadStmt.getProxyStmt();
parsedStmt = proxyStmt;
if (!(proxyStmt instanceof LoadStmt)) {
Preconditions.checkState(
parsedStmt instanceof InsertStmt && ((InsertStmt) parsedStmt).isExternalLoad(),
new IllegalStateException("enable_unified_load=true, should be external insert stmt"));
}
}
try {
if (context.isTxnModel() && !(parsedStmt instanceof InsertStmt)
&& !(parsedStmt instanceof TransactionStmt)) {
throw new TException("This is in a transaction, only insert, commit, rollback is acceptable.");
}
analyzeVariablesInStmt();
if (!context.isTxnModel()) {
Span queryAnalysisSpan =
context.getTracer().spanBuilder("query analysis").setParent(Context.current()).startSpan();
try (Scope ignored = queryAnalysisSpan.makeCurrent()) {
analyze(context.getSessionVariable().toThrift());
} catch (Exception e) {
queryAnalysisSpan.recordException(e);
throw e;
} finally {
queryAnalysisSpan.end();
}
if (isForwardToMaster()) {
if (isProxy) {
throw new UserException("The statement has been forwarded to master FE("
+ Env.getCurrentEnv().getSelfNode().getIp() + ") and failed to execute"
+ " because Master FE is not ready. You may need to check FE's status");
}
forwardToMaster();
if (masterOpExecutor != null && masterOpExecutor.getQueryId() != null) {
context.setQueryId(masterOpExecutor.getQueryId());
}
return;
} else {
LOG.debug("no need to transfer to Master. stmt: {}", context.getStmtId());
}
} else {
analyzer = new Analyzer(context.getEnv(), context);
parsedStmt.analyze(analyzer);
}
if (prepareStmt instanceof PrepareStmt && !isExecuteStmt) {
handlePrepareStmt();
return;
}
if (parsedStmt instanceof QueryStmt) {
if (!parsedStmt.isExplain()) {
if (checkBlockRules()) {
return;
}
}
handleQueryWithRetry(queryId);
} else if (parsedStmt instanceof SetStmt) {
handleSetStmt();
} else if (parsedStmt instanceof EnterStmt) {
handleEnterStmt();
} else if (parsedStmt instanceof SwitchStmt) {
handleSwitchStmt();
} else if (parsedStmt instanceof UseStmt) {
handleUseStmt();
} else if (parsedStmt instanceof TransactionStmt) {
handleTransactionStmt();
} else if (parsedStmt instanceof CreateTableAsSelectStmt) {
handleCtasStmt();
} else if (parsedStmt instanceof InsertStmt) {
InsertStmt insertStmt = (InsertStmt) parsedStmt;
if (insertStmt.isExternalLoad()) {
handleExternalInsertStmt();
} else {
try {
handleInsertStmt();
if (!insertStmt.getQueryStmt().isExplain()) {
queryType = "Load";
}
} catch (Throwable t) {
LOG.warn("handle insert stmt fail: {}", t.getMessage());
throw t;
}
}
} else if (parsedStmt instanceof LoadStmt) {
handleLoadStmt();
} else if (parsedStmt instanceof UpdateStmt) {
handleUpdateStmt();
} else if (parsedStmt instanceof DdlStmt) {
if (parsedStmt instanceof DeleteStmt && ((DeleteStmt) parsedStmt).getFromClause() != null) {
handleDeleteStmt();
} else {
handleDdlStmt();
}
} else if (parsedStmt instanceof ShowStmt) {
handleShow();
} else if (parsedStmt instanceof KillStmt) {
handleKill();
} else if (parsedStmt instanceof ExportStmt) {
handleExportStmt();
} else if (parsedStmt instanceof UnlockTablesStmt) {
handleUnlockTablesStmt();
} else if (parsedStmt instanceof LockTablesStmt) {
handleLockTablesStmt();
} else if (parsedStmt instanceof UnsupportedStmt) {
handleUnsupportedStmt();
} else {
context.getState().setError(ErrorCode.ERR_NOT_SUPPORTED_YET, "Do not support this query.");
}
} catch (IOException e) {
LOG.warn("execute IOException. {}", context.getQueryIdentifier(), e);
context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, e.getMessage());
throw e;
} catch (UserException e) {
LOG.warn("execute Exception. {}", context.getQueryIdentifier(), e);
context.getState().setError(e.getMysqlErrorCode(), e.getMessage());
context.getState().setErrType(QueryState.ErrType.ANALYSIS_ERR);
} catch (Exception e) {
LOG.warn("execute Exception. {}", context.getQueryIdentifier(), e);
context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR,
e.getClass().getSimpleName() + ", msg: " + Util.getRootCauseMessage(e));
if (parsedStmt instanceof KillStmt) {
context.getState().setErrType(QueryState.ErrType.ANALYSIS_ERR);
}
} finally {
if (!context.isTxnModel() && parsedStmt instanceof InsertStmt) {
InsertStmt insertStmt = (InsertStmt) parsedStmt;
if (!insertStmt.isExternalLoad() && insertStmt.isTransactionBegin()
&& context.getState().getStateType() == MysqlStateType.ERR) {
try {
String errMsg = Strings.emptyToNull(context.getState().getErrorMessage());
Env.getCurrentGlobalTransactionMgr().abortTransaction(
insertStmt.getDbObj().getId(), insertStmt.getTransactionId(),
(errMsg == null ? "unknown reason" : errMsg));
} catch (Exception abortTxnException) {
LOG.warn("errors when abort txn. {}", context.getQueryIdentifier(), abortTxnException);
}
}
}
}
}

Line under review: try (Scope ignored = queryAnalysisSpan.makeCurrent()) {

Code after addressing the review:
public void executeByLegacy(TUniqueId queryId) throws Exception {
context.setStartTime();
profile.getSummaryProfile().setQueryBeginTime();
context.setStmtId(STMT_ID_GENERATOR.incrementAndGet());
context.setQueryId(queryId);
if (parsedStmt instanceof QueryStmt) {
context.getState().setIsQuery(true);
}
if (parsedStmt instanceof UnifiedLoadStmt) {
final UnifiedLoadStmt unifiedLoadStmt = (UnifiedLoadStmt) parsedStmt;
unifiedLoadStmt.init();
final StatementBase proxyStmt = unifiedLoadStmt.getProxyStmt();
parsedStmt = proxyStmt;
if (!(proxyStmt instanceof LoadStmt)) {
Preconditions.checkState(
parsedStmt instanceof InsertStmt && ((InsertStmt) parsedStmt).needLoadManager(),
new IllegalStateException("enable_unified_load=true, should be external insert stmt"));
}
}
try {
if (context.isTxnModel() && !(parsedStmt instanceof InsertStmt)
&& !(parsedStmt instanceof TransactionStmt)) {
throw new TException("This is in a transaction, only insert, commit, rollback is acceptable.");
}
analyzeVariablesInStmt();
if (!context.isTxnModel()) {
Span queryAnalysisSpan =
context.getTracer().spanBuilder("query analysis").setParent(Context.current()).startSpan();
try (Scope ignored = queryAnalysisSpan.makeCurrent()) {
analyze(context.getSessionVariable().toThrift());
} catch (Exception e) {
queryAnalysisSpan.recordException(e);
throw e;
} finally {
queryAnalysisSpan.end();
}
if (isForwardToMaster()) {
if (isProxy) {
throw new UserException("The statement has been forwarded to master FE("
+ Env.getCurrentEnv().getSelfNode().getIp() + ") and failed to execute"
+ " because Master FE is not ready. You may need to check FE's status");
}
forwardToMaster();
if (masterOpExecutor != null && masterOpExecutor.getQueryId() != null) {
context.setQueryId(masterOpExecutor.getQueryId());
}
return;
} else {
LOG.debug("no need to transfer to Master. stmt: {}", context.getStmtId());
}
} else {
analyzer = new Analyzer(context.getEnv(), context);
parsedStmt.analyze(analyzer);
}
if (prepareStmt instanceof PrepareStmt && !isExecuteStmt) {
handlePrepareStmt();
return;
}
if (parsedStmt instanceof QueryStmt) {
if (!parsedStmt.isExplain()) {
if (checkBlockRules()) {
return;
}
}
handleQueryWithRetry(queryId);
} else if (parsedStmt instanceof SetStmt) {
handleSetStmt();
} else if (parsedStmt instanceof SwitchStmt) {
handleSwitchStmt();
} else if (parsedStmt instanceof UseStmt) {
handleUseStmt();
} else if (parsedStmt instanceof TransactionStmt) {
handleTransactionStmt();
} else if (parsedStmt instanceof CreateTableAsSelectStmt) {
handleCtasStmt();
} else if (parsedStmt instanceof InsertStmt) {
InsertStmt insertStmt = (InsertStmt) parsedStmt;
if (insertStmt.needLoadManager()) {
handleExternalInsertStmt();
} else {
try {
if (!insertStmt.getQueryStmt().isExplain()) {
profileType = ProfileType.LOAD;
}
handleInsertStmt();
} catch (Throwable t) {
LOG.warn("handle insert stmt fail: {}", t.getMessage());
throw t;
}
}
} else if (parsedStmt instanceof LoadStmt) {
handleLoadStmt();
} else if (parsedStmt instanceof UpdateStmt) {
handleUpdateStmt();
} else if (parsedStmt instanceof DdlStmt) {
if (parsedStmt instanceof DeleteStmt && ((DeleteStmt) parsedStmt).getFromClause() != null) {
handleDeleteStmt();
} else {
handleDdlStmt();
}
} else if (parsedStmt instanceof ShowStmt) {
handleShow();
} else if (parsedStmt instanceof KillStmt) {
handleKill();
} else if (parsedStmt instanceof ExportStmt) {
handleExportStmt();
} else if (parsedStmt instanceof UnlockTablesStmt) {
handleUnlockTablesStmt();
} else if (parsedStmt instanceof LockTablesStmt) {
handleLockTablesStmt();
} else if (parsedStmt instanceof UnsupportedStmt) {
handleUnsupportedStmt();
} else {
context.getState().setError(ErrorCode.ERR_NOT_SUPPORTED_YET, "Do not support this query.");
}
} catch (IOException e) {
LOG.warn("execute IOException. {}", context.getQueryIdentifier(), e);
context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, e.getMessage());
throw e;
} catch (UserException e) {
LOG.warn("execute Exception. {}", context.getQueryIdentifier(), e);
context.getState().setError(e.getMysqlErrorCode(), e.getMessage());
context.getState().setErrType(QueryState.ErrType.ANALYSIS_ERR);
} catch (Exception e) {
LOG.warn("execute Exception. {}", context.getQueryIdentifier(), e);
context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR,
e.getClass().getSimpleName() + ", msg: " + Util.getRootCauseMessage(e));
if (parsedStmt instanceof KillStmt) {
context.getState().setErrType(QueryState.ErrType.ANALYSIS_ERR);
}
} finally {
if (!context.isTxnModel() && parsedStmt instanceof InsertStmt) {
InsertStmt insertStmt = (InsertStmt) parsedStmt;
if (!insertStmt.needLoadManager() && insertStmt.isTransactionBegin()
&& context.getState().getStateType() == MysqlStateType.ERR) {
try {
String errMsg = Strings.emptyToNull(context.getState().getErrorMessage());
Env.getCurrentGlobalTransactionMgr().abortTransaction(
insertStmt.getDbObj().getId(), insertStmt.getTransactionId(),
(errMsg == null ? "unknown reason" : errMsg));
} catch (Exception abortTxnException) {
LOG.warn("errors when abort txn. {}", context.getQueryIdentifier(), abortTxnException);
}
}
}
}
}