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

* fixed: #641 java.lang.IllegalAccessError: Attempt to access protected method from Lambda #646

Merged

Conversation

dkimitsa
Copy link
Contributor

Code to reproduce:

package a;
public class A {
    protected foo(){};
}

package b;
import a.A;
public class B extends A{
    public void test() {
        Runnable r = ::foo;
        r.run();
    }
}

Root case: labda for B class is located in package b and can access protected members of A class from there.

Fix: for such kind of lambda a trampoline method is generated in calling class (which has all access to destination member) and instead of directly invoking method target -- this trampoline is invoked:

public class B extends A{
    public void test() {
        Runnable r = lambda(this);
        r.run();
    }

    static private lambda$1$run(B thiz) {
       thiz.foo();
    }
}
public class lambda implements Runnable {
    private final B thiz;
    lambda(B thiz) { this.thiz = thiz; }
    public void run() {
        B.lambda$1$run(thiz);
    }
}

…rotected method from Lambda

Code to reproduce:
```
package a;
public class A {
    protected foo(){};
}

package b;
import a.A;
public class B extends A{
    public void test() {
        Runnable r = ::foo;
        r.run();
    }
}
```

Root case: labda for B class is located in `package b` and can access protected members of A class from there.

Fix: for such kind of lambda a trampoline method is generated in calling class (which has all access to destination member) and instead of directly invoking method target -- this trampoline is invoked:

```
public class B extends A{
    public void test() {
        Runnable r = lambda(this);
        r.run();
    }

    static private lambda$1$run(B thiz) {
       thiz.foo();
    }
}
public class lambda implements Runnable {
    private final B thiz;
    lambda(B thiz) { this.thiz = thiz; }
    public void run() {
        B.lambda$1$run(thiz);
    }
}
```
@Tom-Ski Tom-Ski merged commit 97fc76a into MobiVM:master Apr 19, 2022
@dkimitsa dkimitsa deleted the fix/#641-illegal-access-error-to-protected branch April 23, 2022 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants