Fix the Java.Net.SocketException: Permission Denied in Java

Sheeraz Gul Jan 30, 2023 Aug 19, 2022
  1. Causes of the Permission denied Error in Java
  2. Fix the Permission denied Error in Java
Fix the Java.Net.SocketException: Permission Denied in Java

This tutorial demonstrates the Permission denied error in Java.

Causes of the Permission denied Error in Java

The SocketException usually occurs when there is a problem with the network connection. It can be Permission denied, Connection reset, or anything else.

The Permission denied error occurs when there is no permission from the network to connect with a certain port. The error can occur while connecting or configuring the network settings on different platforms.

The error Permission denied can occur on any server type like Tomcat or OpenShift.

Here are the main reasons for the error Permission denied:

  1. When the operating system doesn’t allow a particular port number.
  2. The antivirus or firewall stops the connection to a certain network.
  3. Sometimes a problem with the older version of Java.

Fix the Permission denied Error in Java

For example, while configuring the HTTPS certificate for the Tomcat server, the error Permission denied can occur while starting the server:

Caused by: Permission denied
                at Method)
                at org.apache.coyote.AbstractProtocol.init(
                at org.apache.coyote.http11.AbstractHttp11Protocol.init(
                at org.apache.catalina.connector.Connector.initInternal(
                ... 13 more

The reason for this error is that the operating system is stopping the connection. Because the Linux system doesn’t allow non-root users to use the root less than 1024; hence, it becomes a permission problem.

Now, the solutions to this problem can be:

  1. The best solution is to use the root account to start the Tomcat server.
  2. If Linux is not allowing port numbers less than 1024, use a port greater than this number. The port number will be added to the URL request.

Similarly, while using the openshift server, the same error Permission denied can occur. And the reason could be either the firewall or antivirus is stopping it or the Java version you are using is not compatible.

The possible solution for this can be:

  1. Stop the antivirus and firewall. Or check they are not blocking the server.

  2. Use Java 8 or above versions. Or put the following VM arguments in your application to be able to run and connect using Java 7:
  3. Please check the third-party libraries or packages if they have some specific requirements. Some of them will also cause the Permission denied error.

Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook

Related Article - Java Error