-
Notifications
You must be signed in to change notification settings - Fork 38.4k
IllegalAccess to Unnamed Module #26440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
From a quick glance, it should help to declare your config class as A standard configuration class leads to the create of a CGLIB subclass at runtime (similar to a target-class AOP proxy but for a different purpose), and that particular part leads to the illegal access exception. We need to investigate why the unnamed module is involved there to begin with; that subclass should rather live in the same module than your config class. |
Using anyone of the 3 way (change @configuration, omitting @configuration,
add opens ALL_UNNAMED), same result.
A slight different error:
Exception in thread "main"
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'configTest': Injection of autowired dependencies failed;
nested exception is java.lang.reflect.InaccessibleObjectException: Unable
to make field private java.lang.String it.ceschi.owm.ConfigTest.test
accessible: module ceschi.owm does not "opens it.ceschi.owm" to unnamed
module @2631f68c
at [email protected]
/org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:405)
at [email protected]
/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1415)
at [email protected]
/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:608)
at [email protected]
/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531)
at [email protected]
/org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at [email protected]
/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at [email protected]
/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at [email protected]
/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at [email protected]
/org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)
at [email protected]
/org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:923)
at [email protected]
/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:588)
at [email protected]
/org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:93)
at ceschi.owm/it.ceschi.owm.OWMMain.main(OWMMain.java:34)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make
field private java.lang.String it.ceschi.owm.ConfigTest.test accessible:
module ceschi.owm does not "opens it.ceschi.owm" to unnamed module @2631f68c
at
java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:361)
at
java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:301)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
at
org.springframework.util.ReflectionUtils.makeAccessible(ReflectionUtils.java:785)
at [email protected]
/org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:666)
at [email protected]
/org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
at [email protected]
/org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
... 12 more
Il giorno lun 25 gen 2021 alle ore 11:46 Juergen Hoeller <
[email protected]> ha scritto:
… From a quick glance, it should help to declare your config class as
@configuration(proxyBeanMethods=false), or simply omitting the
@configuration annotation completely. That said, an opens declaration for
ALL-UNNAMED should also work.
A standard configuration class leads to the create of a CGLIB subclass at
runtime (similar to a target-class AOP proxy but for a different purpose),
and that particular part leads to the illegal access exception. We need to
investigate why the unnamed module is involved there to begin with; that
subclass should rather live in the same module than your config class.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#26440 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASRCK4IUWNRP4UNE3RGBS4LS3VDXPANCNFSM4WRQVS4Q>
.
|
You did get one step further at least :-) This is a different cause: Your private It looks like your |
Yes, that was my fault (mind already turned off... it happens).
I put the @value on the variable, not on the setter method.
Now it work.
Many Thanks
Il giorno lun 25 gen 2021 alle ore 12:49 Juergen Hoeller <
[email protected]> ha scritto:
… You did get one step further at least :-) This is a different cause: Your
private @value field which will require an opens declaration in any case
since exports only covers the public surface of your classes.
Alternatively, you could turn that field into a public setter method
annotated with the same @value annotation.
It looks like your opens declaration does not work as intended. Please
check the ALL-UNNAMED spelling (IIRC it only works with the regular
hyphen, not with an underscore). Also, it might help to explicitly declare requires
spring.core since that's where Spring's reflection infrastructure lives,
although I would not expect that to be necessary.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#26440 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASRCK4MCKXQ4AMQK34BXH2TS3VLFHANCNFSM4WRQVS4Q>
.
|
This comment was marked as spam.
This comment was marked as spam.
I think this issue has run its course and is no longer actionable. |
Issue with Spring 5.3.3 ->
Main Class
ConfigTest.class (in the same package of Main Class)
application.properties file
test.value = this is a test!
module-info.java
when I try to run it, the following error happen:
As for what the unnamed module can be, i don't know. I tried to open in module-info my module, but nothing changed.
I even opened the module to all, to java.lang, java.base or to cglib.
Running on Windows 10 with JDK 15.0.2 or OpenJDK 15.0.1, same issue.
I also tried removing the @value in the config Class, with no change.
The only thing that work is changing
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigTest.class);
to
ApplicationContext context = new AnnotationConfigApplicationContext();
or putting Maven dependency to Classpath and not to Modulepath.
The text was updated successfully, but these errors were encountered: