On linux, for security reasons the IP ports 1...1024 are so-called "privileged" ports which only root may listen to. The operating system actively prevents other accounts form listening to such ports, unless explicitly configured otherwise. On Java, when trying to listen to a privileged port, IOEXception is thrown.
ServerSocket(0) will pick a free port. Strange but true, when running on linux as non-root on, it still returns free ports from the range of 1...1024. In the end, an application will fail unless it explicitly checks the returned IP port number. The latter makes the Java application code platform-dependent, as on other OS, like Windows, everybody (even non-Administrators), may use that port range (Windows does not know the idea of "privileged" ports).
To free application vendors form the burden of checking the returned IP port, and to make the application code platform-agnostic, the implementation of ServerSocket(0) should be changed in a platform-dependent way:
* On linux, the JRE should check if there is a privileged range configured, and if so, it should return only ports from an unprivileged range.
ServerSocket(0) will pick a free port. Strange but true, when running on linux as non-root on, it still returns free ports from the range of 1...1024. In the end, an application will fail unless it explicitly checks the returned IP port number. The latter makes the Java application code platform-dependent, as on other OS, like Windows, everybody (even non-Administrators), may use that port range (Windows does not know the idea of "privileged" ports).
To free application vendors form the burden of checking the returned IP port, and to make the application code platform-agnostic, the implementation of ServerSocket(0) should be changed in a platform-dependent way:
* On linux, the JRE should check if there is a privileged range configured, and if so, it should return only ports from an unprivileged range.