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

org.mozilla.javascript.MemberBox accesses internal sun class which fails on higher java versions #6254

Open
odoodo opened this issue Jul 11, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@odoodo
Copy link

odoodo commented Jul 11, 2024

Describe the bug
The rhino-layer accesses an underlying Java Class that is private in Java 9+.

To Reproduce
create and execute the following code in any javascript scope:

var url = new java.net.URL('www.google.com');
var connection = url.openConnection();

Expected behavior
org.mozilla.javascript.MemberBox should reference java.net.HttpURLConnection instead of sun.net.www.protocol.http.HttpURLConnection as that is the official API and accessible under all Java versions.

Actual behavior
It throws the following error under Java versions 9+:

java.lang.IllegalAccessException: class org.mozilla.javascript.MemberBox cannot access class sun.net.www.protocol.http.HttpURLConnection (in module java.base) because module java.base does not export sun.net.www.protocol.http to unnamed module @1d3021e4

Environment (please complete the following information):

  • Mirth version 4.5.0
  • Java 21
  • Microsoft Windows Server 2022 Standard

Workarounds

  1. Do not use the java implementation for java versions > 8 (but apache or others)
  2. Add a VM flag: --add-exports java.base/sun.net.www.protocol.http=ALL-UNNAMED (this, however, causes other risks as no offical API)
  3. Make required classes visible via reflections
@odoodo odoodo added the bug Something isn't working label Jul 11, 2024
@tonygermano
Copy link
Collaborator

I had to add a protocol to the url and actually call a method on the connection to get it to error.

var url = new java.net.URL('http://www.google.com');
var connection = url.openConnection();
var inputStream = connection.getInputStream(); // this is what threw the exception

This issue has already been resolved in the upstream Rhino project. I ran this code with the latest snapshot release of Rhino with java 17, and it produced the expected output.

var url = new java.net.URL('http://www.google.com');
var connection = url.openConnection();
var inputStream = connection.getInputStream();
var outputStream = new java.io.ByteArrayOutputStream();
inputStream.transferTo(outputStream);
var content = outputStream.toString('UTF-8');

@Coooz
Copy link

Coooz commented Oct 10, 2024

Hi @tonygermano,

I recently ran into this bug (again) with a customer of ours. When I tried to reproduce the bug on my own machine (Mirth Connect 4.4.2, OpenJDK 11.0.2) with your above code, everything seemed to work fine. So apparently my machine already had the latest snapshot release of Rhino, and the customer did not have that.

Can you explain to me:

  • how I can see that I'm working with the right version of Rhino?
  • how to obtain and install the right version in case I don't have it?

Many thanks in advance!

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

No branches or pull requests

3 participants