Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate much of java.time for nullness. #72

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/java.base/share/classes/java/time/Clock.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;

import java.io.IOException;
import java.io.ObjectInputStream;
Expand Down Expand Up @@ -143,6 +144,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public abstract class Clock {

/**
Expand Down
11 changes: 9 additions & 2 deletions src/java.base/share/classes/java/time/DateTimeException.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
*/
package java.time;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;

/**
* Exception used to indicate a problem while calculating a date-time.
* <p>
Expand All @@ -72,6 +76,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public class DateTimeException extends RuntimeException {

/**
Expand All @@ -84,7 +89,8 @@ public class DateTimeException extends RuntimeException {
*
* @param message the message to use for this exception, may be null
*/
public DateTimeException(String message) {
@SideEffectFree
public DateTimeException(@Nullable String message) {
super(message);
}

Expand All @@ -94,7 +100,8 @@ public DateTimeException(String message) {
* @param message the message to use for this exception, may be null
* @param cause the cause of the exception, may be null
*/
public DateTimeException(String message, Throwable cause) {
@SideEffectFree
public DateTimeException(@Nullable String message, @Nullable Throwable cause) {
super(message, cause);
}

Expand Down
6 changes: 5 additions & 1 deletion src/java.base/share/classes/java/time/DayOfWeek.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
import static java.time.temporal.ChronoUnit.DAYS;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.AnnotatedFor;

import java.time.format.DateTimeFormatterBuilder;
import java.time.format.TextStyle;
import java.time.temporal.ChronoField;
Expand Down Expand Up @@ -106,6 +109,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public enum DayOfWeek implements TemporalAccessor, TemporalAdjuster {

/**
Expand Down Expand Up @@ -248,7 +252,7 @@ public String getDisplayName(TextStyle style, Locale locale) {
* @return true if the field is supported on this day-of-week, false if not
*/
@Override
public boolean isSupported(TemporalField field) {
public boolean isSupported(@Nullable TemporalField field) {
if (field instanceof ChronoField) {
return field == DAY_OF_WEEK;
}
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/share/classes/java/time/Duration.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;

import static java.time.LocalTime.MINUTES_PER_HOUR;
import static java.time.LocalTime.NANOS_PER_MILLI;
Expand Down Expand Up @@ -136,6 +137,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public final class Duration
implements TemporalAmount, Comparable<Duration>, Serializable {

Expand Down
6 changes: 4 additions & 2 deletions src/java.base/share/classes/java/time/Instant.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;

import static java.time.LocalTime.NANOS_PER_SECOND;
import static java.time.LocalTime.SECONDS_PER_DAY;
Expand Down Expand Up @@ -210,6 +211,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public final class Instant
implements Temporal, TemporalAdjuster, Comparable<Instant>, Serializable {

Expand Down Expand Up @@ -460,7 +462,7 @@ private Instant(long epochSecond, int nanos) {
* @return true if the field is supported on this instant, false if not
*/
@Override
public boolean isSupported(TemporalField field) {
public boolean isSupported(@Nullable TemporalField field) {
if (field instanceof ChronoField) {
return field == INSTANT_SECONDS || field == NANO_OF_SECOND || field == MICRO_OF_SECOND || field == MILLI_OF_SECOND;
}
Expand Down Expand Up @@ -497,7 +499,7 @@ public boolean isSupported(TemporalField field) {
* @return true if the unit can be added/subtracted, false if not
*/
@Override
public boolean isSupported(TemporalUnit unit) {
public boolean isSupported(@Nullable TemporalUnit unit) {
if (unit instanceof ChronoUnit) {
return unit.isTimeBased() || unit == DAYS;
}
Expand Down
6 changes: 4 additions & 2 deletions src/java.base/share/classes/java/time/LocalDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;

import static java.time.LocalTime.SECONDS_PER_DAY;
import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
Expand Down Expand Up @@ -142,6 +143,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public final class LocalDate
implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable {

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

Expand Down Expand Up @@ -576,7 +578,7 @@ public boolean isSupported(TemporalField field) {
* @return true if the unit can be added/subtracted, false if not
*/
@Override // override for Javadoc
public boolean isSupported(TemporalUnit unit) {
public boolean isSupported(@Nullable TemporalUnit unit) {
return ChronoLocalDate.super.isSupported(unit);
}

Expand Down
6 changes: 4 additions & 2 deletions src/java.base/share/classes/java/time/LocalDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;

import static java.time.LocalTime.HOURS_PER_DAY;
import static java.time.LocalTime.MICROS_PER_DAY;
Expand Down Expand Up @@ -138,6 +139,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public final class LocalDateTime
implements Temporal, TemporalAdjuster, ChronoLocalDateTime<LocalDate>, Serializable {

Expand Down Expand Up @@ -577,7 +579,7 @@ private LocalDateTime with(LocalDate newDate, LocalTime newTime) {
* @return true if the field is supported on this date-time, false if not
*/
@Override
public boolean isSupported(TemporalField field) {
public boolean isSupported(@Nullable TemporalField field) {
if (field instanceof ChronoField) {
ChronoField f = (ChronoField) field;
return f.isDateBased() || f.isTimeBased();
Expand Down Expand Up @@ -622,7 +624,7 @@ public boolean isSupported(TemporalField field) {
* @return true if the unit can be added/subtracted, false if not
*/
@Override // override for Javadoc
public boolean isSupported(TemporalUnit unit) {
public boolean isSupported(@Nullable TemporalUnit unit) {
return ChronoLocalDateTime.super.isSupported(unit);
}

Expand Down
6 changes: 4 additions & 2 deletions src/java.base/share/classes/java/time/LocalTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;

import static java.time.temporal.ChronoField.HOUR_OF_DAY;
import static java.time.temporal.ChronoField.MICRO_OF_DAY;
Expand Down Expand Up @@ -128,6 +129,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public final class LocalTime
implements Temporal, TemporalAdjuster, Comparable<LocalTime>, Serializable {

Expand Down Expand Up @@ -542,7 +544,7 @@ private LocalTime(int hour, int minute, int second, int nanoOfSecond) {
* @return true if the field is supported on this time, false if not
*/
@Override
public boolean isSupported(TemporalField field) {
public boolean isSupported(@Nullable TemporalField field) {
if (field instanceof ChronoField) {
return field.isTimeBased();
}
Expand Down Expand Up @@ -578,7 +580,7 @@ public boolean isSupported(TemporalField field) {
* @return true if the unit can be added/subtracted, false if not
*/
@Override // override for Javadoc
public boolean isSupported(TemporalUnit unit) {
public boolean isSupported(@Nullable TemporalUnit unit) {
if (unit instanceof ChronoUnit) {
return unit.isTimeBased();
}
Expand Down
6 changes: 5 additions & 1 deletion src/java.base/share/classes/java/time/Month.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
import static java.time.temporal.ChronoUnit.MONTHS;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.AnnotatedFor;

import java.time.chrono.Chronology;
import java.time.chrono.IsoChronology;
import java.time.format.DateTimeFormatterBuilder;
Expand Down Expand Up @@ -103,6 +106,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public enum Month implements TemporalAccessor, TemporalAdjuster {

/**
Expand Down Expand Up @@ -275,7 +279,7 @@ public String getDisplayName(TextStyle style, Locale locale) {
* @return true if the field is supported on this month-of-year, false if not
*/
@Override
public boolean isSupported(TemporalField field) {
public boolean isSupported(@Nullable TemporalField field) {
if (field instanceof ChronoField) {
return field == MONTH_OF_YEAR;
}
Expand Down
4 changes: 3 additions & 1 deletion src/java.base/share/classes/java/time/MonthDay.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;

import static java.time.temporal.ChronoField.DAY_OF_MONTH;
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
Expand Down Expand Up @@ -130,6 +131,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public final class MonthDay
implements TemporalAccessor, TemporalAdjuster, Comparable<MonthDay>, Serializable {

Expand Down Expand Up @@ -352,7 +354,7 @@ private MonthDay(int month, int dayOfMonth) {
* @return true if the field is supported on this month-day, false if not
*/
@Override
public boolean isSupported(TemporalField field) {
public boolean isSupported(@Nullable TemporalField field) {
if (field instanceof ChronoField) {
return field == MONTH_OF_YEAR || field == DAY_OF_MONTH;
}
Expand Down
6 changes: 4 additions & 2 deletions src/java.base/share/classes/java/time/OffsetDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;

import static java.time.temporal.ChronoField.EPOCH_DAY;
import static java.time.temporal.ChronoField.INSTANT_SECONDS;
Expand Down Expand Up @@ -131,6 +132,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public final class OffsetDateTime
implements Temporal, TemporalAdjuster, Comparable<OffsetDateTime>, Serializable {

Expand Down Expand Up @@ -487,7 +489,7 @@ private OffsetDateTime with(LocalDateTime dateTime, ZoneOffset offset) {
* @return true if the field is supported on this date-time, false if not
*/
@Override
public boolean isSupported(TemporalField field) {
public boolean isSupported(@Nullable TemporalField field) {
return field instanceof ChronoField || (field != null && field.isSupportedBy(this));
}

Expand Down Expand Up @@ -528,7 +530,7 @@ public boolean isSupported(TemporalField field) {
* @return true if the unit can be added/subtracted, false if not
*/
@Override // override for Javadoc
public boolean isSupported(TemporalUnit unit) {
public boolean isSupported(@Nullable TemporalUnit unit) {
if (unit instanceof ChronoUnit) {
return unit != FOREVER;
}
Expand Down
6 changes: 4 additions & 2 deletions src/java.base/share/classes/java/time/OffsetTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;

import static java.time.LocalTime.NANOS_PER_HOUR;
import static java.time.LocalTime.NANOS_PER_MINUTE;
Expand Down Expand Up @@ -121,6 +122,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public final class OffsetTime
implements Temporal, TemporalAdjuster, Comparable<OffsetTime>, Serializable {

Expand Down Expand Up @@ -398,7 +400,7 @@ private OffsetTime with(LocalTime time, ZoneOffset offset) {
* @return true if the field is supported on this time, false if not
*/
@Override
public boolean isSupported(TemporalField field) {
public boolean isSupported(@Nullable TemporalField field) {
if (field instanceof ChronoField) {
return field.isTimeBased() || field == OFFSET_SECONDS;
}
Expand Down Expand Up @@ -434,7 +436,7 @@ public boolean isSupported(TemporalField field) {
* @return true if the unit can be added/subtracted, false if not
*/
@Override // override for Javadoc
public boolean isSupported(TemporalUnit unit) {
public boolean isSupported(@Nullable TemporalUnit unit) {
if (unit instanceof ChronoUnit) {
return unit.isTimeBased();
}
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/share/classes/java/time/Period.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;

import static java.time.temporal.ChronoUnit.DAYS;
import static java.time.temporal.ChronoUnit.MONTHS;
Expand Down Expand Up @@ -136,6 +137,7 @@
*
* @since 1.8
*/
@AnnotatedFor({"nullness"})
public final class Period
implements ChronoPeriod, Serializable {

Expand Down
Loading