Bug 400998 - Debugger shows wrong instance of static variable in multi-classloader scenario
Summary: Debugger shows wrong instance of static variable in multi-classloader scenario
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.17   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-16 16:25 EST by Michael Schierl CLA
Modified: 2023-01-02 04:38 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 Michael Schierl CLA 2013-02-16 16:25:58 EST
This bug mostly happens for me when debugging two JSP webapps that run on the same Tomcat server and share a common project dependency.

To make it easier to reproduce without all that setup, here is a contrived minimal example to reproduce the bug without needing any WST plugins or Tomcat:

* In your workspace, create two Java projects, "Loader" and "Loaded". Do not add any build path dependencies between them.

* Add this class to the Loaded project:

//////////////////////////////////////////////////////////////////////
import java.util.*;

public class LoadedThread extends Thread {
	
	private static List<String> staticList = new ArrayList<String>();
	private String value;
	
	public LoadedThread(String value) {
		this.value = value;
		start();
	}
	
	@Override
	public void run() {
		staticList.add(value);
		// place breakpoint in next line:
		System.out.println(staticList);
	}
}
//////////////////////////////////////////////////////////////////////

* Add this class to the Loader project (in case the name of the Loaded project is different or your output folder is not called "bin", don't forget to update the path in the first line of the main method):

//////////////////////////////////////////////////////////////////////
import java.io.*;
import java.net.*;

public class CustomLoader {
	public static void main(String[] args) throws Exception {
		URL[] urls = new URL[] {new File("../Loaded/bin").toURI().toURL()};
		URLClassLoader loader1 = new URLClassLoader(urls);
		URLClassLoader loader2 = new URLClassLoader(urls);
		loader1.loadClass("LoadedThread").getConstructor(String.class).newInstance("First");
		loader2.loadClass("LoadedThread").getConstructor(String.class).newInstance("Second");
	}
}
//////////////////////////////////////////////////////////////////////

* Run this class as "Java Application", it should output both "[First]" and "[Second]" (in unpredictable order).

* Edit the run configuration of the Java Application: on the source tab, add "Loaded" project to source lookup path (or debugger will not find it in next step).

* Place breakpoint as described in the comment of the "Loaded" class and run again in debug mode. Two breakpoints should fire in two different threads.

* Select the threads in the Debug view and hover over the "value" and "staticList" variables with the mouse until a small window appears that shows the current values. 

Actual result: 
You will observe, that in one of the two threads, the "staticList" variable shows the variable of the wrong class loader (in my example, the second thread had value "Second" but staticList "[First]").

Expected result:
One thread should have value "First" and staticList "[First]", the other should have value "Second" and staticList "[Second]".

Thanks for reading, and of course for fixing :-)
Comment 1 Eclipse Genie CLA 2020-10-15 07:18:08 EDT
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.
Comment 2 Michael Schierl CLA 2020-10-17 17:34:45 EDT
As of 2020-09 (4.17.0), the bug still happens in the tooltip when hovering over the variable. It does not (or no longer) happen when marking the variable and pressing Ctrl+Shift+I (Inspect element).

Therefore, I can live with the workaround of using Inspect on static variables and not relying on the tooltip values.
Comment 3 Sarika Sinha CLA 2020-10-19 07:00:12 EDT
@Gayan,
Will you be interested in looking at this?
Comment 4 Gayan Perera CLA 2020-10-19 07:12:50 EDT
@Sarika Iā€™m bit busy with some work these days. So if someone else can look at this that would be good.
Comment 5 Eclipse Genie CLA 2022-12-25 12:31:37 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.
Comment 6 Michael Schierl CLA 2022-12-25 15:27:14 EST
As of 2022-12 (4.26.0), bug is unchanged from what I described in comment 2.