Open Juuxel opened 2 years ago
This is a major pain to handle because it breaks in the verifier, not in the fundamental access rules.
JVMS 4.10.1.8 demands " Otherwise, use of a member of an object of type Target requires that Target be assignable to the type of the current class." to access protected (non-static) members. Without that it is as if the member was package private.
If I read it correctly the type Target
is the type in the stack frame at the instruction location, which isn't known without code analysis. It is not necessarily the same as T
, C
or D
in 5.4.4.
A conservative estimation mode that treats Target = T could work in practice, but isn't ideal.
Yep, 5.4.4 also notes:
During verification of D, it was required that, even if T is a superclass of D, the target reference of a protected field access or method invocation must be an instance of D or a subclass of D (§4.10.1.8).
which seems to imply that Target and T are separate. I took a look at this issue when I originally reported it and it looks like it's not easy to solve with TR's current design since it needs to analyse the stack. See also JLS 6.6.2.1 which is the same rule in source code terms.
See this reproduction repo: https://github.com/Juuxel/tr-package-access-reproduction
example-code/src/main/java
) contains two classes,example.Parent
andexample.Child
example.Parent
has a protected field that is accessed inexample.Child
's constructorgradlew testWithoutRemapping
to see "hello" when the jar is not remappergradlew testWithRemapping
to see a JVM crashexample.Child
is remapped toexample.child.Child
andexample.Parent
stays intact, the protected access now becomes an error. (Accessing protected fields of another instance from a class not in the same package)protected
modifier from the field and make it package-private. TR fixes that to be public.remapper/src/main/java/remapper/Main.java
This issue also has practical effects when remapping Minecraft to Yarn in environments where all protected accesses are not transformed to be public (FML on Yarn).