Skip to content

Commit 4ab1762

Browse files
committed
Annotate much of java.time for nullness.
1 parent 72c372e commit 4ab1762

36 files changed

+193
-63
lines changed

src/java.base/share/classes/java/time/Clock.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.checkerframework.checker.nullness.qual.Nullable;
6767
import org.checkerframework.dataflow.qual.Pure;
6868
import org.checkerframework.dataflow.qual.SideEffectFree;
69+
import org.checkerframework.framework.qual.AnnotatedFor;
6970

7071
import java.io.IOException;
7172
import java.io.ObjectInputStream;
@@ -143,6 +144,7 @@
143144
*
144145
* @since 1.8
145146
*/
147+
@AnnotatedFor({"nullness"})
146148
public abstract class Clock {
147149

148150
/**

src/java.base/share/classes/java/time/DateTimeException.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
*/
6262
package java.time;
6363

64+
import org.checkerframework.checker.nullness.qual.Nullable;
65+
import org.checkerframework.dataflow.qual.SideEffectFree;
66+
import org.checkerframework.framework.qual.AnnotatedFor;
67+
6468
/**
6569
* Exception used to indicate a problem while calculating a date-time.
6670
* <p>
@@ -72,6 +76,7 @@
7276
*
7377
* @since 1.8
7478
*/
79+
@AnnotatedFor({"nullness"})
7580
public class DateTimeException extends RuntimeException {
7681

7782
/**
@@ -84,7 +89,8 @@ public class DateTimeException extends RuntimeException {
8489
*
8590
* @param message the message to use for this exception, may be null
8691
*/
87-
public DateTimeException(String message) {
92+
@SideEffectFree
93+
public DateTimeException(@Nullable String message) {
8894
super(message);
8995
}
9096

@@ -94,7 +100,8 @@ public DateTimeException(String message) {
94100
* @param message the message to use for this exception, may be null
95101
* @param cause the cause of the exception, may be null
96102
*/
97-
public DateTimeException(String message, Throwable cause) {
103+
@SideEffectFree
104+
public DateTimeException(@Nullable String message, @Nullable Throwable cause) {
98105
super(message, cause);
99106
}
100107

src/java.base/share/classes/java/time/DayOfWeek.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
6565
import static java.time.temporal.ChronoUnit.DAYS;
6666

67+
import org.checkerframework.checker.nullness.qual.Nullable;
68+
import org.checkerframework.framework.qual.AnnotatedFor;
69+
6770
import java.time.format.DateTimeFormatterBuilder;
6871
import java.time.format.TextStyle;
6972
import java.time.temporal.ChronoField;
@@ -106,6 +109,7 @@
106109
*
107110
* @since 1.8
108111
*/
112+
@AnnotatedFor({"nullness"})
109113
public enum DayOfWeek implements TemporalAccessor, TemporalAdjuster {
110114

111115
/**
@@ -248,7 +252,7 @@ public String getDisplayName(TextStyle style, Locale locale) {
248252
* @return true if the field is supported on this day-of-week, false if not
249253
*/
250254
@Override
251-
public boolean isSupported(TemporalField field) {
255+
public boolean isSupported(@Nullable TemporalField field) {
252256
if (field instanceof ChronoField) {
253257
return field == DAY_OF_WEEK;
254258
}

src/java.base/share/classes/java/time/Duration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.checkerframework.checker.nullness.qual.Nullable;
6767
import org.checkerframework.dataflow.qual.Pure;
6868
import org.checkerframework.dataflow.qual.SideEffectFree;
69+
import org.checkerframework.framework.qual.AnnotatedFor;
6970

7071
import static java.time.LocalTime.MINUTES_PER_HOUR;
7172
import static java.time.LocalTime.NANOS_PER_MILLI;
@@ -136,6 +137,7 @@
136137
*
137138
* @since 1.8
138139
*/
140+
@AnnotatedFor({"nullness"})
139141
public final class Duration
140142
implements TemporalAmount, Comparable<Duration>, Serializable {
141143

src/java.base/share/classes/java/time/Instant.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.checkerframework.checker.nullness.qual.Nullable;
6767
import org.checkerframework.dataflow.qual.Pure;
6868
import org.checkerframework.dataflow.qual.SideEffectFree;
69+
import org.checkerframework.framework.qual.AnnotatedFor;
6970

7071
import static java.time.LocalTime.NANOS_PER_SECOND;
7172
import static java.time.LocalTime.SECONDS_PER_DAY;
@@ -210,6 +211,7 @@
210211
*
211212
* @since 1.8
212213
*/
214+
@AnnotatedFor({"nullness"})
213215
public final class Instant
214216
implements Temporal, TemporalAdjuster, Comparable<Instant>, Serializable {
215217

@@ -460,7 +462,7 @@ private Instant(long epochSecond, int nanos) {
460462
* @return true if the field is supported on this instant, false if not
461463
*/
462464
@Override
463-
public boolean isSupported(TemporalField field) {
465+
public boolean isSupported(@Nullable TemporalField field) {
464466
if (field instanceof ChronoField) {
465467
return field == INSTANT_SECONDS || field == NANO_OF_SECOND || field == MICRO_OF_SECOND || field == MILLI_OF_SECOND;
466468
}
@@ -497,7 +499,7 @@ public boolean isSupported(TemporalField field) {
497499
* @return true if the unit can be added/subtracted, false if not
498500
*/
499501
@Override
500-
public boolean isSupported(TemporalUnit unit) {
502+
public boolean isSupported(@Nullable TemporalUnit unit) {
501503
if (unit instanceof ChronoUnit) {
502504
return unit.isTimeBased() || unit == DAYS;
503505
}

src/java.base/share/classes/java/time/LocalDate.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.checkerframework.checker.nullness.qual.Nullable;
6767
import org.checkerframework.dataflow.qual.Pure;
6868
import org.checkerframework.dataflow.qual.SideEffectFree;
69+
import org.checkerframework.framework.qual.AnnotatedFor;
6970

7071
import static java.time.LocalTime.SECONDS_PER_DAY;
7172
import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
@@ -142,6 +143,7 @@
142143
*
143144
* @since 1.8
144145
*/
146+
@AnnotatedFor({"nullness"})
145147
public final class LocalDate
146148
implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable {
147149

@@ -542,7 +544,7 @@ private LocalDate(int year, int month, int dayOfMonth) {
542544
* @return true if the field is supported on this date, false if not
543545
*/
544546
@Override // override for Javadoc
545-
public boolean isSupported(TemporalField field) {
547+
public boolean isSupported(@Nullable TemporalField field) {
546548
return ChronoLocalDate.super.isSupported(field);
547549
}
548550

@@ -576,7 +578,7 @@ public boolean isSupported(TemporalField field) {
576578
* @return true if the unit can be added/subtracted, false if not
577579
*/
578580
@Override // override for Javadoc
579-
public boolean isSupported(TemporalUnit unit) {
581+
public boolean isSupported(@Nullable TemporalUnit unit) {
580582
return ChronoLocalDate.super.isSupported(unit);
581583
}
582584

src/java.base/share/classes/java/time/LocalDateTime.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.checkerframework.checker.nullness.qual.Nullable;
6767
import org.checkerframework.dataflow.qual.Pure;
6868
import org.checkerframework.dataflow.qual.SideEffectFree;
69+
import org.checkerframework.framework.qual.AnnotatedFor;
6970

7071
import static java.time.LocalTime.HOURS_PER_DAY;
7172
import static java.time.LocalTime.MICROS_PER_DAY;
@@ -138,6 +139,7 @@
138139
*
139140
* @since 1.8
140141
*/
142+
@AnnotatedFor({"nullness"})
141143
public final class LocalDateTime
142144
implements Temporal, TemporalAdjuster, ChronoLocalDateTime<LocalDate>, Serializable {
143145

@@ -577,7 +579,7 @@ private LocalDateTime with(LocalDate newDate, LocalTime newTime) {
577579
* @return true if the field is supported on this date-time, false if not
578580
*/
579581
@Override
580-
public boolean isSupported(TemporalField field) {
582+
public boolean isSupported(@Nullable TemporalField field) {
581583
if (field instanceof ChronoField) {
582584
ChronoField f = (ChronoField) field;
583585
return f.isDateBased() || f.isTimeBased();
@@ -622,7 +624,7 @@ public boolean isSupported(TemporalField field) {
622624
* @return true if the unit can be added/subtracted, false if not
623625
*/
624626
@Override // override for Javadoc
625-
public boolean isSupported(TemporalUnit unit) {
627+
public boolean isSupported(@Nullable TemporalUnit unit) {
626628
return ChronoLocalDateTime.super.isSupported(unit);
627629
}
628630

src/java.base/share/classes/java/time/LocalTime.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.checkerframework.checker.nullness.qual.Nullable;
6767
import org.checkerframework.dataflow.qual.Pure;
6868
import org.checkerframework.dataflow.qual.SideEffectFree;
69+
import org.checkerframework.framework.qual.AnnotatedFor;
6970

7071
import static java.time.temporal.ChronoField.HOUR_OF_DAY;
7172
import static java.time.temporal.ChronoField.MICRO_OF_DAY;
@@ -128,6 +129,7 @@
128129
*
129130
* @since 1.8
130131
*/
132+
@AnnotatedFor({"nullness"})
131133
public final class LocalTime
132134
implements Temporal, TemporalAdjuster, Comparable<LocalTime>, Serializable {
133135

@@ -542,7 +544,7 @@ private LocalTime(int hour, int minute, int second, int nanoOfSecond) {
542544
* @return true if the field is supported on this time, false if not
543545
*/
544546
@Override
545-
public boolean isSupported(TemporalField field) {
547+
public boolean isSupported(@Nullable TemporalField field) {
546548
if (field instanceof ChronoField) {
547549
return field.isTimeBased();
548550
}
@@ -578,7 +580,7 @@ public boolean isSupported(TemporalField field) {
578580
* @return true if the unit can be added/subtracted, false if not
579581
*/
580582
@Override // override for Javadoc
581-
public boolean isSupported(TemporalUnit unit) {
583+
public boolean isSupported(@Nullable TemporalUnit unit) {
582584
if (unit instanceof ChronoUnit) {
583585
return unit.isTimeBased();
584586
}

src/java.base/share/classes/java/time/Month.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
6565
import static java.time.temporal.ChronoUnit.MONTHS;
6666

67+
import org.checkerframework.checker.nullness.qual.Nullable;
68+
import org.checkerframework.framework.qual.AnnotatedFor;
69+
6770
import java.time.chrono.Chronology;
6871
import java.time.chrono.IsoChronology;
6972
import java.time.format.DateTimeFormatterBuilder;
@@ -103,6 +106,7 @@
103106
*
104107
* @since 1.8
105108
*/
109+
@AnnotatedFor({"nullness"})
106110
public enum Month implements TemporalAccessor, TemporalAdjuster {
107111

108112
/**
@@ -275,7 +279,7 @@ public String getDisplayName(TextStyle style, Locale locale) {
275279
* @return true if the field is supported on this month-of-year, false if not
276280
*/
277281
@Override
278-
public boolean isSupported(TemporalField field) {
282+
public boolean isSupported(@Nullable TemporalField field) {
279283
if (field instanceof ChronoField) {
280284
return field == MONTH_OF_YEAR;
281285
}

src/java.base/share/classes/java/time/MonthDay.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.checkerframework.checker.nullness.qual.Nullable;
6767
import org.checkerframework.dataflow.qual.Pure;
6868
import org.checkerframework.dataflow.qual.SideEffectFree;
69+
import org.checkerframework.framework.qual.AnnotatedFor;
6970

7071
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
7172
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
@@ -130,6 +131,7 @@
130131
*
131132
* @since 1.8
132133
*/
134+
@AnnotatedFor({"nullness"})
133135
public final class MonthDay
134136
implements TemporalAccessor, TemporalAdjuster, Comparable<MonthDay>, Serializable {
135137

@@ -352,7 +354,7 @@ private MonthDay(int month, int dayOfMonth) {
352354
* @return true if the field is supported on this month-day, false if not
353355
*/
354356
@Override
355-
public boolean isSupported(TemporalField field) {
357+
public boolean isSupported(@Nullable TemporalField field) {
356358
if (field instanceof ChronoField) {
357359
return field == MONTH_OF_YEAR || field == DAY_OF_MONTH;
358360
}

0 commit comments

Comments
 (0)