Skip to content
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

Inaccessible Object Exception in Unit Test #837

Closed
satya-devloper opened this issue Aug 9, 2023 · 5 comments
Closed

Inaccessible Object Exception in Unit Test #837

satya-devloper opened this issue Aug 9, 2023 · 5 comments
Labels
closed: notabug The issue is not a bug

Comments

@satya-devloper
Copy link

Expected Behavior

Unit test should not be affected after change from Micronaut 3 to micronaut 4

Actual Behaviour

I have switched from micraonut 3 to Micronaut 4, so I have to use java. 17 now as per documentation and earlier I was using java 14.
So Ideally all the test should pass, but what I can see that wherever I m using withEnvVariable function in unit test, it is failing with execution Inaccessible Object Exception

Steps To Reproduce

public void EnvironmentVariablesTest {
@test
public void setEnvironmentVariable() {
String value = withEnvironmentVariable("name", "value")
.execute(() -> System.getenv("name"));
assertEquals("value", value);
}
}

when I tried to run this sample unit test only getting issue "Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible: module java.base does not "opens java.util" to unnamed module @7549926"

After going through google search I found that this issue is of java17 which microanut 4 is also using
I tries adding this in build.gradle
test {
jvmArgs ["–add-opens java.base/java.lang=ALL-UNNAMED"]
systemProperty 'add-opens', 'java.base/java.lang=ALL-UNNAMED'
systemProperty 'add-opens', 'java.base/java.util=ALL-UNNAMED'
}

but still same issue

Environment Information

Mac
java 17.0.8

Example Application

No response

Version

4.0.1

@dstepanov
Copy link
Contributor

Please create a sample app with a reproducer.

@satya-devloper
Copy link
Author

micronautguid-sample.zip

@satya-devloper
Copy link
Author

I have made necessary changes for micraonut4 version in build.gradle which I m using in my project
command := ./gradlew build -i

@satya-devloper
Copy link
Author

@dstepanov , Any Update on this issue as our code is breaking after upgrade

@dstepanov
Copy link
Contributor

I'm sorry, this has nothing to do with Micronaut. The problem is with systemlambda which is using reflection to access JDK classes, which is not allowed by default in Java 7.
There is an issue stefanbirkner/system-lambda#23

@dstepanov dstepanov added the closed: notabug The issue is not a bug label Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: notabug The issue is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants