Skip to content

Commit b6b6321

Browse files
authored
Add missing @Nullable annotation in Socket, and annotate related classes. (typetools#71)
1 parent 52688e1 commit b6b6321

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

src/java.base/share/classes/java/net/DatagramSocket.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package java.net;
2727

2828
import org.checkerframework.checker.interning.qual.UsesObjectEquals;
29+
import org.checkerframework.checker.nullness.qual.Nullable;
2930
import org.checkerframework.framework.qual.AnnotatedFor;
3031

3132
import java.io.IOException;
@@ -248,7 +249,7 @@
248249
* @see java.nio.channels.DatagramChannel
249250
* @since 1.0
250251
*/
251-
@AnnotatedFor({"interning"})
252+
@AnnotatedFor({"interning", "nullness"})
252253
public @UsesObjectEquals class DatagramSocket implements java.io.Closeable {
253254

254255
// An instance of DatagramSocketAdaptor, NetMulticastSocket, or null
@@ -330,7 +331,7 @@ protected DatagramSocket(DatagramSocketImpl impl) {
330331
* @see SecurityManager#checkListen
331332
* @since 1.4
332333
*/
333-
public DatagramSocket(SocketAddress bindaddr) throws SocketException {
334+
public DatagramSocket(@Nullable SocketAddress bindaddr) throws SocketException {
334335
this(createDelegate(bindaddr, DatagramSocket.class));
335336
}
336337

@@ -389,7 +390,7 @@ public DatagramSocket(int port) throws SocketException {
389390
* @see SecurityManager#checkListen
390391
* @since 1.1
391392
*/
392-
public DatagramSocket(int port, InetAddress laddr) throws SocketException {
393+
public DatagramSocket(int port, @Nullable InetAddress laddr) throws SocketException {
393394
this(new InetSocketAddress(laddr, port));
394395
}
395396

@@ -408,7 +409,7 @@ public DatagramSocket(int port, InetAddress laddr) throws SocketException {
408409
* not supported by this socket.
409410
* @since 1.4
410411
*/
411-
public void bind(SocketAddress addr) throws SocketException {
412+
public void bind(@Nullable SocketAddress addr) throws SocketException {
412413
delegate().bind(addr);
413414
}
414415

@@ -569,7 +570,7 @@ public boolean isConnected() {
569570
* @return the address to which this socket is connected.
570571
* @since 1.2
571572
*/
572-
public InetAddress getInetAddress() {
573+
public @Nullable InetAddress getInetAddress() {
573574
return delegate().getInetAddress();
574575
}
575576

@@ -604,7 +605,7 @@ public int getPort() {
604605
* @see #connect(SocketAddress)
605606
* @since 1.4
606607
*/
607-
public SocketAddress getRemoteSocketAddress() {
608+
public @Nullable SocketAddress getRemoteSocketAddress() {
608609
return delegate().getRemoteSocketAddress();
609610
}
610611

@@ -618,7 +619,7 @@ public SocketAddress getRemoteSocketAddress() {
618619
* @see #bind(SocketAddress)
619620
* @since 1.4
620621
*/
621-
public SocketAddress getLocalSocketAddress() {
622+
public @Nullable SocketAddress getLocalSocketAddress() {
622623
return delegate().getLocalSocketAddress();
623624
}
624625

@@ -722,7 +723,7 @@ public void receive(DatagramPacket p) throws IOException {
722723
* method does not allow the operation
723724
* @since 1.1
724725
*/
725-
public InetAddress getLocalAddress() {
726+
public @Nullable InetAddress getLocalAddress() {
726727
return delegate().getLocalAddress();
727728
}
728729

@@ -1102,7 +1103,7 @@ public boolean isClosed() {
11021103
*
11031104
* @since 1.4
11041105
*/
1105-
public DatagramChannel getChannel() {
1106+
public @Nullable DatagramChannel getChannel() {
11061107
return null;
11071108
}
11081109

src/java.base/share/classes/java/net/MulticastSocket.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
package java.net;
2727

28+
import org.checkerframework.checker.nullness.qual.Nullable;
29+
import org.checkerframework.framework.qual.AnnotatedFor;
30+
import org.checkerframework.framework.qual.CFComment;
31+
2832
import java.io.IOException;
2933
import java.nio.channels.DatagramChannel;
3034
import java.nio.channels.MulticastChannel;
@@ -110,6 +114,7 @@
110114
* @author Pavani Diwanji
111115
* @since 1.1
112116
*/
117+
@AnnotatedFor({"nullness"})
113118
public class MulticastSocket extends DatagramSocket {
114119

115120
@Override
@@ -208,7 +213,7 @@ public MulticastSocket(int port) throws IOException {
208213
*
209214
* @since 1.4
210215
*/
211-
public MulticastSocket(SocketAddress bindaddr) throws IOException {
216+
public MulticastSocket(@Nullable SocketAddress bindaddr) throws IOException {
212217
this(createDelegate(bindaddr, MulticastSocket.class));
213218
}
214219

@@ -366,7 +371,7 @@ public void leaveGroup(InetAddress mcastaddr) throws IOException {
366371
* @since 1.4
367372
*/
368373
@Override
369-
public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
374+
public void joinGroup(SocketAddress mcastaddr, @Nullable NetworkInterface netIf)
370375
throws IOException {
371376
super.joinGroup(mcastaddr, netIf);
372377
}
@@ -382,7 +387,7 @@ public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
382387
* @since 1.4
383388
*/
384389
@Override
385-
public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
390+
public void leaveGroup(SocketAddress mcastaddr, @Nullable NetworkInterface netIf)
386391
throws IOException {
387392
super.leaveGroup(mcastaddr, netIf);
388393
}
@@ -401,6 +406,7 @@ public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
401406
* @see #getInterface()
402407
*/
403408
@Deprecated(since="14")
409+
@CFComment("nullness: TODO: @Nullable parameter or not?")
404410
public void setInterface(InetAddress inf) throws SocketException {
405411
delegate().setInterface(inf);
406412
}
@@ -440,6 +446,7 @@ public InetAddress getInterface() throws SocketException {
440446
* @see StandardSocketOptions#IP_MULTICAST_IF
441447
* @since 1.4
442448
*/
449+
@CFComment("nullness: TODO: @Nullable parameter or not?")
443450
public void setNetworkInterface(NetworkInterface netIf)
444451
throws SocketException {
445452
delegate().setNetworkInterface(netIf);

src/java.base/share/classes/java/net/ServerSocket.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.checkerframework.checker.interning.qual.UsesObjectEquals;
3030
import org.checkerframework.checker.mustcall.qual.CreatesMustCallFor;
3131
import org.checkerframework.checker.mustcall.qual.MustCallAlias;
32+
import org.checkerframework.checker.nullness.qual.Nullable;
3233
import org.checkerframework.framework.qual.AnnotatedFor;
3334

3435
import java.io.FileDescriptor;
@@ -82,7 +83,7 @@
8283
* @see java.nio.channels.ServerSocketChannel
8384
* @since 1.0
8485
*/
85-
@AnnotatedFor({"calledmethods", "interning", "mustcall"})
86+
@AnnotatedFor({"calledmethods", "interning", "mustcall", "nullness"})
8687
public @UsesObjectEquals class ServerSocket implements java.io.Closeable {
8788
/**
8889
* Various states of this socket.
@@ -270,7 +271,7 @@ public ServerSocket(int port, int backlog) throws IOException {
270271
* @see SecurityManager#checkListen
271272
* @since 1.1
272273
*/
273-
public ServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException {
274+
public ServerSocket(int port, int backlog, @Nullable InetAddress bindAddr) throws IOException {
274275
setImpl();
275276
if (port < 0 || port > 0xFFFF)
276277
throw new IllegalArgumentException(
@@ -346,7 +347,7 @@ void createImpl() throws SocketException {
346347
* @since 1.4
347348
*/
348349
@CreatesMustCallFor
349-
public void bind(SocketAddress endpoint) throws IOException {
350+
public void bind(@Nullable SocketAddress endpoint) throws IOException {
350351
bind(endpoint, 50);
351352
}
352353

@@ -376,7 +377,7 @@ public void bind(SocketAddress endpoint) throws IOException {
376377
* @since 1.4
377378
*/
378379
@CreatesMustCallFor
379-
public void bind(SocketAddress endpoint, int backlog) throws IOException {
380+
public void bind(@Nullable SocketAddress endpoint, int backlog) throws IOException {
380381
if (isClosed())
381382
throw new SocketException("Socket is closed");
382383
if (isBound())
@@ -424,7 +425,7 @@ public void bind(SocketAddress endpoint, int backlog) throws IOException {
424425
*
425426
* @see SecurityManager#checkConnect
426427
*/
427-
public InetAddress getInetAddress() {
428+
public @Nullable InetAddress getInetAddress() {
428429
if (!isBound())
429430
return null;
430431
try {
@@ -493,7 +494,7 @@ public int getLocalPort() {
493494
* @since 1.4
494495
*/
495496

496-
public SocketAddress getLocalSocketAddress() {
497+
public @Nullable SocketAddress getLocalSocketAddress() {
497498
if (!isBound())
498499
return null;
499500
return new InetSocketAddress(getInetAddress(), getLocalPort());
@@ -744,7 +745,7 @@ public void close() throws IOException {
744745
*
745746
* @since 1.4
746747
*/
747-
public @MustCallAlias ServerSocketChannel getChannel(@MustCallAlias ServerSocket this) {
748+
public @MustCallAlias @Nullable ServerSocketChannel getChannel(@MustCallAlias ServerSocket this) {
748749
return null;
749750
}
750751

src/java.base/share/classes/java/net/Socket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public Socket(Proxy proxy) {
237237
*
238238
* @since 1.1
239239
*/
240-
protected Socket(SocketImpl impl) throws SocketException {
240+
protected Socket(@Nullable SocketImpl impl) throws SocketException {
241241
checkPermission(impl);
242242
this.impl = impl;
243243
}

src/java.base/share/classes/java/net/SocketOption.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
package java.net;
2727

28+
import org.checkerframework.framework.qual.AnnotatedFor;
29+
2830
/**
2931
* A socket option associated with a socket.
3032
*
@@ -40,7 +42,7 @@
4042
*
4143
* @see StandardSocketOptions
4244
*/
43-
45+
@AnnotatedFor({"nullness"})
4446
public interface SocketOption<T> {
4547

4648
/**

0 commit comments

Comments
 (0)