apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.64k stars 845 forks source link

Variables show wrong value when debugging #7696

Open frankvdh opened 1 month ago

frankvdh commented 1 month ago

Apache NetBeans version

Apache NetBeans 22

What happened

I am not sure of what triggers the fault, but in the Variables window, the wrong value is displayed for some variables. I have only seen this with java.awt.Point variables. In the attached screenshot, the value of this.curr.p is displayed as four different values in 4 places...

The Watch curr.p says its value is [6,3] in the summary line, yet the individual fields are x=2, y=1 In the Variables, this.curr.p shows [2, 2] in the summary line, with x=0 and y=0 for the individual fields.

The correct value is x=2, y=1

Screenshot 2024-08-26 045712

Language / Project Type / NetBeans Component

No response

How to reproduce

I am sorry, but I don't know what triggers this. I have only ever seen it in my current project in the last few weeks. I don't recall when it first happened, but certainly not 6 months ago. Possibly it was introduced in the latest Netbeans update? However, I have only seen it for java.awt.Point variables, and I have only been using that type recently.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Win11

JDK

jdk21

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

It seems intermittent... some variables display correct values, other don't. Usually looking at individual fields shows the correct values, whereas the summary line is often wrong. Creating a new Watch seems to give correct values... it is the update of a pre-existing Watch or Variable that shows the wrong value

Are you willing to submit a pull request?

No

matthiasblaesing commented 1 month ago

You don't say what that point is and which threads are blocked when you observe this. Trivial reason: You break on $random thread, which also has access to the variable written in parallel by a different (unbreaked) thread. Evaluating the variables does take a non-trivial amout of time, so each invocation potentially observes a different state.

frankvdh commented 1 month ago

Hi Matthias, "Point" is java.awt.Point. I am currently only using it as a convenient way to store (X,Y) integer pairs.

This is not a complex multi-threaded app. It happens even when running a single-threaded individual test, so I don't think it's related to variables being written in parallel.

Attached are source files... TracerTest has test cases (some of which fail in various ways... testInnerOuter2 [line 423] succeeds), Tracer is the class I'm trying to debug, others are just supporting classes. Tracer.zip

A breakpoint at Line 398 exhibits the fault. "curr.p" shows a value of {1, 0} but below it the value of curr.p.x is shown correctly as 2. image

As you can imagine, this displaying of incorrect values (whatever the reason) makes it very tedious to try and debug the application.

Frank

matthiasblaesing commented 1 month ago

@frankvdh please provide a minimal runnable sample (maven project?). I took your source files, moved them into a maven structure only to then notice, that it is an incomplete set of classes. I.e. the project is not runnable. Given, that the behavior at runtime is the core of the problem, the code is only of limited help.

frankvdh commented 1 month ago

New minimal project attached.

When I debug the test case, the fault is visible on the second hit of the breakpoint at line 368 of Tracer.java

Tracer.zip image

matthiasblaesing commented 1 month ago

Thank you for the project, regrettably I can't reproduce. Both the Ubuntu JDK 21 (Linux), and Amazon Corretto 21 (Windows) give consistent output:

image image

Multiple runs gave the same output when the breakpoint was hit.

What I did was this:

  1. I downloaded the example project
  2. I set a break point in `Tracer.java´, line 368
  3. Run "Debug testInnerOuter2 method" from the test menu: image 4.Wait until breakpoint is hit
  4. Add 4 watches: curr, curr.p, curr.p.x, curr.p.y

The NB Version used was 22. Which JDK did you use for the test?

frankvdh commented 4 weeks ago

Hi Matthias, I am now on holiday until December, away from my computer, so I can't do much. I was using the latest JDK, as at 31 August. NB was v22, I think. Running on Win11.

Frank

On Tue, 3 Sept 2024, 11:54 Matthias Bläsing, @.***> wrote:

Thank you for the project, regrettably I can't reproduce. Both the Ubuntu JDK 21 (Linux), and Amazon Corretto 21 (Windows) give consistent output:

image.png (view on web) https://github.com/user-attachments/assets/b9f03f5b-46fa-4c3e-8047-7a60c1d1a5dc image.png (view on web) https://github.com/user-attachments/assets/574168a2-ad3d-4621-bf87-3f7da822445d

Multiple runs gave the same output when the breakpoint was hit.

What I did was this:

  1. I downloaded the example project
  2. I set a break point in `Tracer.java´, line 368
  3. Run "Debug testInnerOuter2 method" from the test menu: image.png (view on web) https://github.com/user-attachments/assets/75aac9ca-e70b-43ae-b732-225c6597e71d 4.Wait until breakpoint is hit
  4. Add 4 watches: curr, curr.p, curr.p.x, curr.p.y

The NB Version used was 22. Which JDK did you use for the test?

— Reply to this email directly, view it on GitHub https://github.com/apache/netbeans/issues/7696#issuecomment-2327106525, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSIUYCOAVY2U4RX5D4LIH3ZUXZU7AVCNFSM6AAAAABNCWVW2SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRXGEYDMNJSGU . You are receiving this because you were mentioned.Message ID: @.***>

matthiasblaesing commented 4 weeks ago

@frankvdh there is no "latest JDK". There is one popular JDK implementation project called OpenJDK, which only supplies sources. Then there are multiple vendors (Amazon, Microsoft, Azul, Red Hat, Bellsoft, Oracle, ....) that provide binaries build from this source. But these binaries are also not identical, but contain vendor specific patches. What is more there are other projects, that retain the classpath from OpenJDK, but implement their own VM (GraalVM, OpenJ9). So which JDK flavor did you use?

frankvdh commented 4 weeks ago

Sorry, I don't know for sure. I think most likely Oracle.

On Thu, 5 Sept 2024, 2:03 am Matthias Bläsing, @.***> wrote:

@frankvdh https://github.com/frankvdh there is no "latest JDK". There is one popular JDK implementation project called OpenJDK, which only supplies sources. Then there are multiple vendors (Amazon, Microsoft, Azul, Red Hat, Bellsoft, Oracle, ....) that provide binaries build from this source. But these binaries are also not identical, but contain vendor specific patches. What is more there are other projects, that retain the classpath from OpenJDK, but implement their own VM (GraalVM, OpenJ9). So which JDK flavor did you use?

— Reply to this email directly, view it on GitHub https://github.com/apache/netbeans/issues/7696#issuecomment-2330868389, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSIUYGGP4IY4LR4LE7US6LZVAF3HAVCNFSM6AAAAABNCWVW2SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZQHA3DQMZYHE . You are receiving this because you were mentioned.Message ID: @.***>

matthiasblaesing commented 4 weeks ago

Tested now with Oracle JDK 21 and GraalVM 21 - both show consistent results. Still not reproducible. Sorry.