Skip to content

Commit e07b421

Browse files
cpovirkwmdietl
andauthored
Annotate some recent io APIs. (#113)
In `Console`, I had annotated the parameter of `readln` previously but missing the return type. Then the JDK added an overload whose return type also needs an annotation. Along the way, I noticed similar methods in the `IO` class, so I annotated it, too. Co-authored-by: Werner Dietl <[email protected]>
1 parent c3f3ab4 commit e07b421

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Diff for: src/java.base/share/classes/java/io/Console.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public Console print(@Nullable Object obj) {
224224
* @since 23
225225
*/
226226
@PreviewFeature(feature = PreviewFeature.Feature.IMPLICIT_CLASSES)
227-
public String readln(@Nullable String prompt) {
227+
public @Nullable String readln(@Nullable String prompt) {
228228
throw newUnsupportedOperationException();
229229
}
230230

@@ -242,7 +242,7 @@ public String readln(@Nullable String prompt) {
242242
* @since 24
243243
*/
244244
@PreviewFeature(feature = PreviewFeature.Feature.IMPLICIT_CLASSES)
245-
public String readln() {
245+
public @Nullable String readln() {
246246
throw newUnsupportedOperationException();
247247
}
248248

Diff for: src/java.base/share/classes/java/io/IO.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
package java.io;
2727

2828
import jdk.internal.javac.PreviewFeature;
29+
import org.jspecify.annotations.NullMarked;
30+
import org.jspecify.annotations.Nullable;
2931

3032
/**
3133
* A collection of static convenience methods that provide access to
@@ -41,6 +43,7 @@
4143
* @since 23
4244
*/
4345
@PreviewFeature(feature = PreviewFeature.Feature.IMPLICIT_CLASSES)
46+
@NullMarked
4447
public final class IO {
4548

4649
private IO() {
@@ -59,7 +62,7 @@ private IO() {
5962
* @throws IOError if {@code System.console()} returns {@code null},
6063
* or if an I/O error occurs
6164
*/
62-
public static void println(Object obj) {
65+
public static void println(@Nullable Object obj) {
6366
con().println(obj);
6467
}
6568

@@ -90,7 +93,7 @@ public static void println() {
9093
* @throws IOError if {@code System.console()} returns {@code null},
9194
* or if an I/O error occurs
9295
*/
93-
public static void print(Object obj) {
96+
public static void print(@Nullable Object obj) {
9497
con().print(obj);
9598
}
9699

@@ -110,7 +113,7 @@ public static void print(Object obj) {
110113
* @throws IOError if {@code System.console()} returns {@code null},
111114
* or if an I/O error occurs
112115
*/
113-
public static String readln(String prompt) {
116+
public static @Nullable String readln(@Nullable String prompt) {
114117
return con().readln(prompt);
115118
}
116119

@@ -128,7 +131,7 @@ public static String readln(String prompt) {
128131
* or if an I/O error occurs
129132
* @since 24
130133
*/
131-
public static String readln() {
134+
public static @Nullable String readln() {
132135
return con().readln();
133136
}
134137

0 commit comments

Comments
 (0)