Bug 578148 - Evaluations are not working if the method contains local class
Summary: Evaluations are not working if the method contains local class
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.23   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-11 01:44 EST by Jinbo Wang CLA
Modified: 2024-01-03 08:00 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jinbo Wang CLA 2022-01-11 01:44:25 EST
Sample:
```
import java.util.List;
import java.util.ArrayList;

public class Hello {
    public static void main(String[] args) {
        
        class Position {
            int x;
            int y;
        }
        
        String msg = "Hello World";
        List<Position> x = new ArrayList<>();
        System.out.println(msg + x); // Add a breakpoint here
    }

}

```

Stop at the line '// Add a breakpoint here', it fails to evaluate local variables 'msg', 'x'.

But if changing the local class Position as inner class of Hello, the evaluation works well.
Comment 1 Sarika Sinha CLA 2022-01-11 01:59:29 EST
@Gayan,
Can you check this?
Comment 2 Jinbo Wang CLA 2022-01-11 04:00:10 EST
When evaluating the expression 'x' on the breakpoint, the evaluation engine collects all context-visible variables and wrap them into arguments of a virtual ___run method that's used to compile the target expression.


```
import java.util.List;
import java.util.ArrayList;
public class Hello{
static void ___run(java.lang.String[] args, java.lang.String msg, java.util.List<new org.springframework.samples.petclinic.Hello(){}> x) throws Throwable {
return x;
}
public static void main (String[] args){
}
}
```

For the case of local class, the EvaluationSourceGenerator converts the type name List<Position> of variable x to java.util.List<new org.springframework.samples.petclinic.Hello(){}>, which does not comply to the Java syntax, so the compiled expression will report a compilation error.

The question is how do we handle the local class of the target frame context?
Comment 3 Eclipse Genie CLA 2024-01-03 08:00:24 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.