Skip to content

Cannot launch debug session using JDK16 #970

@0dinD

Description

@0dinD

When using JDK16 (tested with AdoptOpenJDK, HotSpot), you cannot launch a debug session, because the extension throws an exception:
image

This is especially cumbersome for new users, who will be quite likely to just download the latest JDK and therefore run into this problem as soon as they try to run their code. In fact, I believe even the Java Coding Pack will install JDK16 by default, right?

Environment
  • Operating System: Windows 10
  • JDK version: AdoptOpenJDK 16 (HotSpot)
  • Visual Studio Code version: 1.54.3
  • Java extension version: 0.76.0
  • Java Debugger extension version: 0.32.0
Steps To Reproduce
  1. Use JDK16 to launch jdt.ls (this is key)
  2. Try to start a debug session, via code lens for example

Relevant exception in the log:

{
  message: '[Error - 14:51:32] 21 mars 2021 14:51:32 [error response][launch]: class com.microsoft.java.debug.core.adapter.handler.LaunchUtils (in unnamed module @0x48d1eecf) cannot access class sun.security.action.GetPropertyAction (in module java.base) because module java.base does not export sun.security.action to unnamed module @0x48d1eecf\n' +
    'class com.microsoft.java.debug.core.adapter.handler.LaunchUtils (in unnamed module @0x48d1eecf) cannot access class sun.security.action.GetPropertyAction (in module java.base) because module java.base does not export sun.security.action to unnamed module @0x48d1eecf\n' +
    'java.lang.IllegalAccessError: class com.microsoft.java.debug.core.adapter.handler.LaunchUtils (in unnamed module @0x48d1eecf) cannot access class sun.security.action.GetPropertyAction (in module java.base) because module java.base does not export sun.security.action to unnamed module @0x48d1eecf\r\n' +
    '\tat com.microsoft.java.debug.core.adapter.handler.LaunchUtils.getTmpDir(LaunchUtils.java:113)\r\n' +
    '\tat com.microsoft.java.debug.core.adapter.handler.LaunchUtils.cleanupTempFiles(LaunchUtils.java:130)\r\n' +
    '\tat com.microsoft.java.debug.core.adapter.handler.LaunchUtils.generateArgfile(LaunchUtils.java:88)\r\n' +
    '\tat com.microsoft.java.debug.core.adapter.handler.LaunchRequestHandler.handleLaunchCommand(LaunchRequestHandler.java:132)\r\n' +
    '\tat com.microsoft.java.debug.core.adapter.handler.LaunchRequestHandler.handle(LaunchRequestHandler.java:81)\r\n' +
    '\tat com.microsoft.java.debug.core.adapter.DebugAdapter.lambda$dispatchRequest$0(DebugAdapter.java:87)\r\n' +
    '\tat java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1183)\r\n' +
    '\tat java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2305)\r\n' +
    '\tat com.microsoft.java.debug.core.adapter.DebugAdapter.dispatchRequest(DebugAdapter.java:86)\r\n' +
    '\tat com.microsoft.java.debug.core.adapter.ProtocolServer.dispatchRequest(ProtocolServer.java:118)\r\n' +
    '\tat com.microsoft.java.debug.core.protocol.AbstractProtocolServer.lambda$new$0(AbstractProtocolServer.java:78)\r\n' +
    '\tat io.reactivex.internal.observers.LambdaObserver.onNext(LambdaObserver.java:60)\r\n' +
    '\tat io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:200)\r\n' +
    '\tat io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:252)\r\n' +
    '\tat io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)\r\n' +
    '\tat io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)\r\n' +
    '\tat java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\r\n' +
    '\tat java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)\r\n' +
    '\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)\r\n' +
    '\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)\r\n' +
    '\tat java.base/java.lang.Thread.run(Thread.java:831)\r\n',
  level: 'info',
  timestamp: '2021-03-21 14:51:32.493'
}
Current Result

image

Expected Result

No exception is thrown, the debug session starts like normal.

Additional Information

As you might be able to tell, this exception has something to do with the module system. More specifically, it seems that in JDK16, sun.security.action is no longer exported from the java.base module, which causes an exception when this extension tries to use the sun.security.action.GetPropertyAction class. After some investigation, it seems like this is related to JEP 396, which was implemented in JDK16.

The solution then, is to either migrate away from these internal APIs, or to add more command line flags to explicitly allow their usage. I was able to use the following workaround to get this extension working using JDK16:

  1. Set the java.jdt.ls.vmargs setting to --add-exports java.base/sun.security.action=ALL-UNNAMED
  2. Restart VS Code
  3. You should now be able to launch a debug session

Note: I've only tested the Java debug extension, but it's possible that some of the other Java extension are affected as well. You should probably look over the usage of these internal APIs in all of the Java extensions.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions