@@ -447,7 +447,10 @@ final class Instant private(private val seconds: Long, private val nanos: Int) e
447
447
* @throws DateTimeException if a value for the field cannot be obtained
448
448
* @throws ArithmeticException if numeric overflow occurs
449
449
*/
450
- def getLong (field : TemporalField ): Long =
450
+ def getLong (field : TemporalField ): Long = {
451
+ if (field == null ) {
452
+ throw new NullPointerException ()
453
+ }
451
454
if (field.isInstanceOf [ChronoField ])
452
455
field.asInstanceOf [ChronoField ] match {
453
456
case NANO_OF_SECOND => nanos
@@ -458,6 +461,7 @@ final class Instant private(private val seconds: Long, private val nanos: Int) e
458
461
}
459
462
else
460
463
field.getFrom(this )
464
+ }
461
465
462
466
/** Gets the number of seconds from the Java epoch of 1970-01-01T00:00:00Z.
463
467
*
@@ -765,13 +769,17 @@ final class Instant private(private val seconds: Long, private val nanos: Int) e
765
769
* @throws DateTimeException if unable to query (defined by the query)
766
770
* @throws ArithmeticException if numeric overflow occurs (defined by the query)
767
771
*/
768
- override def query [R >: Null ](query : TemporalQuery [R ]): R =
772
+ override def query [R >: Null ](query : TemporalQuery [R ]): R = {
773
+ if (query == null ) {
774
+ throw new NullPointerException ()
775
+ }
769
776
if (query eq TemporalQueries .precision)
770
777
NANOS .asInstanceOf [R ]
771
778
else if ((query eq TemporalQueries .localDate) || (query eq TemporalQueries .localTime) || (query eq TemporalQueries .chronology) || (query eq TemporalQueries .zoneId) || (query eq TemporalQueries .zone) || (query eq TemporalQueries .offset))
772
779
null
773
780
else
774
781
query.queryFrom(this )
782
+ }
775
783
776
784
/** Adjusts the specified temporal object to have this instant.
777
785
*
@@ -943,6 +951,9 @@ final class Instant private(private val seconds: Long, private val nanos: Int) e
943
951
* @throws NullPointerException if otherInstant is null
944
952
*/
945
953
def compare (otherInstant : Instant ): Int = {
954
+ if (otherInstant == null ) {
955
+ throw new NullPointerException (" null object in comparison" )
956
+ }
946
957
val cmp : Int = java.lang.Long .compare(seconds, otherInstant.seconds)
947
958
if (cmp != 0 ) cmp
948
959
else nanos - otherInstant.nanos
0 commit comments