JDK-8239055 : Wrong implementation of VMState.hasListener
  • Type: Bug
  • Component: core-svc
  • Sub-Component: debugger
  • Affected Version: 8,11,15
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2020-02-05
  • Updated: 2020-06-10
  • Resolved: 2020-03-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 13 JDK 15 Other
11.0.8-oracleFixed 13.0.4Fixed 15 b13Fixed openjdk8u262Fixed
Description
A DESCRIPTION OF THE PROBLEM :
https://github.com/openjdk/jdk/blob/03721247d8f3d6b2aefe2826a59c10fd1fad51cb/src/jdk.jdi/share/classes/com/sun/tools/jdi/VMState.java#L176-L178

shows that the implementation is still implemented in the same way as seen in JDK 1.8:

    synchronized boolean hasListener(VMListener listener) {
        return listeners.contains(listener);
    }

listener is of type VMListener, while listeners is declared to contain WeakReference<VMListener>, so this method never returns true.

removeListener(VMListener listener) is implemented correctly.



Comments
Fix Request (13u) I'd like to backport it to 13u as well. The patch applies cleanly.
10-06-2020

8u Fix Request: I would like to backport this patch to 8u, as it is an implementation bug, that affects jdi. Original patch applies cleanly after file path change.
23-03-2020

11u Fix Request: I would like to backport this patch to 11u, as it is on Oracle's 11.0.8 release. Original patch applies cleanly.
23-03-2020

URL: https://hg.openjdk.java.net/jdk/jdk/rev/06b31c23a9a8 User: poonam Date: 2020-03-03 17:44:10 +0000
03-03-2020

Moving from core-svc/tools -> core-svc/debugger since this is JDI related.
14-02-2020

Below patch should fix this issue in jdk/jdk diff -r 51fb05ec531d src/jdk.jdi/share/classes/com/sun/tools/jdi/VMState.java --- a/src/jdk.jdi/share/classes/com/sun/tools/jdi/VMState.java Fri Dec 20 17:17:37 2019 +0100 +++ b/src/jdk.jdi/share/classes/com/sun/tools/jdi/VMState.java Thu Feb 13 20:44:13 2020 -0800 @@ -174,7 +174,14 @@ } synchronized boolean hasListener(VMListener listener) { - return listeners.contains(listener); + Iterator<WeakReference<VMListener>> iter = listeners.iterator(); + while (iter.hasNext()) { + WeakReference<VMListener> ref = iter.next(); + if (listener.equals(ref.get())) { + return true; + } + } + return false; } synchronized void removeListener(VMListener listener) {
14-02-2020