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.

Java 9 (JDK-9) support for guice

See original GitHub issue

I am evaluating my projects with a pre-release Java 9 SDK. It’s using recent guice that fails to inject the dependencies. Guice is trying to alter some classes in java.base module via setAccessible(...) Reflection call. Many other DI frameworks suffer from the same issue.

Are you currently working on Java 9 support for guice?

I used Java(TM) SE Runtime Environment (build 9-ea+159) and guice 1.4.1. Build target is Java 1.8.

Here is the stack trace that occured when DI-ing:

Exception in thread "Thread-0" java.lang.ExceptionInInitializerError
      at com.google.inject.internal.cglib.reflect.$FastClass$Generator.getProtectionDomain(FastClass.java:73)
      at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:206)
      at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:65)
      at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:252)
      at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:203)
      at com.google.inject.internal.ProviderMethod.create(ProviderMethod.java:69)
      at com.google.inject.internal.ProviderMethodsModule.createProviderMethod(ProviderMethodsModule.java:275)
      at com.google.inject.internal.ProviderMethodsModule.getProviderMethods(ProviderMethodsModule.java:144)
      at com.google.inject.internal.ProviderMethodsModule.configure(ProviderMethodsModule.java:123)
      at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
      at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:349)
      at com.google.inject.spi.Elements.getElements(Elements.java:110)
      at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:138)
      at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
      at com.google.inject.Guice.createInjector(Guice.java:99)
      at de.client.main.Factory.createInjector(Factory.java:248)
      at de.client.main.Main$1$1.run(Main.java:76)
      at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @a42cff
      at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:335)
      at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:278)
      at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:196)
      at java.base/java.lang.reflect.Method.setAccessible(Method.java:190)
      at com.google.inject.internal.cglib.core.$ReflectUtils$1.run(ReflectUtils.java:52)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at com.google.inject.internal.cglib.core.$ReflectUtils.<clinit>(ReflectUtils.java:42)
      ... 21 more

I can surpass that issue using the VM args --add-opens java.base/java.lang=ALL-UNNAMED

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:20
  • Comments:51 (16 by maintainers)

github_iconTop GitHub Comments

16reactions
bartlomiej-dawidowcommented, Nov 3, 2017

Java 9 was released a few weeks ago, it’s high time to update Guice.

9reactions
anthraxxcommented, Feb 19, 2018

What exactly is left? I stronly think its solid enough for a release, any minor additional java9 related changes can go into a fixup point relese. Guice with java9 is really unusable and its just getting worse and wore the more time passes. Whatever is left, it seems good enough to get a release now and a possible fixup later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java Platform, Standard Edition Oracle JDK 9 Migration Guide
The purpose of this guide is to help you identify potential issues and give you suggestions on how to proceed as you migrate...
Read more >
State of Gradle Java 9 Support
This post provides an overview of Gradle's Java 9 support, touching on runtime, cross-compilation, MRJARs, and Jigsaw modules support.
Read more >
Java 9 - Quick Guide - Tutorialspoint
Java 9 - Quick Guide, JAVA 9 (aka jdk 1.9) is a major release of JAVA ... API in Java SE 9 has...
Read more >
java - Spring: @Resource injection stopped working under JDK9
Which version of Spring is this? Spring 5 seems to be the first version to support JDK 9. – Alan Bateman. Sep 29,...
Read more >
Java Versions and Features - Marco Behler
And then learn, from a guide like this, what additional features came in Java 9-19 and use them whenever you can.
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