【问题标题】:Unable to evaluate statement, identifier not found无法评估语句,未找到标识符
【发布时间】:2021-09-13 10:13:59
【问题描述】:

我为非 gcp 环境设置了 google-cloud-debug。这是一个附加代理运行的示例代码。

import java.util.Random;

public class FooMain {

  public static int SHARED_INT = 0;

  public static void main(String[] args) throws Exception {
    System.out.println("started");
    Random random = new Random();
    FooMain fooMain = new FooMain();
    for (int i = 0; i < 10_000; i++) {
      System.out.println("Coded message " + fooMain.m1(random.nextInt(100)));
      SHARED_INT = random.nextInt(100); // <-- line# 13
      Thread.sleep(1000);
    }
  }

  private int m1(int num1) {
    int num2 = num1 + 1;
    int num3 = num2 + 1;
    return m2(num2);
  }

  private int m2(int num1) {
    int num3 = num1 + 1;
    return m3(num3);
  }

  private int m3(int num1) {
    int num4 = num1 + 1;
    return m4(num4);
  }

  private int m4(int num1) {
    int num5 = num1 + 1;
    return m5(num5);
  }

  private int m5(int num1) {
    int num6 = num1 + 1;
    return num6;
  }
}

我尝试使用此有效负载设置断点

"breakpoint": {
      "id": "<some-id>",
      "location": {
        "path": "FooMain.java",
        "line": 13
      },
      "expressions": [
        "i"
      ],
      "create_time": "2021-09-13T10:03:30.537Z",
      "action": "LOG",
      "log_message_format": "Message received, id = $0"
    }

错误

I0913 09:59:24.572947  3128 jvm_breakpoint.cc:118] Line 13 in method main resolved to method ID: 0x7fe7b00013d8, location: 54
W0913 09:59:24.572988  3128 expression_util.cc:97] Expression could not be compiled
Input: i
AST:  ( statement i )
Error message: ("Identifier $0 not found", "i")
I0913 09:59:24.573019  3128 jvm_breakpoint.cc:729] Activating breakpoint f0cec009-1f7a-4eec-88d5-6316634d87a0, path: FooMain.java, line: 13
I0913 09:59:24.573025  3128 jvm_breakpoints_manager.cc:295] Setting new JVMTI breakpoint, method = 0x7fe7b00013d8, location = 0x36
I0913 09:59:24.573696  3233 jni_logger.cc:31] transmitBreakpointUpdate format: json, breakpointId: f0cec009-1f7a-4eec-88d5-6316634d87a0, breakpoint: {"createTime":"2021-09-13T09:59:21.138Z","evaluatedExpressions":[{"name":"i","status":{"description":{"format":"Identifier $0 not found","parameters":["i"]},"isError":true,"refersTo":"VARIABLE_NAME"}}],"expressions":["i"],"id":"f0cec009-1f7a-4eec-88d5-6316634d87a0","location":{"line":13,"path":"FooMain.java"},"logMessageFormat":"Message received, id = $0"}
.

使用 Java 11(采用openjdk,11.0.11+9)。预期的行为是记录表达式。您能帮我理解这里的错误吗?

【问题讨论】:

    标签: java google-cloud-debugger


    【解决方案1】:

    我必须使用-g (javac -g ...) 标志进行编译以保留调试符号。

    【讨论】:

      【解决方案2】:

      for 循环中你应该写:

      for (int i = 0; i < 10000; i++)
      

      由于您编写的代码在“10 和 000”之间有 underscore(_),这是无效的。请让我知道您的问题是否已解决。

      【讨论】:

      • _ 是一个有效的标识符。
      • 你是否尝试过不带下划线_
      • 我试过没有_,但仍然是同样的错误。注意:这不是 Java 端的编译错误。这是来自代理的运行时
      • 谢谢,您还有什么其他的想法吗?
      猜你喜欢
      • 1970-01-01
      • 2013-11-12
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 2013-06-01
      • 1970-01-01
      • 2018-03-16
      • 2019-06-06
      相关资源
      最近更新 更多