Skip to content

Commit 9d0ee66

Browse files
8255758: JEP 380 spec clarifications
Reviewed-by: dfuchs, alanb
1 parent 3dcde55 commit 9d0ee66

File tree

3 files changed

+70
-6
lines changed

3 files changed

+70
-6
lines changed

src/java.base/share/classes/java/net/doc-files/net-properties.html

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@
3030
</HEAD>
3131
<BODY LANG="en-US" DIR="LTR">
3232
<H1 style="text-align:center">Networking Properties</H1>
33-
<P>There are a few standard system properties used to
33+
<p>
34+
There are a few standard system properties used to
3435
alter the mechanisms and behavior of the various classes of the
3536
java.net package. Some are checked only once at startup of the VM,
3637
and therefore are best set using the -D option of the java command,
3738
while others have a more dynamic nature and can also be changed using
3839
the <a href="../../lang/System.html#setProperty(java.lang.String,java.lang.String)">System.setProperty()</a> API.
3940
The purpose of this document is to list
4041
and detail all of these properties.</P>
41-
<P>If there is no special note, a property value is checked every time it is used.</P>
42+
<p>
43+
If there is no special note, a property value is checked every time it is used.</P>
4244
<a id="Ipv4IPv6"></a>
4345
<H2>IPv4 / IPv6</H2>
4446
<UL>
@@ -240,5 +242,57 @@ <H2>Address Cache</H2>
240242
<P>Since these 2 properties are part of the security policy, they are
241243
not set by either the -D option or the {@code System.setProperty()} API,
242244
instead they are set as security properties.</P>
245+
<a id="Unixdomain"></a>
246+
<H2>Unix domain sockets</H2>
247+
<p>
248+
Calling {@link java.nio.channels.ServerSocketChannel#bind(SocketAddress,int) ServerSocketChannel.bind}
249+
with a {@code null} address parameter will bind to an <i>automatically assigned</i> socket address.
250+
For Unix domain sockets, this means a unique path in some predefined system temporary directory.
251+
There are a number of system (and networking) properties that affect this behavior.
252+
<p>
253+
Unix domain socket addresses are limited in length to approximately 100
254+
bytes (depending on the platform), it is important to ensure that the temporary directory's name
255+
together with the filename used for the socket (currently a name similar to
256+
{@code socket_1679697142}) does not exceed this limit. The following properties
257+
can be used to control the selection of this directory:
258+
<p>
259+
<ul>
260+
<li><p><b>{@systemProperty jdk.net.unixdomain.tmpdir}</b> This can be set as
261+
a networking property in {@code conf/net.properties} If set, this specifies the
262+
directory to use for automatically bound server socket addresses. On some platforms,
263+
(eg some Unix systems) this will have a predefined default value. On others,
264+
(eg Windows) there is no default value. Either way, it is always possible
265+
to override the networking property with a system property of the same name
266+
set on the command line. If neither of the networking nor system property
267+
are set, then some systems (eg Windows) may check a commonly used environment
268+
variable as temporary directory.
269+
<li><p><b>{@systemProperty java.io.tmpdir}</b> If the previous step fails to locate
270+
a directory to use, then the directory identified by the system property
271+
{@code java.io.tmpdir} is used.
272+
</ul>
273+
More information about the platform specific behavior can be seen in the
274+
{@code conf/net.properties} configuration file.
275+
<p>
276+
<i>Implicit</i> binding of a {@link java.nio.channels.SocketChannel SocketChannel}
277+
<p>
278+
If a client socket is connected to a remote destination without calling {@code bind} first,
279+
then the socket is <i>implicitly</i> bound. In this case, <i>Unix domain</i> sockets
280+
are <i>unnamed</i> (ie. their path is empty). This behavior is not affected by any
281+
system or networking properties.
282+
<p>
283+
<a id="EnhancedExceptions"></a>
284+
<H2>Enhanced exception messages</H2>
285+
By default, for security reasons, exception messages do not include potentially sensitive
286+
security information such as hostnames or Unix domain socket address paths.
287+
The following property can be used to relax this restriction, for debugging and other
288+
purposes.
289+
<ul>
290+
<li><p><b>{@systemProperty jdk.includeInExceptions}</b> This is typically set to
291+
a comma separated list of keywords that refer to exception types whose messages
292+
may be enhanced with more detailed information. If the value includes the string
293+
{@code hostInfo} then socket addresses will be included in exception message
294+
texts (eg hostnames, Unix domain socket address paths).
295+
</ul>
296+
243297
</BODY>
244298
</HTML>

src/java.base/share/classes/java/nio/channels/ServerSocketChannel.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ public final ServerSocketChannel bind(SocketAddress local)
252252
* Each platform enforces an implementation specific, maximum length for the
253253
* name of a <i>Unix Domain</i> socket. This limitation is enforced when a
254254
* channel is bound. The maximum length is typically close to and generally
255-
* not less than 100 bytes.
255+
* not less than 100 bytes. This limitation also applies to <i>automatically</i>
256+
* bound server socket channels. See the <i>Unix domain</i>
257+
* <a href="../../net/doc-files/net-properties.html#Unixdomain">networking
258+
* properties</a> that can be used to select the temporary directory where
259+
* these sockets are created.
256260
*
257261
* @param local
258262
* The address to bind the socket, or {@code null} to bind to
@@ -348,9 +352,12 @@ public abstract <T> ServerSocketChannel setOption(SocketOption<T> name, T value)
348352
* If this channel's socket has not yet been bound
349353
*
350354
* @throws SecurityException
351-
* If a security manager has been installed
352-
* and it does not permit access to the remote endpoint
353-
* of the new connection
355+
* If a security manager has been installed and this
356+
* channel is bound to an {@link InetSocketAddress}
357+
* and the security manager denies access to the remote endpoint
358+
* of the new connection, or if this channel is bound to a
359+
* {@link UnixDomainSocketAddress} and the security manager
360+
* denies {@link NetPermission}{@code ("accessUnixDomainSocket")}
354361
*
355362
* @throws IOException
356363
* If some other I/O error occurs

test/jdk/java/nio/channels/unixdomain/Security.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ public static void testPolicy2() throws Exception {
151151
call(() -> {
152152
client.connect(saddr);
153153
}, null);
154+
try (final SocketChannel peer = server.accept()) {
155+
// Should succeed
156+
}
154157
}
155158
} finally {
156159
Files.deleteIfExists(servername);

0 commit comments

Comments
 (0)