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

[Java] java.lang.reflect.InaccessibleObjectException on Java 18 #340

Closed
asfimport opened this issue May 3, 2022 · 12 comments
Closed

[Java] java.lang.reflect.InaccessibleObjectException on Java 18 #340

asfimport opened this issue May 3, 2022 · 12 comments
Labels
Type: bug Something isn't working

Comments

@asfimport
Copy link

asfimport commented May 3, 2022

Getting the following stack trace when running on Java 18.

BaseAllocator throws this when it calls the DefaultAllocationManagerFactory.

    private ArrowBuf createEmpty() {
        return this.allocationManagerFactory.empty();
    }
Caused by: java.lang.RuntimeException: Failed to initialize MemoryUtil.
	at org.apache.arrow.memory.util.MemoryUtil.<clinit>(MemoryUtil.java:136)
	... 20 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field long java.nio.Buffer.address accessible: module java.base does not \"opens java.nio\" to unnamed module @3453e479
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
	at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
	at org.apache.arrow.memory.util.MemoryUtil.<clinit>(MemoryUtil.java:84)
	... 20 more
 

Reporter: Daniel Glöckner

Related issues:

Note: This issue was originally created as ARROW-16449. Please see the migration documentation for further details.

@asfimport
Copy link
Author

David Li / @lidavidm:
Can you test with Arrow 8.0.0 once it releases (in the next few weeks)? Until ARROW-15755 was implemented there was no support for Java > 11

@asfimport
Copy link
Author

David Li / @lidavidm:
CC @davisusanibar

@asfimport
Copy link
Author

Raúl Cumplido / @raulcd:
Hi Daniel,

Thanks for your report. We are working towards supporting newer JDK versions.

Support for JDK 17 will be added to the next 8.0.0 release as you can see from this ticket https://issues.apache.org/jira/browse/ARROW-15755 .

Support for JDK 18 is expected to be added to a following release. You can follow how support for JDK 18 progresses on this ticket: https://issues.apache.org/jira/browse/ARROW-16267

@asfimport
Copy link
Author

Daniel Glöckner:
Thanks @lidavidm and @raulcd. I will trace the Arrow release and re-test.

@asfimport
Copy link
Author

Daniel Glöckner:
@lidavidm I re-tested with the Arrow 8.0 release and java 17.0.2.

The minimal code below only works if I add --add-opens java.base/java.nio=ALL-UNNAMED VM option. Is this expected?

import org.apache.arrow.memory.RootAllocator;

public class Arrow {

  public static void main(String[] args) {
    RootAllocator rootAllocator = new RootAllocator();
    var buf = rootAllocator.buffer(1024);
    System.out.println(buf);
  }
}

@asfimport
Copy link
Author

David Li / @lidavidm:
[~[email protected]] I believe this is currently unavoidable because of Arrow/Netty's use of direct memory, cc @davisusanibar for comments. (JEP419 may help but we are a very long way off from being able to rely on that.)

@asfimport
Copy link
Author

David Dali Susanibar Arce / @davisusanibar:
Hi [~[email protected]]  as per the jar artifacts are exposed as a legacy mode (it means any jar are running in the classpath is consider as a unnamed module) and base on JEP 200 The Modular JDK: yes, this is needed:

--add-opens ${module}/${package}=${target_modules}
Let the ${target_modules} access all types and members, regardless of visibility, from ${module}'s ${package}

Also this is added to the Arrow Java documentation 8.0.0 at https://arrow.apache.org/docs/java/install.html

 

 

This is a draft for implement JEP 200 The Modular JDK and be more restrict about to not give ALL-UNNAMED access but there is a lot of discussion we need to close before to convert this draft into PR: apache/arrow#13072

 

@asfimport
Copy link
Author

David Dali Susanibar Arce / @davisusanibar:
Hi [~[email protected]] please could you help us if we could close this issue as resolved ?, thank you in advance.

@asfimport
Copy link
Author

Fabian Mastenbroek:
Hi,

I stumbled upon this issue today and ideally I would like to avoid having to open java.base to unnamed modules. I took a look at the source code of MemoryUtil today and it seems there might be workaround for this issue.

The reflective call that is currently causing the failure is not necessary. Applying this patch to the Arrow tree seems to resolve this issue for me. However, without the suggested add-opens parameter, any call to MemoryUtil.directBuffer will now fail during runtime.

This patch resolves that issue for me. However, this is a rather hairy solution, since it overwrites fields of DirectByteBuffer using Unsafe to construct a buffer for an arbitrary memory address.

@asfimport
Copy link
Author

David Li / @lidavidm:
Thanks [~fabianishere]!

The first patch seems reasonable. But the second patch seems rather risky, and from a quick look, without directBuffer, much of the Arrow library will still fail at runtime.

@asfimport
Copy link
Author

David Li / @lidavidm:
CC @davisusanibar @lwhite1 for opinions

@lidavidm
Copy link
Member

We can't solve this without rewriting the memory subsystem (unfortunately). FFM is a better potential solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants