vscode-java
vscode-java copied to clipboard
Access restriction error in Java language server log
Hi,
I have recently started using VSCode with your extension for a Gradle project, however I come across the "Access restriction" error which was flagged in other issues (#120 and #219). I have tried the proposed solution in those threads but without any luck so far.
Below are few errors that I got:
Access restriction: The type 'Signal' is not API (restriction on required library 'C:\Program Files\JAVA\openjdk11.0.5\lib\jrt-fs.jar'); code: 16777523;
Access restriction: The method 'HttpExchange.getRequestHeaders()' is not API (restriction on required library 'C:\Program Files\JAVA\openjdk11.0.5\lib\jrt-fs.jar'); code: 16777523;
And they are primarily from the below library import:
import sun.misc.Signal;
import sun.misc.SignalHandler;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
I have integrated below access rule into my build.gradle:
import org.gradle.plugins.ide.eclipse.model.AccessRule
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
classpath {
file {
whenMerged {
def jre = entries.find { it.path.contains 'org.eclipse.jdt.launching.JRE_CONTAINER' }
jre.accessRules.add(new AccessRule('accessible', 'sun/misc/**'))
jre.accessRules.add(new AccessRule('accessible', 'com/sun/net/**'))
}
}
}
}
And the generated .classpath is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/">
<accessrules>
<accessrule kind="accessible" pattern="sun/misc/**"/>
<accessrule kind="accessible" pattern="com/sun/net/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
It looks to me that the .classpath is ok, but somehow I am still getting the same error. The option to clean the Java language server workspace does not seem to help either. Appreciate if you can shed some lights on this.
Can you please attach a sample project?
@fbricon I afraid I cannot attach the problematic project here directly as it is not open source. I will try creating a dummy project with those library dependencies and see if I can re-produce the problem there. In the mean time, is there anything on top of your head that I should check for the problematic project? Thanks!
@fbricon I realized that there are actually some exceptions in the Java language server log file, not sure if that matters:
!ENTRY org.eclipse.jdt.core 4 4 2019-12-12 14:33:29.598
!MESSAGE Exception while reading last build state for: P/jdt.ls-java-project
!STACK 1
org.eclipse.core.runtime.CoreException: Error reading last build state for project jdt.ls-java-project
at org.eclipse.jdt.internal.core.JavaModelManager.readState(JavaModelManager.java:4161)
at org.eclipse.jdt.internal.core.JavaModelManager.getLastBuiltState(JavaModelManager.java:2287)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.getLastState(JavaBuilder.java:456)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:189)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:833)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:220)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:263)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:316)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:319)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:371)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:392)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:154)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:244)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.NullPointerException
at org.eclipse.jdt.internal.compiler.util.JRTUtil.walkModuleImage(JRTUtil.java:158)
at org.eclipse.jdt.internal.core.builder.ClasspathJrt.loadModules(ClasspathJrt.java:127)
at org.eclipse.jdt.internal.core.builder.ClasspathJrt.<init>(ClasspathJrt.java:68)
at org.eclipse.jdt.internal.core.builder.ClasspathLocation.forJrtSystem(ClasspathLocation.java:146)
at org.eclipse.jdt.internal.core.builder.State.read(State.java:290)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.readState(JavaBuilder.java:161)
at org.eclipse.jdt.internal.core.JavaModelManager.readState(JavaModelManager.java:4153)
... 15 more
!SUBENTRY 1 org.eclipse.jdt.core 4 2 2019-12-12 14:33:29.598
!MESSAGE Error reading last build state for project jdt.ls-java-project
!STACK 0
java.lang.NullPointerException
at org.eclipse.jdt.internal.compiler.util.JRTUtil.walkModuleImage(JRTUtil.java:158)
at org.eclipse.jdt.internal.core.builder.ClasspathJrt.loadModules(ClasspathJrt.java:127)
at org.eclipse.jdt.internal.core.builder.ClasspathJrt.<init>(ClasspathJrt.java:68)
at org.eclipse.jdt.internal.core.builder.ClasspathLocation.forJrtSystem(ClasspathLocation.java:146)
at org.eclipse.jdt.internal.core.builder.State.read(State.java:290)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.readState(JavaBuilder.java:161)
at org.eclipse.jdt.internal.core.JavaModelManager.readState(JavaModelManager.java:4153)
at org.eclipse.jdt.internal.core.JavaModelManager.getLastBuiltState(JavaModelManager.java:2287)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.getLastState(JavaBuilder.java:456)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:189)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:833)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:220)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:263)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:316)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:319)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:371)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:392)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:154)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:244)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
is there any solution to this? or what is "the right way" to solve the original problem?
@lfarkas you can try to call the 'Java: Clean the Java language server workspace' command.
@lfarkas you can try to call the 'Java: Clean the Java language server workspace' command.
thanks it's working!
There are two issues:
- one is tip says: Missing Gradle project configuration file: .settings/org.eclipse.buildship.core.prefs, cos I touch a file org.eclipse.buildship.core.prefs, and added the "org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore" to file. but it doesn't work at all.
- two issue is : Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar')
- env:
- apple m1 pro - latest java pack - use Oracle JDK 1.8 to run the program, and use OpenJDK 17 to jdt, as the java server. - Help! It's been bothering me all day. @fbricon @snjeza @lfarkas
some info as follow:
!ENTRY org.eclipse.jdt.ls.core 4 0 2022-06-24 00:40:59.039 !MESSAGE Error occured while building workspace. Details: message: Access restriction: The method 'OperatingSystemMXBean.getProcessCpuLoad()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 70 message: Access restriction: The method 'OperatingSystemMXBean.getSystemCpuLoad()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 78 message: Access restriction: The method 'OperatingSystemMXBean.getTotalPhysicalMemorySize()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 94 message: Access restriction: The method 'OperatingSystemMXBean.getFreePhysicalMemorySize()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 102 message: Access restriction: The method 'OperatingSystemMXBean.getTotalSwapSpaceSize()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 109 message: Access restriction: The method 'OperatingSystemMXBean.getFreeSwapSpaceSize()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 116 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 5 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 44 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 47 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/common/src/main/java/org/tron/common/prometheus/OperatingSystemExports.java; line: 51 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 3 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 41 message: Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 41 message: Access restriction: The method 'OperatingSystemMXBean.getTotalPhysicalMemorySize()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 75 message: Access restriction: The method 'OperatingSystemMXBean.getFreePhysicalMemorySize()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 76 message: Access restriction: The method 'OperatingSystemMXBean.getSystemCpuLoad()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 77 message: Access restriction: The method 'OperatingSystemMXBean.getProcessCpuLoad()' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar'); code: 16777523; resource: /Users/blake.chen/work/code/opensource/java-tron/framework/src/main/java/org/tron/core/services/NodeInfoService.java; line: 84
!ENTRY org.eclipse.jdt.ls.core 1 0 2022-06-24 00:41:01.712 !MESSAGE >> workspace/executeCommand vscode.java.resolveBuildFiles
@ai-chen2050 could you try the following patch:
index 713e0a213..fab67d82c 100644
--- a/common/build.gradle
+++ b/common/build.gradle
@@ -1,6 +1,8 @@
+import org.gradle.plugins.ide.eclipse.model.AccessRule
plugins {
id 'java'
}
+apply plugin: 'eclipse'
version '1.0.0'
@@ -68,3 +70,15 @@ jacocoTestReport {
}
}
}
+
+eclipse {
+ classpath {
+ file {
+ whenMerged {
+ def jre = entries.find { it.path.contains 'org.eclipse.jdt.launching.JRE_CONTAINER' }
+ jre.accessRules.add(new AccessRule('accessible', 'sun/misc/**'))
+ jre.accessRules.add(new AccessRule('accessible', 'com/sun/**'))
+ }
+ }
+ }
+}
diff --git a/framework/build.gradle b/framework/build.gradle
index e656c73b0..021f2fe28 100644
--- a/framework/build.gradle
+++ b/framework/build.gradle
@@ -1,9 +1,11 @@
+import org.gradle.plugins.ide.eclipse.model.AccessRule
plugins {
id "org.sonarqube" version "2.6"
}
apply plugin: 'application'
apply plugin: 'checkstyle'
+apply plugin: 'eclipse'
mainClassName = 'org.tron.program.FullNode'
@@ -281,3 +283,15 @@ task copyToParent(type: Copy) {
}
build.finalizedBy(copyToParent)
+
+eclipse {
+ classpath {
+ file {
+ whenMerged {
+ def jre = entries.find { it.path.contains 'org.eclipse.jdt.launching.JRE_CONTAINER' }
+ jre.accessRules.add(new AccessRule('accessible', 'sun/misc/**'))
+ jre.accessRules.add(new AccessRule('accessible', 'com/sun/**'))
+ }
+ }
+ }
+}
@ai-chen2050 could you try the following patch:
index 713e0a213..fab67d82c 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,6 +1,8 @@ +import org.gradle.plugins.ide.eclipse.model.AccessRule plugins { id 'java' } +apply plugin: 'eclipse' version '1.0.0' @@ -68,3 +70,15 @@ jacocoTestReport { } } } + +eclipse { + classpath { + file { + whenMerged { + def jre = entries.find { it.path.contains 'org.eclipse.jdt.launching.JRE_CONTAINER' } + jre.accessRules.add(new AccessRule('accessible', 'sun/misc/**')) + jre.accessRules.add(new AccessRule('accessible', 'com/sun/**')) + } + } + } +} diff --git a/framework/build.gradle b/framework/build.gradle index e656c73b0..021f2fe28 100644 --- a/framework/build.gradle +++ b/framework/build.gradle @@ -1,9 +1,11 @@ +import org.gradle.plugins.ide.eclipse.model.AccessRule plugins { id "org.sonarqube" version "2.6" } apply plugin: 'application' apply plugin: 'checkstyle' +apply plugin: 'eclipse' mainClassName = 'org.tron.program.FullNode' @@ -281,3 +283,15 @@ task copyToParent(type: Copy) { } build.finalizedBy(copyToParent) + +eclipse { + classpath { + file { + whenMerged { + def jre = entries.find { it.path.contains 'org.eclipse.jdt.launching.JRE_CONTAINER' } + jre.accessRules.add(new AccessRule('accessible', 'sun/misc/**')) + jre.accessRules.add(new AccessRule('accessible', 'com/sun/**')) + } + } + } +}
is need compiled by myself? And install offline, right ?
git clone [email protected]:tronprotocol/java-tron.git
cd java-tron
git checkout -t origin/master
git apply <patch>
code .