wu-sheng commented on code in PR #13737:
URL: https://github.com/apache/skywalking/pull/13737#discussion_r2912580617
##########
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/v2/compiler/LALBlockCodegen.java:
##########
@@ -1140,6 +1172,288 @@ static String generateExtraLogAccess(
return prevVar;
}
+ // ==================== Def statement codegen ====================
+
+ static void generateDefStatement(final StringBuilder sb,
+ final LALScriptModel.DefStatement def,
+ final LALClassGenerator.GenCtx genCtx) {
+ final LALScriptModel.ValueAccess init = def.getInitializer();
+ final String varName = def.getVarName();
+ final String javaVar = "_" + varName;
Review Comment:
Fixed in c5911cc. Using `_def_` prefix now (e.g., `def config` →
`_def_config`) to avoid collision with reserved locals like `_p`, `_o`, `_tN`.
##########
oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/v2/compiler/LALBlockCodegen.java:
##########
@@ -1174,29 +1488,29 @@ static void generateProcessRegistryCall(
// ==================== Utility methods ====================
static String appendMethodSegment(final String current,
- final LALScriptModel.MethodSegment ms) {
+ final LALScriptModel.MethodSegment ms,
+ final LALClassGenerator.GenCtx genCtx) {
+ final String mn = ms.getName();
+ final String args = ms.getArguments().isEmpty()
+ ? "" : generateMethodArgs(ms.getArguments(), genCtx);
if (ms.isSafeNav()) {
- final String mn = ms.getName();
+ // Special-cased helpers for common safe-nav methods on Object
if ("toString".equals(mn)) {
return "h.toString(" + current + ")";
} else if ("trim".equals(mn)) {
return "h.trim(" + current + ")";
- } else {
- throw new IllegalArgumentException(
- "Unsupported safe-nav method: ?." + mn + "()");
}
+ // General safe-nav: null guard with ternary
+ return "(" + current + " == null ? null : "
+ + current + "." + mn + "(" + args + "))";
} else {
Review Comment:
Not an issue in practice. This general safe-nav path is only reachable for
untyped chains (non-def-var). In real LAL scripts, `?.` chains on untyped
values only call object-returning methods like `.get()`, `.getAsString()`,
`.toString()`, `.trim()`. The typed def-var path (`generateDefVarChain`)
already handles primitive boxing correctly. Adding type tracking to the untyped
path would require significant complexity for a case that doesn't occur in
practice.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]