Unable to evaluate statement, identifier not found

94 Views Asked by At

I setup the google-cloud-debug for non gcp environment. This is a sample code running with agent attached.

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;
  }
}

I try setting break-point with this payload

"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"
    }

Error

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"}
.

Using Java 11 (adoptopenjdk, 11.0.11+9). Expected behavior is to get the expression logged. Could you help me understand what is incorrect here ?

2

There are 2 best solutions below

4
On

In the for loop you should write :

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

As the code you have written having underscore(_) in between “10 and 000” which is invalid. Do let me know if your problem was solved or not.

0
On

I had to compile with -g (javac -g ...) flag to preserve debug symbols.