eclipse-ee4j / eclipse-ee4j/yasson

Java module system: "access to public member failed" when using 'opens' x to 'y'

Open
#545 4 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Java
Stars
218
Forks
109
Avg merge
1d 5h
Merged PRs (30d)
9

Description

**Describe the bug**
Allowing runtime-only access to a package by org.eclipse.yasson is not working.
I have a module-info file containing the following statement:

`opens nl.scuro.media.model to org.eclipse.yasson;`

This should allow Yasson to be able to read this package when (de)serializing. Unfortunately, I get an error:

```
Caused by: java.lang.IllegalAccessException: access to public member failed: nl.scuro.media.model.MediaRefClientWrapper.getMediaRef[Ljava.lang.Object;@6af6a361/invokeVirtual, from public Lookup
at java.base/java.lang.invoke.MemberName.makeAccessException(MemberName.java:955)
```

I can work around this by exporting my package:
`exports nl.scuro.media.model;`

But I there are scenarios where one doesn't want to export globally.

**To Reproduce**
Create a simple project with a module-info file and package containing a POJO.
Add Yasson as a dependency and _open_ this package _to_ org.eclipse.yasson.

**Expected behavior**
I would expect Yasson to be able to access all classes in the _opened_ package.

**System information:**
- OS: Linux
- Java Version: 17
- Yasson Version: 2.0.4

**Additional context**
While I'm not very experienced with the module system yet, this seems to be incorrect behavior.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.