question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix support for Java modules

See original GitHub issue

Context - reported in our forum:

java.lang.IllegalAccessError: Module 'java.base' no access to: package 'java.lang' because module 'java.base' can't read module 'unnamed module @61b4e073'
	at java.base/java.lang.invoke.MethodHandle.sendResolveMethodHandle(MethodHandle.java:1237)
	at java.base/java.lang.invoke.MethodHandle.getCPMethodHandleAt(Native Method)
	at java.base/java.lang.invoke.MethodHandle.resolveInvokeDynamic(MethodHandle.java:1070)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:556)
	at co.elastic.apm.agent.profiler.SamplingProfiler.run(SamplingProfiler.java:342)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:836)

The SamplingProfiler is scheduled for execution by java.util.concurrent.ScheduledThreadPoolExecutor, which is loaded by the java.base module. For some reason, although it explicitly implements Runnable, an invokedynamic resolution is done, causing this failure.

The unnamed module should have all it’s packages exported automatically, however this doesn’t mean they can be accessed by named modules.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
raphwcommented, Oct 10, 2020

Yes, any unnamed module exports all of its packages and reads all packages that are exported to any module, what is implicit for any unnamed module (or open module). In this case, you have to adjust the module graph. If you can avoid it, I’d however make sure any class you provide is only ever loaded once within a hierarchy of class loaders. It will only cause trouble.

0reactions
eyalkorencommented, Nov 2, 2020

Since it’s only about one agent class, it feels that the safest would be to use Unsafe (😁 ) to modify the module field of this class right after it has been loaded. If I do it conservatively enough (change the reference only if I find the right field and its type is exactly the same of the one I want to replace), we should at least not break other stuff in the JVM (🤞 )

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problems with Java modules still plague developers
The Java Platform Module System promised to standardize how Java apps modularized. But years later, the problems with Java modules remain.
Read more >
Understanding Java 9 Modules - Oracle
In this article, I introduce the Java 9 Platform Module System (JPMS), the most important new software engineering technology in Java since its...
Read more >
Java 9+ modularity: The difficulties and pitfalls of migrating ...
By looking at compatibility, migration issues, and techniques, explore the new APIs and tools, changes, deletions, and deprecations in Java ...
Read more >
Support for Java 9 Modules in IntelliJ IDEA 2017.1
In this latest version, support includes code completion in the module-info.java file, and quick fixes for adding modules to your project.
Read more >
A Guide to Java 9 Modularity - Baeldung
Services Offered – we can provide service implementations that can be consumed by other modules; Services Consumed – allows the current module ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found