0

I have a program in java in eclipse 2022-06. I had realized that the jre and compiler versions were different versions as soon as I updated both of them to 1.8 the error disappeared but somehow it has re appeared again and I don't know what could be causing this.

Is it some kind of setting or incompatibility with java versions? I would like to use Java 8 on this project.

Exception in thread "main" java.lang.reflect.InaccessibleObjectException: Unable to make protected void java.net.URLClassLoader.addURL(java.net.URL) accessible: module java.base does not "opens java.net" to unnamed module @d2cc05a
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
  • It looks like you have the security system set to reject attempts to use reflection. I'm not an expert here but I think it's not a version incompatibility. Is this running on your own system or are you getting the error on another system like a remote server or a users system? – markspace Aug 13 '22 at 16:49
  • I am running my own system @markspace – user19693987 Aug 13 '22 at 16:51
  • And your environment? If you're running a container like Tomcat or Wildfly/JBoss it'll have its own security manager. By default just the JDK has the policy file here: `java.home\lib\security\java.policy` More info: https://docs.oracle.com/javase/8/docs/technotes/guides/security/PolicyFiles.html – markspace Aug 13 '22 at 16:54
  • No container as such. I am just using eclipse and jre.1.8.0_321. @markspace – user19693987 Aug 13 '22 at 16:57
  • 2
    The stack trace includes modules, as it mentions the "unnamed module" and multiple mentions of the `java.base` module, which means you're executing this code with Java 9+, not Java 8. Modules were added in Java 9. – Slaw Aug 13 '22 at 17:21
  • @Slaw oh wow. How do I know what version and how do I change it? I mentioned above that I created this in eclipse and added a new jre which is 1.8.0 in the create a new project dialog and I changed the compiler jdk compliance to 1.8. What am I missing? – user19693987 Aug 13 '22 at 17:26
  • Did you set the project's JDK though? I don't know Eclipse, and this Q&A may be out-of-date, but perhaps [How to change JDK version for an Eclipse project](https://stackoverflow.com/questions/12588537/how-to-change-jdk-version-for-an-eclipse-project) can help. – Slaw Aug 13 '22 at 17:32
  • @slaw unfortunately, yes I have done that as well but I still seem to get this error. – user19693987 Aug 13 '22 at 17:37
  • Well, somehow your project is running on Java 9+, I'm sorry, but I don't know Eclipse well enough to know why. – Slaw Aug 13 '22 at 17:38
  • @Slaw alright thank you anyways, I will look into it. – user19693987 Aug 13 '22 at 17:39

1 Answers1

0

Please add it to your startup

--add-opens java.base/java.lang=ALL-UNNAMED

can solve the problem.

For details, you can refer to https://www.cnblogs.com/IcanFixIt/p/7144366.html But it is a Chinese website and you may need to translate it.

DAHUANGGO
  • 71
  • 1
  • 5
  • hi @DAHUANGGO what do you exactly mean by add to startup? – user19693987 Aug 13 '22 at 17:22
  • If you are using idea, you can type in the Terminal box at the bottom `--add-opens java.base/java.lang=ALL-UNNAMED`, Or in your startup items, which is your VM options: `--add-opens java.base/java.lang=ALL-UNNAMED` – DAHUANGGO Aug 13 '22 at 17:34
  • I am using eclipse. where can I try that in eclipse? – user19693987 Aug 13 '22 at 17:36
  • @user19693987 This sort of option would be set in the "VM Arguments" of a run configuration (or whatever Eclipse calls these things). But `--add-opens` is a Java 9+ option. Given you're trying to use Java 8, this won't help you. – Slaw Aug 13 '22 at 17:37
  • Is there a possibility, you try to upgrade your JDK version, try to see if it can solve the problem, I'm sorry, I just didn't see the question clearly, I thought you had a problem with upgrading JDK1.8, I'm sorry. – DAHUANGGO Aug 13 '22 at 17:43
  • @DAHUANGGO actually I can't, I am using tools that only support Java 8 – user19693987 Aug 13 '22 at 17:59