ikvmnet / ikvm

A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Other
1.24k stars 116 forks source link

Package-Private access is not allowed between individual assemblies #491

Open dibble-james opened 7 months ago

dibble-james commented 7 months ago

I briefly mentioned this to @wasabii over here and have created a little repro project: IKVM.FOP.zip

My Java and Maven knowledge is next to 0, but from anecdotal reading, the fop-util jar file here is being recreated by IKVM with a different signature, so when fop-core tries to call out to it, it think it's working with a different assembly and throws this exception:

Unhandled exception. java.lang.IllegalAccessError: Try to access field org.apache.fop.util.text.AdvancedMessageFormat.COMMA_SEPARATOR_REGEX from class org.apache.fop.util.text.IfFieldPart

In the attached repro, I've got it working with a very basic fo file, it can generate a pdf from align.xml, but there's something in basicfonts.xml that sends it down a slightly different path that then causes the error. I haven't quite figured out how to reference the jar files using IKVMReference so I can absolve IKVM here and just put it down to MavenReference.

GeorgeS2019 commented 6 months ago

@dibble-james https://github.com/ikvmnet/ikvm/issues/493

wasabii commented 6 months ago

So I am working on a solution to this. The basic issue is that fop is split into three JARs, which access each other's package-private members. This is fine as long as all three are loaded dynamically. However, in general IKVM use, we treat each individual JAR as a separate assembly. But, package-private members get converted to 'internal'. So, .NET cannot access across them.

The solution I'm working on currently is to use the IgnoresAccessChecksToAttribute to insure each generated assembly has access to the internals of their referenced assemblies. This does skip a .NET verification check. But, it would have no impact on a Java compiler examine the assembly exported to a stub JAR. So, access should be prevented at compile time. It's an interesting solution, and we'll see if it works.

wasabii commented 6 months ago

It also appears that this is a problem with fop itself, as they're engaged in a modernization effort for JPMS (JDK9+).

https://issues.apache.org/jira/browse/FOP-3160

herodrigues commented 3 months ago

Hi, @wasabii

anything we can do to help on this issue?

I'm trying to use the FOP library in my Dotnet project, but I was able to generate PDFs only from simple XSLT/XML files.

wasabii commented 3 months ago

I never came up with a good solution inside IKVM as of yet. It looks like the FOP issue I referenced has since been 'resolved'. Might want to check with that and see if any changes have been made that remove need for IKVM to do anything.