Skip to content

Allow J() convenience on Java 17+ #345

Description

@vpinna80

With current implementation, some legitimate Java calls fail because of access to private methods in Java 17+, where setAccessible doesn't work anymore.

For example, the following fails though the Map class and all the methods are public:

java_iter <- J("java.util.Map")$of("A", "B")$entrySet()$iterator()

In this case, and in similar cases, you have to resort to .jcall which is cumbersome because you have to remember the actual parameter classes, and the return type.

Expected behavior:

> str(J("java.util.Map")$of("A", "B")$entrySet()$iterator())
Formal class 'jobjRef' [package "rJava"] with 2 slots
  ..@ jobj  :<externalptr> 
  ..@ jclass: chr "java/util/ImmutableCollections$Set12$1"

Activity

  1. added a commit that references this issue on Nov 12, 2025
    a20bbcd
  2. s-u commented on Jan 19, 2026

    @s-u
    Owner

    Many thanks!

  3. s-u commented on Mar 11, 2026

    @s-u
    Owner

    Sorry, this had to be reverted, because it causes failure in reverse-dependencies, so will require more investigation.

  4. reopened this on Mar 11, 2026
  5. s-u commented on Mar 11, 2026

    @s-u
    Owner

    The failure report (from R CMD check):

    streamMOA:

    Error in .jcheck(silent = FALSE) :
     java.lang.IllegalAccessException: class RJavaTools cannot access a member of class StreamMOA with modifiers "public static"
    Calls: update ... update.DSC_MOA -> J -> .jrcall -> .jcall -> .jcheck
    

    @vpinna80 any hope you have a minute to check? I'm currently swamped so can't really have a look right now :(

  6. added 2 commits that reference this issue on Mar 11, 2026
  7. vpinna80 commented on Mar 11, 2026

    @vpinna80
    ContributorAuthor

    Hi @s-u , I could look at it but I need some more info.
    Which Java version was used in the test?
    Is this bug resulting from a test that's part of the streamMOA unit tests, or was it just a bug discovered by usage?

  8. s-u commented on Mar 11, 2026

    @s-u
    Owner

    @vpinna80 Thanks! It is a report from R CMD check streamMOA (that's how CRAN does rev.dep. checks). I think Kurt uses latest Debian Java so probably 21.

  9. added a commit that references this issue on Mar 12, 2026
    d03e1ca
  10. vpinna80 commented on Mar 24, 2026

    @vpinna80
    ContributorAuthor

    Hi @s-u , sorry to come back to you this late.

    Can you confirm that streamMOA isn't working with java 8? I looked at the code and it seems to me that the package isn't compatible with any java > 8. In particular, the Java classes in the package are not public, so their fields aren't accessible; no patch can allow for this accesses on any java > 8.

    You said that the reverse dependencies tests were run with java 21. What version did you use before this patch? Go back to it and use this rJava with the same Java version you were using before.

    Note that this patch doesn't automatically make all existing packages compatible with java > 8. The purpose of this patch is to allow packages that both require and are already compatible with Java 17 to run without errors.

  11. added a commit that references this issue on Mar 24, 2026
  12. added a commit that references this issue on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions