Skip to content

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

Closed
DarkCeschi opened this issue Jan 25, 2021 · 6 comments
Closed

IllegalAccess to Unnamed Module #26440

DarkCeschi opened this issue Jan 25, 2021 · 6 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression)

Comments

@DarkCeschi
Copy link

Issue with Spring 5.3.3 ->
Main Class

/**
 * @param args
 */
public static void main(String[] args) {
     ApplicationContext context = new AnnotationConfigApplicationContext(ConfigTest.class);
}

ConfigTest.class (in the same package of Main Class)

@Configuration
@PropertySource("application.properties")
public class ConfigTest {
	
    @Value(value = "test.value")
    private String test;

     /**
      * @return the test
      */
     public String getTest() {
          return test;
     } 

application.properties file
test.value = this is a test!

module-info.java

module ceschi.owm {
	requires spring.context;
	requires spring.beans;
        exports it.ceschi.owm;
}

when I try to run it, the following error happen:

Exception in thread "main" org.springframework.cglib.core.CodeGenerationException: java.lang.IllegalAccessException-->module ceschi.owm does not open it.ceschi.owm to unnamed module @25bfcafd
	at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:514)
	at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363)
	at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:585)
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110)
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108)
	at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
	at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134)
	at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319)
	at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:572)
	at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:419)
	at [email protected]/org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:137)
	at [email protected]/org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:109)
	at [email protected]/org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:443)
	at [email protected]/org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:273)
	at [email protected]/org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:299)
	at [email protected]/org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:134)
	at [email protected]/org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:751)
	at [email protected]/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:569)
	at [email protected]/org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:93)
	at ceschi.owm/it.ceschi.owm.OWMMain.main(OWMMain.java:29)
Caused by: java.lang.IllegalAccessException: module ceschi.owm does not open it.ceschi.owm to unnamed module @25bfcafd
	at java.base/java.lang.invoke.MethodHandles.privateLookupIn(MethodHandles.java:255)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:508)
	... 22 more

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 25, 2021
@jhoeller
Copy link
Contributor

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.

@jhoeller jhoeller self-assigned this Jan 25, 2021
@jhoeller jhoeller added the in: core Issues in core modules (aop, beans, core, context, expression) label Jan 25, 2021
@DarkCeschi
Copy link
Author

DarkCeschi commented Jan 25, 2021 via email

@jhoeller
Copy link
Contributor

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.

@DarkCeschi
Copy link
Author

DarkCeschi commented Jan 25, 2021 via email

@JJBRT

This comment was marked as spam.

@snicoll
Copy link
Member

snicoll commented Sep 21, 2023

I think this issue has run its course and is no longer actionable.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2023
@snicoll snicoll removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression)
Projects
None yet
Development

No branches or pull requests

5 participants