Bug 574211 - OSGiWeavingAdaptor.defineClass fails without --illegal-access=warn
Summary: OSGiWeavingAdaptor.defineClass fails without --illegal-access=warn
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Runtime (show other bugs)
Version: 1.9.6   Edit
Hardware: All Windows 10
: P3 blocker (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-15 10:27 EDT by Reto Urfer CLA
Modified: 2021-06-21 11:12 EDT (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 Reto Urfer CLA 2021-06-15 10:27:58 EDT
The method OSGiWeavingAdaptor.defineClass still calls the protected method ClassLoader.defineClass(String, byte[],int,int) and defines setAccessible(true) for this method which results in an error with JDK16 if you not not explicitly define --illegal-access=warn/debug. Only defining --add-opens java.base/java.lang=ALL-UNNAMED does not solve the problem.

Unfortunately --illegal-access is deprecated and may be removed with JDK17 (https://openjdk.java.net/jeps/403). This JEP lists exactly this problem in its "Risk and Assumptions" section and contains the following description how it has to be solved:
"Frameworks that use the protected defineClass methods of java.lang.ClassLoader in order to define new classes in existing class loaders. Such frameworks should instead use java.lang.invoke.MethodHandles.Lookup::defineClass, which has been available since JDK 9."
If --illegal-access is really removed in JDK17 we are not able to run our Eclipse RCP applcation with JDK17 which is our intention because JDK17 is the next release containing LTS.
Comment 1 Thomas Watson CLA 2021-06-16 09:27:17 EDT
I assume you are referring to org.eclipse.equinox.weaving.aspectj.loadtime.OSGiWeavingAdaptor

See bug 470000.  This moved to the AspectJ project
Comment 2 Reto Urfer CLA 2021-06-16 14:13:51 EDT
Ok, thank, then i will open this bug there
Comment 3 Reto Urfer CLA 2021-06-16 14:24:14 EDT
Sorry, i just saw that you have aleady moved the issue to the aspectj project
Comment 4 Reto Urfer CLA 2021-06-17 05:37:28 EDT
I am a little bit confused because the Eclipse RCP app having the described problem works fine from within Eclipse IDE with the following definitions

--add-opens java.base/java.lang=ALL-UNNAMED
--illegal-access=deny

so it seems that adding --add-opens java.base/java.lang=ALL-UNNAMED should fix the problem.
But when i deploy the app by exporting the product and start it with app.exe the app.ini file generated contains

-vmargs
--add-opens java.base/java.lang=ALL-UNNAMED
--illegal-access=deny

but it fails. Can it be that there is only a problem with the native launcher app?
Comment 5 Reto Urfer CLA 2021-06-17 08:42:54 EDT
i just found a solution for the problem. If you define

-vmargs
--add-opens=java.base/java.lang=ALL-UNNAMED
--illegal-access=deny

then it works also if the rcp app ist started with eclipse.exe
Comment 6 Thomas Watson CLA 2021-06-21 11:12:32 EDT
If you are defining classes with the bundle class loader it may be possible to use the public method:

org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(String, byte[], ClasspathEntry)