All Products
Search
Document Center

Mobile Testing - Deprecated:java_lang_SecurityException

Last Updated:Feb 28, 2022

Problem description

This exception occurs when security errors are detected in violation of security rules.

Solution

This exception occurs when security errors are detected in violation of security rules. Check other information and grant proper permissions to determine the cause.

Examples

  Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
        at java.net.InetAddress.lookupHostByName(InetAddress.java:430)
        at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
        at java.net.InetAddress.getAllByName(InetAddress.java:214)
        at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
        at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
        at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
        at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
        at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
        at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)

Problem description:

This exception occurs because Internet access permissions are not granted.

Solution:

This exception occurs because Internet access permissions are not granted. Check whether Internet access permissions are granted to the AndroidManifest.xml file or whether software programs that block the permissions are enabled on the mobile phone. Grant the required permissions.

Sample code

Grant the Internet access permissions to the AndroidManifest.xml file.

<uses-permissionandroid:name="android.permission.INTERNET"/>

HTTPUrlConnection classes are used in this example. You must apply for permission to detect network status as specified in official documentation.

<uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE"/>

If the exception persists, check whether software programs that block the Internet access permissions are enabled on the mobile phone.

References