Injection causes IllegalAccessError depending on archiveBaseName #44676
Description
Describe the bug
I have a gradle multi-project with one Quarkus App (prj2) extending another (prj1).
(See also attached zipped reproducer project)
The settings.gradle file simply references the two sub-projects:
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
}
plugins {
id "${quarkusPluginId}" version "${quarkusPluginVersion}"
}
}
rootProject.name='project'
include 'prj1'
include 'prj2'
The gradle file of the root project is empty.
The sub-project 'prj1' simply depends on ARC:
plugins {
id 'java'
id 'io.quarkus'
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkus:quarkus-arc'
}
The project prj1
simply contains one bean referencing a second one:
@Dependent
public class BaseBean {
@Inject
ReferencedBean refBean;
public String getIdentity() {
return "BaseBean (including reference to " + refBean.getIdentity() + ")";
}
}
@Dependent
public class ReferencedBean {
public String getIdentity() {
return "ReferencedBean";
}
}
The sub-project 'prj2' depends on ARC and prj1
(and has a test):
plugins {
id 'java'
id 'io.quarkus'
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkus:quarkus-arc'
implementation project(':prj1')
testImplementation("io.quarkus:quarkus-junit5") { exclude group: 'io.quarkus', module: 'quarkus-junit5-properties' }
}
This project contains a deviation of the base bean defined in prj1
:
@Dependent
public class DerivedBean extends BaseBean {
@Override
public String getIdentity() {
return "DerivedBean extending " + super.getIdentity();
}
}
The following test in prj2
checks if the injection works as expected:
@QuarkusTest
public class BeanTest {
@Inject
DerivedBean bean;
@Test
void test() {
System.out.println(bean.getIdentity());
}
}
The test works as expected in this scenario.
However if I add the following lines changing the archive base name
in the gradle.build
file in prj1
the test will fail:
jar {
archiveBaseName = "${rootProject.name}-${project.name}"
}
The test faile with the following exception:
Failed to create test instance
org.junit.jupiter.api.extension.TestInstantiationException: Failed to create test instance
at io.quarkus.test.junit.QuarkusTestExtension.initTestState(QuarkusTestExtension.java:773)
at io.quarkus.test.junit.QuarkusTestExtension.interceptTestClassConstructor(QuarkusTestExtension.java:739)
at java.base/java.util.Optional.orElseGet(Optional.java:364)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at io.quarkus.runner.bootstrap.RunningQuarkusApplicationImpl.instance(RunningQuarkusApplicationImpl.java:90)
at io.quarkus.test.junit.QuarkusTestExtension.createActualTestInstance(QuarkusTestExtension.java:779)
at io.quarkus.test.junit.QuarkusTestExtension.initTestState(QuarkusTestExtension.java:767)
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at io.quarkus.runner.bootstrap.RunningQuarkusApplicationImpl.instance(RunningQuarkusApplicationImpl.java:88)
... 6 more
Caused by: java.lang.IllegalAccessError: class org.acme.DerivedBean_Bean tried to access field org.acme.BaseBean.refBean (org.acme.DerivedBean_Bean is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @3874b815; org.acme.BaseBean is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @57ea113a)
at org.acme.DerivedBean_Bean.doCreate(Unknown Source)
at org.acme.DerivedBean_Bean.create(Unknown Source)
at org.acme.DerivedBean_Bean.get(Unknown Source)
at org.acme.DerivedBean_Bean.get(Unknown Source)
at org.acme.BeanTest_Bean.doCreate(Unknown Source)
at org.acme.BeanTest_Bean.create(Unknown Source)
at org.acme.BeanTest_Bean.get(Unknown Source)
at org.acme.BeanTest_Bean.get(Unknown Source)
at io.quarkus.arc.impl.InstanceImpl.getBeanInstance(InstanceImpl.java:325)
at io.quarkus.arc.impl.InstanceImpl.getInternal(InstanceImpl.java:309)
at io.quarkus.arc.impl.InstanceImpl.get(InstanceImpl.java:190)
... 8 more
Expected behavior
Test is green even with a renamed archive base name.
Actual behavior
Exception (see description).
How to Reproduce?
Execute the test mentioned in the description.
Output of uname -a
or ver
No response
Output of java -version
No response
Quarkus version or git rev
No response
Build tool (ie. output of mvnw --version
or gradlew --version
)
No response