Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Thread checkAccess

Tags:

java

android

I was pondering, playing around with some code. I came across the following method in the Thread class: checkAccess().

The documentation (literally) says "Does nothing." Why would this possibly be in the Thread class if it does nothing? - Are we possibly dealing with developer trolls?

Screenshot:

enter image description here

like image 482
Luke Taylor Avatar asked Nov 03 '22 14:11

Luke Taylor


1 Answers

Thread.checkAccess() is from core Java APIs so that's why it exists in Android as well, however it is not implemented.

Android's java.lang.Thread.checkAccess() doesn't provide this implementation because it is not trusting SecurityManagers.

Security managers do not provide a secure environment for executing untrusted code. Untrusted code cannot be safely isolated within the Dalvik VM.

And this is how Thread.checkAccess is implemented inside OpenJDK.

public final void checkAccess() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkAccess(this);
    }
}
like image 94
auselen Avatar answered Nov 15 '22 00:11

auselen