Skip to content

Commit

Permalink
Annotate some recent io APIs.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cpovirk committed Dec 10, 2024
1 parent 300a39f commit 1b57e4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/io/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public Console print(@Nullable Object obj) {
* @since 23
*/
@PreviewFeature(feature = PreviewFeature.Feature.IMPLICIT_CLASSES)
public String readln(@Nullable String prompt) {
public @Nullable String readln(@Nullable String prompt) {
throw newUnsupportedOperationException();
}

Expand All @@ -242,7 +242,7 @@ public String readln(@Nullable String prompt) {
* @since 24
*/
@PreviewFeature(feature = PreviewFeature.Feature.IMPLICIT_CLASSES)
public String readln() {
public @Nullable String readln() {
throw newUnsupportedOperationException();
}

Expand Down
11 changes: 7 additions & 4 deletions src/java.base/share/classes/java/io/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
package java.io;

import jdk.internal.javac.PreviewFeature;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* A collection of static convenience methods that provide access to
Expand All @@ -41,6 +43,7 @@
* @since 23
*/
@PreviewFeature(feature = PreviewFeature.Feature.IMPLICIT_CLASSES)
@NullMarked
public final class IO {

private IO() {
Expand All @@ -59,7 +62,7 @@ private IO() {
* @throws IOError if {@code System.console()} returns {@code null},
* or if an I/O error occurs
*/
public static void println(Object obj) {
public static void println(@Nullable Object obj) {
con().println(obj);
}

Expand Down Expand Up @@ -90,7 +93,7 @@ public static void println() {
* @throws IOError if {@code System.console()} returns {@code null},
* or if an I/O error occurs
*/
public static void print(Object obj) {
public static void print(@Nullable Object obj) {
con().print(obj);
}

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

Expand All @@ -128,7 +131,7 @@ public static String readln(String prompt) {
* or if an I/O error occurs
* @since 24
*/
public static String readln() {
public static @Nullable String readln() {
return con().readln();
}

Expand Down

0 comments on commit 1b57e4a

Please sign in to comment.